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 "../layout/row_column_layout.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
59 template<typename Widget, horizontal_alignment Alignment = horizontal_alignment::left, typename... Args>
60 Widget& make_widget(Args&&...args)
61 {
62 auto widget = std::make_shared<Widget>(this, std::forward<Args>(args)...);
63 return static_cast<Widget&>(add_widget(Alignment, std::move(widget)));
64 }
65
67 [[nodiscard]] generator<widget *> children() const noexcept override
68 {
69 for (hilet& child : _children) {
70 co_yield child.value.get();
71 }
72 }
73
74 [[nodiscard]] box_constraints update_constraints() noexcept;
75 void set_layout(widget_layout const& context) noexcept override;
76 void draw(draw_context const& context) noexcept override;
77 hitbox hitbox_test(point2i position) const noexcept override;
78 [[nodiscard]] color focus_color() const noexcept override;
80private:
81 mutable row_layout<std::shared_ptr<widget>> _children;
82 mutable int _child_height_adjustment = 0;
83 size_t _spacer_index = 0;
84
85 void update_layout_for_child(widget& child, ssize_t index, widget_layout const& context) const noexcept;
86
89 widget& add_widget(horizontal_alignment alignment, std::shared_ptr<widget> widget) noexcept;
90
95 bool tab_button_has_focus() const noexcept;
96};
97
98}} // namespace hi::v1
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
types and utilities for alignment.
Defines widget.
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
geometry/margins.hpp
Definition assert.hpp:18
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:34
Widget & make_widget(Args &&...args)
Add a widget directly to this toolbar-widget.
Definition toolbar_widget.hpp:60
toolbar_widget(widget *parent) noexcept
Constructs an empty row/column widget.
An interactive graphical object as part of the user-interface.
Definition widget.hpp:46
widget(widget *parent) noexcept
widget * parent
Pointer to the parent widget.
Definition widget.hpp:51
T move(T... args)