HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
system_menu_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 "icon_widget.hpp"
13#include "../l10n/l10n.hpp"
14#include "../macros.hpp"
15#include <memory>
16#include <string>
17#include <array>
18#include <coroutine>
19
20hi_export_module(hikogui.widgets.system_menu_widget);
21
22hi_export namespace hi { inline namespace v1 {
23
30class system_menu_widget : public widget {
31public:
32 using super = widget;
33
34 observer<icon> icon;
35
37
38 system_menu_widget(widget_intf const* parent) noexcept : super(parent)
39 {
40 _icon_widget = std::make_unique<icon_widget>(this, icon);
41 }
42
43 template<forward_of<observer<hi::icon>> Icon>
44 system_menu_widget(widget_intf const* parent, Icon&& icon) noexcept :
46 {
47 this->icon = std::forward<Icon>(icon);
48 }
49
51 [[nodiscard]] generator<widget_intf &> children(bool include_invisible) noexcept override
52 {
53 co_yield *_icon_widget;
54 }
55
56 [[nodiscard]] box_constraints update_constraints() noexcept override
57 {
58 hi_assert_not_null(_icon_widget);
59
60 _layout = {};
61 _icon_constraints = _icon_widget->update_constraints();
62
63 auto const size = extent2{theme().large_size(), theme().large_size()};
64 return {size, size, size};
65 }
66
67 void set_layout(widget_layout const& context) noexcept override
68 {
69 if (compare_store(_layout, context)) {
70 auto const icon_height =
71 context.height() < round_cast<int>(theme().large_size() * 1.2f) ? context.height() : theme().large_size();
72 auto const icon_rectangle = aarectangle{0, context.height() - icon_height, context.width(), icon_height};
73 _icon_shape = box_shape{_icon_constraints, icon_rectangle, theme().baseline_adjustment()};
74 // Leave space for window resize handles on the left and top.
75 _system_menu_rectangle = aarectangle{
76 theme().margin<float>(),
77 0.0f,
78 context.width() - theme().margin<float>(),
79 context.height() - theme().margin<float>()};
80 }
81
82 _icon_widget->set_layout(context.transform(_icon_shape));
83 }
84
85 void draw(draw_context const& context) noexcept override
86 {
87 if (mode() > widget_mode::invisible and overlaps(context, layout())) {
88 _icon_widget->draw(context);
89 }
90 }
91
92 [[nodiscard]] hitbox hitbox_test(point2 position) const noexcept override
93 {
94 hi_axiom(loop::main().on_thread());
95
96 if (mode() >= widget_mode::partial and layout().contains(position)) {
97 // Only the top-left square should return ApplicationIcon, leave
98 // the reset to the toolbar implementation.
99 return {id, _layout.elevation, hitbox_type::application_icon};
100 } else {
101 return {};
102 }
103 }
104
106private:
107 std::unique_ptr<icon_widget> _icon_widget;
108 box_constraints _icon_constraints;
109 box_shape _icon_shape;
110
111 aarectangle _system_menu_rectangle;
112};
113
114}} // namespace hi::v1
Defines widget.
Defines icon_widget.
@ partial
A widget is partially enabled.
@ invisible
The widget is invisible.
The HikoGUI namespace.
Definition array_generic.hpp:20
bool compare_store(T &lhs, U &&rhs) noexcept
Compare then store if there was a change.
Definition misc.hpp:53
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:33
A high-level geometric extent.
Definition extent2.hpp:32
Draw context for drawing using the HikoGUI shaders.
Definition draw_context_intf.hpp:209
Definition widget_intf.hpp:24
widget_id id
The numeric identifier of a widget.
Definition widget_intf.hpp:30
widget_layout const & layout() const noexcept
Get the current layout for this widget.
Definition widget_intf.hpp:206
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:35
The layout of a widget.
Definition widget_layout.hpp:56
constexpr widget_layout transform(box_shape const &child_shape, transform_command command, aarectangle new_clipping_rectangle) const noexcept
Create a new widget_layout for the child widget.
Definition widget_layout.hpp:236
2D constraints.
Definition box_constraints.hpp:25
Definition box_shape.hpp:18
A observer pointing to the whole or part of a observed_base.
Definition observer_intf.hpp:32
The system menu widget.
Definition system_menu_widget.hpp:30
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
widget() noexcept
Constructor for creating sub views.
Definition widget.hpp:55