40 auto const size =
extent2{DIAMETER * 3.0f + 2.0f * MARGIN + 2.0f * SPACING, DIAMETER + 2.0f * MARGIN};
41 return {size, size, size};
44 void set_layout(
widget_layout const& context)
noexcept override
47 auto extent = context.size();
48 if (extent.height() > floor_cast<int>(theme().large_size() * 1.2f)) {
52 closeRectangle =
aarectangle{point2(MARGIN, extent.height() / 2.0f - RADIUS),
extent2{DIAMETER, DIAMETER}};
55 aarectangle{point2(MARGIN + DIAMETER + SPACING, extent.height() / 2.0f - RADIUS),
extent2{DIAMETER, DIAMETER}};
58 point2(MARGIN + DIAMETER + SPACING + DIAMETER + SPACING, extent.height() / 2.0f - RADIUS),
61 closeWindowGlyph = find_glyph(hikogui_icon::CloseWindow);
62 minimizeWindowGlyph = find_glyph(hikogui_icon::MinimizeWindow);
63 maximizeWindowGlyph = find_glyph(hikogui_icon::MaximizeWindowMacOS);
64 restoreWindowGlyph = find_glyph(hikogui_icon::RestoreWindowMacOS);
65 auto const glyph_size = 5.0f;
67 auto const closeWindowGlyphBB = closeWindowGlyph.get_metrics().bounding_rectangle * glyph_size;
68 auto const minimizeWindowGlyphBB = minimizeWindowGlyph.get_metrics().bounding_rectangle * glyph_size;
69 auto const maximizeWindowGlyphBB = maximizeWindowGlyph.get_metrics().bounding_rectangle * glyph_size;
70 auto const restoreWindowGlyphBB = restoreWindowGlyph.get_metrics().bounding_rectangle * glyph_size;
72 closeWindowGlyphRectangle = align(closeRectangle, closeWindowGlyphBB, alignment::middle_center());
73 minimizeWindowGlyphRectangle = align(minimizeRectangle, minimizeWindowGlyphBB, alignment::middle_center());
74 maximizeWindowGlyphRectangle = align(maximizeRectangle, maximizeWindowGlyphBB, alignment::middle_center());
75 restoreWindowGlyphRectangle = align(maximizeRectangle, restoreWindowGlyphBB, alignment::middle_center());
82 auto const close_circle_color = (phase() == widget_phase::inactive) ?
color(0.246f, 0.246f, 0.246f) :
83 pressedClose ?
color(1.0f, 0.242f, 0.212f) :
84 color(1.0f, 0.1f, 0.082f);
87 auto const minimize_circle_color = (phase() == widget_phase::inactive) ?
color(0.246f, 0.246f, 0.246f) :
88 pressedMinimize ?
color(1.0f, 0.847f, 0.093f) :
89 color(0.784f, 0.521f, 0.021f);
90 context.draw_box(
layout(), minimizeRectangle, minimize_circle_color,
corner_radii{RADIUS});
92 auto const maximize_circle_color = (phase() == widget_phase::inactive) ?
color(0.246f, 0.246f, 0.246f) :
93 pressedMaximize ?
color(0.223f, 0.863f, 0.1f) :
94 color(0.082f, 0.533f, 0.024f);
96 context.draw_box(
layout(), maximizeRectangle, maximize_circle_color,
corner_radii{RADIUS});
98 if (phase() == widget_phase::hover) {
100 layout(), translate_z(0.1f) * closeWindowGlyphRectangle, closeWindowGlyph,
color{0.319f, 0.0f, 0.0f});
102 layout(), translate_z(0.1f) * minimizeWindowGlyphRectangle, minimizeWindowGlyph,
color{0.212f, 0.1f, 0.0f});
104 if (
layout().window_size_state == gui_window_size::maximized) {
106 layout(), translate_z(0.1f) * restoreWindowGlyphRectangle, restoreWindowGlyph,
color{0.0f, 0.133f, 0.0f});
110 translate_z(0.1f) * maximizeWindowGlyphRectangle,
112 color{0.0f, 0.133f, 0.0f});
118 bool handle_event(
gui_event const& event)
noexcept override
120 switch (event.
type()) {
121 case gui_event_type::mouse_move:
122 case gui_event_type::mouse_drag:
125 auto state_has_changed =
false;
129 if (state_has_changed) {
135 case gui_event_type::mouse_exit:
137 hoverMinimize =
false;
138 hoverMaximize =
false;
142 case gui_event_type::mouse_down:
148 pressedMinimize =
true;
151 pressedMaximize =
true;
158 case gui_event_type::mouse_up:
160 pressedClose =
false;
161 pressedMinimize =
false;
162 pressedMaximize =
false;
172 switch (
layout().window_size_state) {
173 case gui_window_size::normal:
176 case gui_window_size::maximized:
192 [[nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
194 hi_axiom(loop::main().on_thread());
197 (closeRectangle.
contains(position) or minimizeRectangle.
contains(position) or maximizeRectangle.
contains(position))) {
198 return hitbox{
id, _layout.elevation, hitbox_type::button};
205 constexpr static int GLYPH_SIZE = 5;
206 constexpr static int RADIUS = 5;
207 constexpr static int DIAMETER = RADIUS * 2;
208 constexpr static int MARGIN = 10;
209 constexpr static int SPACING = 8;
215 font_book::font_glyph_type closeWindowGlyph;
216 font_book::font_glyph_type minimizeWindowGlyph;
217 font_book::font_glyph_type maximizeWindowGlyph;
218 font_book::font_glyph_type restoreWindowGlyph;
225 bool hoverClose =
false;
226 bool hoverMinimize =
false;
227 bool hoverMaximize =
false;
229 bool pressedClose =
false;
230 bool pressedMinimize =
false;
231 bool pressedMaximize =
false;