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 "grid_layout.hpp"
13#include "../alignment.hpp"
14#include <memory>
15#include <ranges>
16
17namespace hi { inline namespace v1 {
18
34class toolbar_widget final : public widget {
35public:
36 using super = widget;
37
43 toolbar_widget(gui_window& window, widget *parent) noexcept;
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>(window, 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() noexcept;
79 void set_layout(widget_layout const& layout) 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::vector<std::unique_ptr<widget>> _left_children;
86 std::vector<std::unique_ptr<widget>> _right_children;
87 grid_layout _grid_layout;
88 margins _inner_margins;
89
90 void update_constraints_for_child(
91 widget& child,
92 ssize_t index,
93 float& shared_height,
94 float& shared_top_margin,
95 float& shared_bottom_margin,
96 widget_baseline& shared_baseline) noexcept;
97
98 void update_layout_for_child(widget& child, ssize_t index, widget_layout const& context) const noexcept;
99
102 widget& add_widget(horizontal_alignment alignment, std::unique_ptr<widget> widget) noexcept;
103
108 bool tab_button_has_focus() const noexcept;
109};
110
111}} // 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:162
A toolbar widget is located at the top of a window and lays out its children horizontally.
Definition toolbar_widget.hpp:34
Widget & make_widget(Args &&...args)
Add a widget directly to this toolbar-widget.
Definition toolbar_widget.hpp:61
toolbar_widget(gui_window &window, widget *parent) noexcept
Constructs an empty row/column widget.
An interactive graphical object as part of the user-interface.
Definition widget.hpp:44
widget_layout const & layout() const noexcept
Get the current layout for this widget.
Definition widget.hpp:198
widget *const parent
Pointer to the parent widget.
Definition widget.hpp:53
widget(gui_window &window, widget *parent) noexcept
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:48
T move(T... args)