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 "../flow_layout.hpp"
9#include "../alignment.hpp"
10#include <memory>
11#include <ranges>
12
13namespace tt {
14
28class toolbar_widget final : public widget {
29public:
30 using super = widget;
31
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 widget->init();
61 return static_cast<Widget &>(add_widget(Alignment, std::move(widget)));
62 }
63
65 [[nodiscard]] float margin() const noexcept override;
66 [[nodiscard]] bool constrain(utc_nanoseconds display_time_point, bool need_reconstrain) noexcept;
67 void layout(utc_nanoseconds display_time_point, bool need_layout) noexcept override;
68 void draw(draw_context context, utc_nanoseconds display_time_point) noexcept override;
69 hitbox hitbox_test(point2 position) const noexcept override;
71private:
72 std::vector<widget *> _left_children;
73 std::vector<widget *> _right_children;
74 flow_layout _layout;
75
76 void update_constraints_for_child(widget const &child, ssize_t index, float &shared_height) noexcept;
77
78 void update_layout_for_child(widget &child, ssize_t index) const noexcept;
79
82 widget &add_widget(horizontal_alignment alignment, std::unique_ptr<widget> widget) noexcept;
83};
84
85} // namespace tt
horizontal_alignment
Horizontal alignment.
Definition alignment.hpp:31
alignment
Vertical and horizontal alignment.
Definition alignment.hpp:47
STL namespace.
Layout algorithm.
Definition flow_layout.hpp:52
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:28
Definition gui_window.hpp:39
Definition hitbox.hpp:14
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:37
widget *const parent
Pointer to the parent widget.
Definition widget.hpp:46
virtual void init() noexcept
Should be called right after allocating and constructing a widget.
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:41
widget(gui_window &window, widget *parent) noexcept
T move(T... args)