89 co_yield *_icon_widget;
90 co_yield *_text_widget;
98 hilet resolved_alignment = resolve(*
alignment,
true);
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) {
156 void draw(draw_context
const&
context)
noexcept override
159 for (hilet&
cell : _grid) {
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;
188 void set_attributes(label_widget_attribute
auto&& first, label_widget_attribute
auto&&...
rest)
noexcept
191 label = hi_forward(first);
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();