HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
window_widget.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2020-2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
9#pragma once
10
11#include "widget.hpp"
12#include "toolbar_widget.hpp"
14#include "grid_widget.hpp"
16#include "../label.hpp"
17
18namespace hi { inline namespace v1 {
19
26class window_widget final : public widget
27{
28public:
29 using super = widget;
30
31 observer<label> title;
32
33 window_widget(forward_of<observer<label>> auto&& title) noexcept :
34 super(nullptr), title(hi_forward(title))
35 {
36 _toolbar = std::make_unique<toolbar_widget>(this);
37
38 if (operating_system::current == operating_system::windows) {
39#if HI_OPERATING_SYSTEM == HI_OS_WINDOWS
40 _system_menu = &_toolbar->make_widget<system_menu_widget>();
41 this->_system_menu->icon = this->title.get<"icon">();
42#endif
44 } else if (operating_system::current == operating_system::macos) {
45 _toolbar->make_widget<window_traffic_lights_widget>();
46 } else {
48 }
49
50 _content = std::make_unique<grid_widget>(this);
51 }
52
57 [[nodiscard]] color background_color() noexcept;
58
63 [[nodiscard]] grid_widget& content() noexcept;
64
69 [[nodiscard]] toolbar_widget& toolbar() noexcept;
70
72 [[nodiscard]] generator<widget_intf&> children(bool include_invisible) noexcept override;
73 [[nodiscard]] box_constraints update_constraints() noexcept override;
74 void set_layout(widget_layout const& context) noexcept override;
75 void draw(draw_context const& context) noexcept override;
76 [[nodiscard]] hitbox hitbox_test(point2 position) const noexcept override;
77 bool handle_event(gui_event const& event) noexcept override;
78 bool process_event(gui_event const& event) const noexcept override;
79 void set_window(gui_window *window) noexcept override;
80 [[nodiscard]] gui_window *window() const noexcept override;
82private:
83 gui_window *_window = nullptr;
84
85 std::unique_ptr<grid_widget> _content;
86 box_constraints _content_constraints;
87 box_shape _content_shape;
88
89 std::unique_ptr<toolbar_widget> _toolbar;
90 box_constraints _toolbar_constraints;
91 box_shape _toolbar_shape;
92
93 mutable bool _can_resize_width;
94 mutable bool _can_resize_height;
95
96#if HI_OPERATING_SYSTEM == HI_OS_WINDOWS
97 system_menu_widget *_system_menu = nullptr;
98#endif
99};
100
101}} // namespace hi::v1
Functionality for labels, text and icons.
Defines widget.
Defines window_traffic_lights_widget.
Defines system_menu_widget.
Defines toolbar_widget.
Defines grid_widget.
#define hi_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:279
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
@ right
Align the text to the right side.
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
This is a RGBA floating point color.
Definition color.hpp:42
Draw context for drawing using the HikoGUI shaders.
Definition draw_context.hpp:209
A user interface event.
Definition gui_event.hpp:74
Definition widget_intf.hpp:16
The layout of a widget.
Definition widget_layout.hpp:35
2D constraints.
Definition box_constraints.hpp:22
Definition box_shape.hpp:15
A GUI widget that lays out child-widgets in a grid with variable sized cells.
Definition grid_widget.hpp:39
The system menu widget.
Definition system_menu_widget.hpp:26
A toolbar widget is located at the top of a window and lays out its children horizontally.
Definition toolbar_widget.hpp:34
An interactive graphical object as part of the user-interface.
Definition widget.hpp:36
widget(widget *parent) noexcept
Window control button widget.
Definition window_traffic_lights_widget.hpp:26
The top-level window widget.
Definition window_widget.hpp:27
grid_widget & content() noexcept
Get a reference to the window's content widget.
toolbar_widget & toolbar() noexcept
Get a reference to window's toolbar widget.
color background_color() noexcept
The background color of the window.