HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
toolbar_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 "../alignment.hpp"
13#include <memory>
14#include <ranges>
15
16namespace hi { inline namespace v1 {
17class system_menu_widget;
18class window_traffic_lights_widget;
19
35class toolbar_widget final : public widget {
36public:
37 using super = widget;
38
44
60 template<typename Widget, horizontal_alignment Alignment = horizontal_alignment::left, typename... Args>
61 Widget& make_widget(Args&&...args)
62 {
63 auto widget = std::make_unique<Widget>(this, std::forward<Args>(args)...);
64 return static_cast<Widget&>(add_widget(Alignment, std::move(widget)));
65 }
66
68 [[nodiscard]] generator<widget *> children() const noexcept override
69 {
70 for (hilet& child : _left_children) {
71 co_yield child.get();
72 }
73 for (hilet& child : std::ranges::reverse_view(_right_children)) {
74 co_yield child.get();
75 }
76 }
77
78 widget_constraints const& set_constraints(set_constraints_context const &context) noexcept;
79 void set_layout(widget_layout const& context) noexcept override;
80 void draw(draw_context const& context) noexcept override;
81 hitbox hitbox_test(point3 position) const noexcept override;
82 [[nodiscard]] color focus_color() const noexcept override;
84private:
85 std::unique_ptr<window_traffic_lights_widget> _controls;
86 std::unique_ptr<system_menu_widget> _system_menu;
87 std::vector<std::unique_ptr<widget>> _left_children;
88 std::vector<std::unique_ptr<widget>> _right_children;
89 margins _inner_margins;
90
91 void update_constraints_for_child(
92 set_constraints_context const &context,
93 widget& child,
94 ssize_t index,
95 float& shared_height,
96 float& shared_top_margin,
97 float& shared_bottom_margin,
98 widget_baseline& shared_baseline) noexcept;
99
100 void update_layout_for_child(widget& child, ssize_t index, widget_layout const& context) const noexcept;
101
104 widget& add_widget(horizontal_alignment alignment, std::unique_ptr<widget> widget) noexcept;
105
110 bool tab_button_has_focus() const noexcept;
111};
112
113}} // namespace hi::v1
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
Defines widget.
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
std::ptrdiff_t ssize_t
Signed size/index into an array.
Definition utility.hpp:173
A toolbar widget is located at the top of a window and lays out its children horizontally.
Definition toolbar_widget.hpp:35
Widget & make_widget(Args &&...args)
Add a widget directly to this toolbar-widget.
Definition toolbar_widget.hpp:61
toolbar_widget(widget *parent) noexcept
Constructs an empty row/column widget.
An interactive graphical object as part of the user-interface.
Definition widget.hpp:45
widget(widget *parent) noexcept
widget * parent
Pointer to the parent widget.
Definition widget.hpp:50
T move(T... args)