Fill¶
Header: winui/ui/panels/Fill.hpp. Spec: winui/ui/panels/Fill.hpp.
A child of a stack that is given the room the other children leave. Built by ui::Fill.
A StackControl measures its children unbounded along its axis. A fill is measured last, with the room left over as its bound, so a scrolling child inside it (a Scroll, a ListView) gets a real height and scrolls. Several fills, and the stack's spacers, share the room by their weight. Where the stack itself has no bound along its axis (inside a Scroll) there is nothing to share, and a fill is as big as its content. Outside a stack it is a plain one-child container.
Example:
auto page = std::make_unique<ui::StackControl>(ui::Orientation::Vertical);
page->add(std::make_unique<ui::TextControl>("Inbox"));
auto* fill = page->add(std::make_unique<ui::FillControl>());
fill->set_child(std::make_unique<ui::ScrollControl>());
page->add(std::make_unique<ui::TextControl>("3 unread"));
ui::Fill¶
Gives one child of a stack the room the other children leave. Builds a ui::FillControl.
In a VerticalStack of a header, a list and a footer, putting the list in a Fill keeps the footer at the bottom and lets the list scroll in between.
A stack gives each child what it asks for along its axis, with no limit, so a list in a plain stack grows as long as its items and never scrolls. A Fill is measured with the room the other children leave. Several fills share that room by .weight, together with the stack's spacers. A ui::Spacer is a Fill with nothing in it. In a stack that has no limit itself (one inside a Scroll) a Fill is measured as big as its content, and takes what room the stack is arranged with beyond that.
Example:
ui::Property<std::vector<std::string>> messages;
ui::Property<int> unread{0};
window.set_content(ui::VerticalStack{
.spacing = 8,
.content = {
ui::Text{.text = "Inbox", .role = ui::TextRole::Subtitle},
ui::Fill{.content = ui::ListView<std::string>{.items = messages}},
ui::Text{.text = ui::bind(unread, [](int n) { return std::format("{} unread", n); })},
},
});
Every field, in the order a designated initializer names them:
ui::Fill{
.weight, .style, .margin, .width, .height, .min_width, .min_height, .max_width,
.max_height, .horizontal_alignment, .vertical_alignment, .visible, .tool_tip,
.accessibility, .on_pointer_entered, .on_pointer_exited, .on_got_focus, .on_lost_focus,
.on_key_down, .on_wheel, .control, .content
}
Fields, in declaration order (designators must follow it):
| Field | Type | Default | |
|---|---|---|---|
weight |
ui::Binding<float> |
{1.0f} |
This fill's share of the leftover room, relative to the other fills and spacers in the same stack. |
on_pointer_entered |
ui::Action |
The pointer moved onto the control. | |
on_pointer_exited |
ui::Action |
The pointer left the control. | |
on_got_focus |
ui::Action |
Keyboard focus arrived on the control, or on anything inside it, from outside it. A control with nothing focusable in it never gets focus, and never raises this. | |
on_lost_focus |
ui::Action |
Keyboard focus left the control and everything inside it. | |
on_key_down |
ui::Callback<ui::Handling(const ui::KeyEvent&)> |
A key pressed while focus is on the control or inside it, before the control's own handling; ui::Handled stops it there (Element::on_key_down()). | |
on_wheel |
ui::Callback<ui::Handling(const ui::PointerEvent&)> |
A wheel turn over the control, before the control scrolls; ui::Handled stops it there (Element::on_wheel()). | |
control |
ui::ControlOut<ui::Fill> |
Out: the handle that receives the built control. | |
content |
ui::Spec |
What gets the room. |
Plus the common fields style, margin, width, height, min_width, min_height, max_width, max_height, horizontal_alignment, vertical_alignment, visible, tool_tip, accessibility every spec carries (conventions).
build¶
Consumes the spec and returns the built ui::FillControl; the caller owns it.
ui::FillControl¶
Derives from ui::ContentHost.
A child of a stack that is given the room the other children leave. Built by ui::Fill.
A StackControl measures its children unbounded along its axis. A fill is measured last, with the room left over as its bound, so a scrolling child inside it (a Scroll, a ListView) gets a real height and scrolls. Several fills, and the stack's spacers, share the room by their weight. Where the stack itself has no bound along its axis (inside a Scroll) there is nothing to share, and a fill is as big as its content. Outside a stack it is a plain one-child container.
Example:
auto page = std::make_unique<ui::StackControl>(ui::Orientation::Vertical);
page->add(std::make_unique<ui::TextControl>("Inbox"));
auto* fill = page->add(std::make_unique<ui::FillControl>());
fill->set_child(std::make_unique<ui::ScrollControl>());
page->add(std::make_unique<ui::TextControl>("3 unread"));
FillControl¶
An empty fill of weight 1.
weight¶
This fill's share of the leftover room, relative to the other fills and spacers in the same stack.
set_weight¶
Sets the share; negative is treated as 0. Updates the layout.
Tests¶
tests/test_stack.cpp