68 observer<alignment>
alignment = hi::alignment::top_flush();
72 observer<semantic_text_style>
text_style = semantic_text_style::label;
83 set_attributes(hi_forward(attributes)...);
87 [[nodiscard]] generator<widget_intf &> children(
bool include_invisible)
noexcept override
89 co_yield *_icon_widget;
90 co_yield *_text_widget;
98 hilet resolved_alignment = resolve(*
alignment,
true);
101 if (to_bool(
label->icon) and to_bool(
label->text)) {
105 _grid.add_cell(0, 0, _icon_widget.get());
106 _grid.add_cell(1, 0, _text_widget.get(),
true);
109 _grid.add_cell(0, 0, _text_widget.get(),
true);
110 _grid.add_cell(1, 0, _icon_widget.get());
114 _grid.add_cell(0, 0, _icon_widget.get());
115 _grid.add_cell(0, 1, _text_widget.get(),
true);
119 _grid.add_cell(0, 0, _text_widget.get(),
true);
120 _grid.add_cell(0, 1, _icon_widget.get());
122 hi_no_default(
"alignment is not allowed to be middle-center.");
124 }
else if (to_bool(
label->icon)) {
126 _grid.add_cell(0, 0, _icon_widget.get());
127 }
else if (to_bool(
label->text)) {
129 _grid.add_cell(0, 0, _text_widget.get());
134 theme().large_icon_size() :
135 theme().text_style(*text_style)->size * theme().scale;
137 _icon_widget->minimum = extent2{icon_size, icon_size};
138 _icon_widget->maximum = extent2{icon_size, icon_size};
140 for (
auto& cell : _grid) {
141 cell.set_constraints(cell.value->update_constraints());
144 return _grid.constraints(os_settings::left_to_right());
146 void set_layout(widget_layout
const& context)
noexcept override
149 _grid.set_layout(context.shape, theme().baseline_adjustment());
152 for (hilet& cell : _grid) {
153 cell.value->set_layout(context.transform(cell.shape, 0.0f));
156 void draw(draw_context
const& context)
noexcept override
159 for (hilet& cell : _grid) {
160 cell.value->draw(context);
164 [[nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
166 hi_axiom(loop::main().on_thread());
169 return _text_widget->hitbox_test_from_parent(position);
179 decltype(
label)::callback_token _label_cbt;
180 decltype(
text_style)::callback_token _text_style_cbt;
181 decltype(
alignment)::callback_token _alignment_cbt;
183 std::unique_ptr<icon_widget> _icon_widget;
184 std::unique_ptr<text_widget> _text_widget;
185 grid_layout<widget *> _grid;
187 void set_attributes() noexcept {}
188 void set_attributes(label_widget_attribute
auto&& first, label_widget_attribute
auto&&...rest)
noexcept
190 if constexpr (forward_of<
decltype(first), observer<hi::label>>) {
191 label = hi_forward(first);
192 }
else if constexpr (forward_of<
decltype(first), observer<hi::alignment>>) {
194 }
else if constexpr (forward_of<
decltype(first), observer<hi::semantic_text_style>>) {
197 hi_static_no_default();
200 set_attributes(hi_forward(rest)...);
207 _icon_widget = std::make_unique<icon_widget>(
this,
label.get<
"icon">());
208 _text_widget = std::make_unique<text_widget>(
this,
label.get<
"text">());
211 _text_widget->mode =
mode;
213 _alignment_cbt =
alignment.subscribe([
this](
auto...) {
215 _icon_widget->alignment = hi::alignment::middle_center();
220 (*_alignment_cbt)(*alignment);
222 _text_style_cbt =
text_style.subscribe([
this](
auto...) {
224 case semantic_text_style::label:
225 _icon_widget->color = color::foreground();
227 case semantic_text_style::small_label:
228 _icon_widget->color = color::foreground();
230 case semantic_text_style::warning:
231 _icon_widget->color = color::orange();
233 case semantic_text_style::error:
234 _icon_widget->color = color::red();
236 case semantic_text_style::help:
237 _icon_widget->color = color::indigo();
239 case semantic_text_style::placeholder:
240 _icon_widget->color = color::gray();
242 case semantic_text_style::link:
243 _icon_widget->color = color::blue();
246 _icon_widget->color = color::foreground();