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();
103 void set_layout(widget_layout
const& context)
noexcept override
107 auto shape = context.shape;
108 shape.rectangle = aarectangle{shape.x(), shape.y(), shape.width(), shape.height() + _child_height_adjustment};
109 _children.set_layout(shape, theme<prefix>.cap_height(
this));
112 hilet overhang = context.redraw_overhang;
114 for (
hilet& child : _children) {
115 hilet child_clipping_rectangle =
116 aarectangle{child.shape.x() - overhang, 0.0f, child.shape.width() + overhang * 2.0f, context.height() + overhang * 2.0f};
118 child.value->set_layout(context.transform(child.shape, 1.0f, child_clipping_rectangle));
122 void draw(widget_draw_context& context)
noexcept override
125 if (overlaps(context, layout)) {
126 context.draw_box(layout, layout.rectangle(), theme<prefix>.background_color(
this));
128 if (tab_button_has_focus()) {
131 hilet focus_rectangle =
132 aarectangle{0.0f, 0.0f, layout.rectangle().width(), theme<prefix>.border_width(
this)};
135 translate3{0.0f, 0.0f, 1.5f} * narrow_cast<aarectangle>(focus_rectangle),
136 theme<prefix>.background_color(
this));
140 for (
hilet& child : _children) {
142 child.value->draw(context);
147 hitbox hitbox_test(point2 position)
const noexcept override
153 auto r = layout.contains(position) ? hitbox{
id, layout.elevation, hitbox_type::move_area} : hitbox{};
155 for (
hilet& child : _children) {
157 r = child.value->hitbox_test_from_parent(position, r);
167 mutable row_layout<std::unique_ptr<widget>> _children;
168 mutable float _child_height_adjustment = 0;
169 size_t _spacer_index = 0;
171 void update_layout_for_child(widget& child,
ssize_t index, widget_layout
const& context)
const noexcept;
181 _children.insert(_children.cbegin() + _spacer_index,
std::move(widget));
185 _children.insert(_children.cbegin() + _spacer_index + 1,
std::move(widget));
198 [[nodiscard]]
bool tab_button_has_focus() const noexcept
200 for (
hilet& cell : _children) {
201 hilet child = cell.value.get();
203 if (child->is_tab_button()) {
204 if (*child->focus and *child->state != hi::widget_state::off) {
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253