40 constexpr static auto prefix = Name /
"toolbar";
53 _children.push_back(std::make_unique<spacer_widget>(
this));
71 template<
typename Widget, horizontal_alignment Alignment = horizontal_alignment::left,
typename... Args>
74 auto widget = std::make_unique<Widget>(
this, std::forward<Args>(args)...);
79 [[nodiscard]] generator<widget const&> children(
bool include_invisible)
const noexcept override
81 for (
hilet& child : _children) {
82 co_yield *child.value;
86 [[nodiscard]] box_constraints update_constraints() noexcept
override
88 for (
auto& child : _children) {
89 child.set_constraints(child.value->update_constraints());
92 auto r = _children.constraints(os_settings::left_to_right());
93 _child_height_adjustment = -r.margins.top();
95 r.minimum.height() += r.margins.top();
96 r.preferred.height() += r.margins.top();
97 r.maximum.height() += r.margins.top();
98 r.padding.top() += r.margins.top();
104 void set_layout(widget_layout
const& context)
noexcept override
108 auto shape = context.shape;
109 shape.rectangle = aarectanglei{shape.x(), shape.y(), shape.width(), shape.height() + _child_height_adjustment};
110 _children.set_layout(shape, theme<prefix>.cap_height(
this));
113 hilet overhang = context.redraw_overhang;
115 for (
hilet& child : _children) {
116 hilet child_clipping_rectangle =
117 aarectanglei{child.shape.x() - overhang, 0, child.shape.width() + overhang * 2, context.height() + overhang * 2};
119 child.value->set_layout(context.transform(child.shape, 1.0f, child_clipping_rectangle));
123 void draw(widget_draw_context
const& context)
noexcept override
126 if (overlaps(context, layout)) {
127 context.draw_box(layout, layout.rectangle(), theme<prefix>.background_color(
this));
129 if (tab_button_has_focus()) {
132 hilet focus_rectangle =
133 aarectanglei{0, 0, layout.rectangle().width(), theme<prefix>.border_width(
this)};
136 translate3{0.0f, 0.0f, 1.5f} * narrow_cast<aarectangle>(focus_rectangle),
137 theme<prefix>.background_color(
this));
141 for (
hilet& child : _children) {
143 child.value->draw(context);
148 hitbox hitbox_test(point2i position)
const noexcept override
154 auto r = layout.
contains(position) ? hitbox{
id, layout.
elevation, hitbox_type::move_area} : hitbox{};
156 for (
hilet& child : _children) {
158 r = child.value->hitbox_test_from_parent(position, r);
168 mutable row_layout<std::unique_ptr<widget>> _children;
169 mutable int _child_height_adjustment = 0;
170 size_t _spacer_index = 0;
172 void update_layout_for_child(widget& child,
ssize_t index, widget_layout
const& context)
const noexcept;
182 _children.insert(_children.cbegin() + _spacer_index,
std::move(widget));
186 _children.insert(_children.cbegin() + _spacer_index + 1,
std::move(widget));
199 [[nodiscard]]
bool tab_button_has_focus() const noexcept
201 for (
hilet& cell : _children) {
202 hilet child = cell.value.get();
204 if (child->is_tab_button()) {
205 if (*child->focus and *child->state != hi::widget_state::off) {
#define hi_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:279
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253