40 auto const size =
extent2{DIAMETER * 3.0f + 2.0f * MARGIN + 2.0f * SPACING, DIAMETER + 2.0f * MARGIN};
41 return {size, size, size};
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);
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());
83 pressedClose ?
color(1.0f, 0.242f, 0.212f) :
84 color(1.0f, 0.1f, 0.082f);
88 pressedMinimize ?
color(1.0f, 0.847f, 0.093f) :
89 color(0.784f, 0.521f, 0.021f);
93 pressedMaximize ?
color(0.223f, 0.863f, 0.1f) :
94 color(0.082f, 0.533f, 0.024f);
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});
120 switch (
event.type()) {
121 case gui_event_type::mouse_move:
122 case gui_event_type::mouse_drag:
135 case gui_event_type::mouse_exit:
137 hoverMinimize =
false;
138 hoverMaximize =
false;
142 case gui_event_type::mouse_down:
143 if (
event.mouse().cause.left_button) {
147 }
else if (minimizeRectangle.
contains(
event.mouse().position)) {
148 pressedMinimize =
true;
150 }
else if (maximizeRectangle.
contains(
event.mouse().position)) {
151 pressedMaximize =
true;
158 case gui_event_type::mouse_up:
159 if (
event.mouse().cause.left_button) {
160 pressedClose =
false;
161 pressedMinimize =
false;
162 pressedMaximize =
false;
168 }
else if (minimizeRectangle.
contains(
event.mouse().position)) {
171 }
else if (maximizeRectangle.
contains(
event.mouse().position)) {
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());
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;