87 set_attributes(std::forward<Attributes>(attributes)...);
91 [[nodiscard]] generator<widget_intf &> children(
bool include_invisible)
noexcept override
93 co_yield *_icon_widget;
94 co_yield *_text_widget;
102 auto const resolved_alignment = resolve(*
alignment,
true);
105 if (to_bool(
label->icon) and to_bool(
label->text)) {
109 _grid.add_cell(0, 0, _icon_widget.get());
110 _grid.add_cell(1, 0, _text_widget.get(),
true);
113 _grid.add_cell(0, 0, _text_widget.get(),
true);
114 _grid.add_cell(1, 0, _icon_widget.get());
118 _grid.add_cell(0, 0, _icon_widget.get());
119 _grid.add_cell(0, 1, _text_widget.get(),
true);
123 _grid.add_cell(0, 0, _text_widget.get(),
true);
124 _grid.add_cell(0, 1, _icon_widget.get());
126 hi_no_default(
"alignment is not allowed to be middle-center.");
128 }
else if (to_bool(
label->icon)) {
130 _grid.add_cell(0, 0, _icon_widget.get());
131 }
else if (to_bool(
label->text)) {
133 _grid.add_cell(0, 0, _text_widget.get());
136 auto const icon_size =
138 theme().large_icon_size() :
139 (theme().text_style(*text_style)->size * theme().pixel_density).in(pixels_per_em);
141 _icon_widget->minimum = extent2{icon_size, icon_size};
142 _icon_widget->maximum = extent2{icon_size, icon_size};
144 for (
auto& cell : _grid) {
145 cell.set_constraints(cell.value->update_constraints());
148 return _grid.constraints(os_settings::left_to_right());
150 void set_layout(widget_layout
const& context)
noexcept override
153 _grid.set_layout(context.shape, theme().baseline_adjustment());
156 for (
auto const& cell : _grid) {
160 void draw(draw_context
const& context)
noexcept override
163 for (
auto const& cell : _grid) {
164 cell.value->draw(context);
168 [[nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
170 hi_axiom(loop::main().on_thread());
173 return _text_widget->hitbox_test_from_parent(position);
185 grid_layout<widget *> _grid;
187 callback<void(hi::label)> _label_cbt;
188 callback<void(semantic_text_style)> _text_style_cbt;
191 void set_attributes() noexcept {}
193 template<label_widget_attribute First, label_widget_attribute... Rest>
194 void set_attributes(First&& first, Rest&&...rest)
noexcept
196 if constexpr (forward_of<First, observer<hi::label>>) {
197 label = std::forward<First>(first);
198 }
else if constexpr (forward_of<First, observer<hi::alignment>>) {
200 }
else if constexpr (forward_of<First, observer<hi::semantic_text_style>>) {
203 hi_static_no_default();
206 set_attributes(std::forward<Rest>(rest)...);
213 _icon_widget = std::make_unique<icon_widget>(
this,
label.
sub<
"icon">());
214 _text_widget = std::make_unique<text_widget>(
this,
label.
sub<
"text">());
217 _text_widget->set_mode(mode());
219 _alignment_cbt =
alignment.subscribe([
this](
auto...) {
221 _icon_widget->alignment = hi::alignment::middle_center();
230 case semantic_text_style::label:
231 _icon_widget->color = color::foreground();
233 case semantic_text_style::small_label:
234 _icon_widget->color = color::foreground();
236 case semantic_text_style::warning:
237 _icon_widget->color = color::orange();
239 case semantic_text_style::error:
240 _icon_widget->color = color::red();
242 case semantic_text_style::help:
243 _icon_widget->color = color::indigo();
245 case semantic_text_style::placeholder:
246 _icon_widget->color = color::gray();
248 case semantic_text_style::link:
249 _icon_widget->color = color::blue();
252 _icon_widget->color = color::foreground();