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 "../geometry/axis.hpp"
13#include "../label.hpp"
14
15namespace hi { inline namespace v1 {
16class toolbar_widget;
17class grid_widget;
18
19template<typename Context>
20concept window_widget_attribute = forward_of<Context, observer<hi::label>>;
21
28class window_widget final : public widget {
29public:
30 using super = widget;
31
32 observer<label> title;
33
34 window_widget(gui_window *window, window_widget_attribute auto&&...attributes) noexcept : window_widget(window)
35 {
36 set_attributes(hi_forward(attributes)...);
37 }
38
43 [[nodiscard]] color background_color() noexcept;
44
49 [[nodiscard]] grid_widget& content() noexcept;
50
55 [[nodiscard]] toolbar_widget& toolbar() noexcept;
56
57 [[nodiscard]] axis resize_axis() const noexcept
58 {
59 auto r = axis::none;
60 if (_constraints.minimum.width() != _constraints.maximum.width()) {
61 r |= axis::width;
62 }
63 if (_constraints.minimum.height() != _constraints.maximum.height()) {
64 r |= axis::height;
65 }
66 return r;
67 }
68
70 [[nodiscard]] generator<widget *> children() const noexcept override;
71 widget_constraints const& set_constraints(set_constraints_context const& context) noexcept override;
72 void set_layout(widget_layout const& context) noexcept;
73 void draw(draw_context const& context) noexcept override;
74 [[nodiscard]] hitbox hitbox_test(point3 position) const noexcept override;
75 bool handle_event(gui_event const& event) noexcept override;
76 bool process_event(gui_event const& event) const noexcept override;
78private:
79 gui_window *_window;
80
81 aarectangle _content_rectangle;
82 std::unique_ptr<grid_widget> _content;
83
84 aarectangle _toolbar_rectangle;
85 std::unique_ptr<toolbar_widget> _toolbar;
86
87 window_widget(gui_window *window) noexcept;
88
89 void set_attributes() noexcept {}
90 void set_attributes(window_widget_attribute auto&& first, window_widget_attribute auto&&...rest) noexcept
91 {
92 if constexpr (forward_of<decltype(first), observer<hi::label>>) {
93 title = hi_forward(first);
94 } else {
96 }
97
98 set_attributes(hi_forward(rest)...);
99 }
100};
101
102}} // namespace hi::v1
#define hi_static_no_default()
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:172
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
Functionality for labels, text and icons.
Defines widget.
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
A user interface event.
Definition gui_event.hpp:76
A GUI widget that lays out child-widgets in a grid with variable sized cells.
Definition grid_widget.hpp:40
Definition set_constraints_context.hpp:15
A toolbar widget is located at the top of a window and lays out its children horizontally.
Definition toolbar_widget.hpp:35
An interactive graphical object as part of the user-interface.
Definition widget.hpp:45
widget(widget *parent) noexcept
The constraints of a widget.
Definition widget_constraints.hpp:26
The layout of a widget.
Definition widget_layout.hpp:40
The top-level window widget.
Definition window_widget.hpp:28
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.
Definition window_widget.hpp:20