HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
toolbar_widget.hpp
1// Copyright Take Vos 2020.
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
5#pragma once
6
7#include "widget.hpp"
8#include "grid_layout.hpp"
9#include "../alignment.hpp"
10#include <memory>
11#include <ranges>
12
13namespace hi::inline v1 {
14
28class toolbar_widget final : public widget {
29public:
30 using super = widget;
31
39 toolbar_widget(gui_window &window, widget *parent) noexcept;
40
56 template<typename Widget, horizontal_alignment Alignment = horizontal_alignment::left, typename... Args>
57 Widget &make_widget(Args &&...args)
58 {
59 auto widget = std::make_unique<Widget>(window, this, std::forward<Args>(args)...);
60 return static_cast<Widget &>(add_widget(Alignment, std::move(widget)));
61 }
62
64 [[nodiscard]] generator<widget *> children() const noexcept override
65 {
66 for (hilet &child : _left_children) {
67 co_yield child.get();
68 }
69 for (hilet &child : std::ranges::reverse_view(_right_children)) {
70 co_yield child.get();
71 }
72 }
73
74 widget_constraints const &set_constraints() noexcept;
75 void set_layout(widget_layout const &layout) noexcept override;
76 void draw(draw_context const &context) noexcept override;
77 hitbox hitbox_test(point3 position) const noexcept override;
78 [[nodiscard]] color focus_color() const noexcept override;
80private:
81 std::vector<std::unique_ptr<widget>> _left_children;
82 std::vector<std::unique_ptr<widget>> _right_children;
83 grid_layout _grid_layout;
84 margins _inner_margins;
85
86 void update_constraints_for_child(
87 widget &child,
88 ssize_t index,
89 float &shared_height,
90 float &shared_top_margin,
91 float &shared_bottom_margin) noexcept;
92
93 void update_layout_for_child(widget &child, ssize_t index, widget_layout const &context) const noexcept;
94
97 widget &add_widget(horizontal_alignment alignment, std::unique_ptr<widget> widget) noexcept;
98
103 bool tab_button_has_focus() const noexcept;
104};
105
106} // namespace hi::inline v1
#define hilet
Invariant should be the default for variables.
Definition required.hpp:23
horizontal_alignment
Definition alignment.hpp:31
STL namespace.
A return value for a generator-function.
Definition generator.hpp:27
Definition gui_window.hpp:40
A toolbar widget is located at the top of a window and lays out its children horizontally.
Definition toolbar_widget.hpp:28
Widget & make_widget(Args &&...args)
Add a widget directly to this toolbar-widget.
Definition toolbar_widget.hpp:57
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:40
T move(T... args)