31 constexpr static auto prefix = Name /
"window";
33 observer<label> title;
37 _toolbar = std::make_unique<toolbar_widget<prefix>>(
this);
39 if (operating_system::current == operating_system::windows) {
40#if HI_OPERATING_SYSTEM == HI_OS_WINDOWS
42 this->_system_menu->icon = this->title.get<
"icon">();
45 }
else if (operating_system::current == operating_system::macos) {
51 _content = std::make_unique<grid_widget<prefix>>(
this);
54 void set_window(gui_window& window)
noexcept
82 [[nodiscard]] generator<widget const&> children(
bool include_invisible)
const noexcept override
93 _content_constraints = _content->update_constraints();
94 _toolbar_constraints = _toolbar->update_constraints();
98 _toolbar_constraints.margins.left() + _toolbar_constraints.minimum.
width() + _toolbar_constraints.margins.right(),
99 _content_constraints.margins.left() + _content_constraints.minimum.
width() + _content_constraints.margins.right());
101 _toolbar_constraints.margins.left() + _toolbar_constraints.preferred.
width() + _toolbar_constraints.margins.right(),
102 _content_constraints.margins.left() + _content_constraints.preferred.
width() + _content_constraints.margins.right());
104 _toolbar_constraints.margins.left() + _toolbar_constraints.maximum.
width() + _toolbar_constraints.margins.right(),
105 _content_constraints.margins.left() + _content_constraints.maximum.
width() + _content_constraints.margins.right());
109 _toolbar_constraints.margins.top() +
110 _toolbar_constraints.preferred.
height() +
111 std::max(_toolbar_constraints.margins.bottom(), _content_constraints.margins.top()) +
112 _content_constraints.minimum.
height() +
113 _content_constraints.margins.bottom();
114 r.preferred.height() =
115 _toolbar_constraints.margins.top() +
116 _toolbar_constraints.preferred.
height() +
117 std::max(_toolbar_constraints.margins.bottom(), _content_constraints.margins.top()) +
118 _content_constraints.preferred.
height() +
119 _content_constraints.margins.bottom();
121 _toolbar_constraints.margins.top() +
122 _toolbar_constraints.preferred.
height() +
123 std::max(_toolbar_constraints.margins.bottom(), _content_constraints.margins.top()) +
124 _content_constraints.maximum.
height() +
125 _content_constraints.margins.bottom();
130 inplace_max(r.minimum.width(), os_settings::minimum_window_width());
131 inplace_max(r.minimum.height(), os_settings::minimum_window_height());
133 inplace_clamp(r.maximum.width(), r.minimum.width(), os_settings::maximum_window_width());
134 inplace_clamp(r.maximum.height(), r.minimum.height(), os_settings::maximum_window_height());
136 inplace_clamp(r.preferred.width(), r.minimum.width(), r.maximum.width());
137 inplace_clamp(r.preferred.height(), r.minimum.height(), r.maximum.height());
139 _can_resize_width = r.minimum.width() != r.maximum.width();
140 _can_resize_height = r.minimum.height() != r.maximum.height();
145 void set_layout(widget_layout
const& context)
noexcept override
148 hilet toolbar_height = _toolbar_constraints.preferred.
height();
149 hilet between_margin =
std::max(_toolbar_constraints.margins.bottom(), _content_constraints.margins.top());
151 hilet toolbar_rectangle = aarectanglei{
153 _toolbar_constraints.margins.left(), context.height() - toolbar_height - _toolbar_constraints.margins.top()},
155 context.width() - _toolbar_constraints.margins.right(),
156 context.height() - _toolbar_constraints.margins.top()}};
157 _toolbar_shape = box_shape{_toolbar_constraints, toolbar_rectangle, theme<prefix>.cap_height(
this)};
159 hilet content_rectangle = aarectanglei{
160 point2i{_content_constraints.margins.left(), _content_constraints.margins.bottom()},
161 point2i{context.width() - _content_constraints.margins.right(), toolbar_rectangle.bottom() - between_margin}};
162 _content_shape = box_shape{_content_constraints, content_rectangle, theme<prefix>.cap_height(
this)};
164 _toolbar->set_layout(context.transform(_toolbar_shape));
165 _content->set_layout(context.transform(_content_shape));
168 void draw(widget_draw_context& context)
noexcept override
171 _toolbar->draw(context);
172 _content->draw(context);
176 [[nodiscard]] hitbox hitbox_test(point2i position)
const noexcept override
178 constexpr float BORDER_WIDTH = 10.0f;
182 auto r = _toolbar->hitbox_test_from_parent(position);
183 r = _content->hitbox_test_from_parent(position, r);
185 hilet is_on_l_edge = position.x() <= BORDER_WIDTH;
186 hilet is_on_r_edge = position.x() >= (layout.width() - BORDER_WIDTH);
187 hilet is_on_b_edge = position.y() <= BORDER_WIDTH;
188 hilet is_on_t_edge = position.y() >= (layout.height() - BORDER_WIDTH);
191 if (is_on_l_edge and is_on_b_edge) {
192 if (_can_resize_width and _can_resize_height) {
193 return {
id, layout.
elevation, hitbox_type::bottom_left_resize_corner};
194 }
else if (_can_resize_width) {
195 return {
id, layout.
elevation, hitbox_type::left_resize_border};
196 }
else if (_can_resize_height) {
197 return {
id, layout.
elevation, hitbox_type::bottom_resize_border};
199 }
else if (is_on_r_edge and is_on_b_edge) {
200 if (_can_resize_width and _can_resize_height) {
201 return {
id, layout.
elevation, hitbox_type::bottom_right_resize_corner};
202 }
else if (_can_resize_width) {
203 return {
id, layout.
elevation, hitbox_type::right_resize_border};
204 }
else if (_can_resize_height) {
205 return {
id, layout.
elevation, hitbox_type::bottom_resize_border};
207 }
else if (is_on_l_edge and is_on_t_edge) {
208 if (_can_resize_width and _can_resize_height) {
209 return {
id, layout.
elevation, hitbox_type::top_left_resize_corner};
210 }
else if (_can_resize_width) {
211 return {
id, layout.
elevation, hitbox_type::left_resize_border};
212 }
else if (_can_resize_height) {
213 return {
id, layout.
elevation, hitbox_type::top_resize_border};
215 }
else if (is_on_r_edge and is_on_t_edge) {
216 if (_can_resize_width and _can_resize_height) {
217 return {
id, layout.
elevation, hitbox_type::top_right_resize_corner};
218 }
else if (_can_resize_width) {
219 return {
id, layout.
elevation, hitbox_type::right_resize_border};
220 }
else if (_can_resize_height) {
221 return {
id, layout.
elevation, hitbox_type::top_resize_border};
226 if (r.type != hitbox_type::scroll_bar) {
227 if (is_on_l_edge and _can_resize_width) {
228 return {
id, layout.
elevation, hitbox_type::left_resize_border};
229 }
else if (is_on_r_edge and _can_resize_width) {
230 return {
id, layout.
elevation, hitbox_type::right_resize_border};
231 }
else if (is_on_b_edge and _can_resize_height) {
232 return {
id, layout.
elevation, hitbox_type::bottom_resize_border};
233 }
else if (is_on_t_edge and _can_resize_height) {
234 return {
id, layout.
elevation, hitbox_type::top_resize_border};
241 bool handle_event(gui_event
const& event)
noexcept override
245 switch (event.type()) {
246 case gui_toolbar_open:
248 gui_event::window_set_keyboard_target(
id, keyboard_focus_group::toolbar, keyboard_focus_direction::forward));
254 bool process_event(gui_event
const& event)
const noexcept override
256 if (_window ==
nullptr) {
263 if (not _events_before_window.
empty()) {
264 for (
hilet& e : _events_before_window) {
265 _window->process_event(e);
267 _events_before_window.
clear();
270 return _window->process_event(event);
277 gui_window *_window =
nullptr;
282 box_constraints _content_constraints;
283 box_shape _content_shape;
286 box_constraints _toolbar_constraints;
287 box_shape _toolbar_shape;
289 mutable bool _can_resize_width;
290 mutable bool _can_resize_height;
292#if HI_OPERATING_SYSTEM == HI_OS_WINDOWS
293 system_menu_widget<prefix> *_system_menu =
nullptr;