HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
overlay_widget.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2021.
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
13namespace hi { inline namespace v1 {
14
38class overlay_widget final : public widget {
39public:
40 using super = widget;
41
43
49 overlay_widget(gui_window& window, widget *parent) noexcept;
50
51 void set_widget(std::unique_ptr<widget> new_widget) noexcept;
52
62 template<typename Widget, typename... Args>
63 Widget& make_widget(Args&&...args) noexcept
64 {
65 hi_axiom(is_gui_thread());
66 hi_axiom(not _content);
67
68 auto tmp = std::make_unique<Widget>(window, this, std::forward<Args>(args)...);
69 auto& ref = *tmp;
70 set_widget(std::move(tmp));
71 return ref;
72 }
73
75 [[nodiscard]] generator<widget *> children() const noexcept override
76 {
77 co_yield _content.get();
78 }
79
80 widget_constraints const& set_constraints() noexcept override;
81 void set_layout(widget_layout const& layout) noexcept override;
82 void draw(draw_context const& context) noexcept override;
83 [[nodiscard]] color background_color() const noexcept override;
84 [[nodiscard]] color foreground_color() const noexcept override;
85 void scroll_to_show(hi::aarectangle rectangle) noexcept override;
86 [[nodiscard]] hitbox hitbox_test(point3 position) const noexcept override;
88private:
89 std::unique_ptr<widget> _content;
90
91 void draw_background(draw_context const& context) noexcept;
92};
93
94}} // namespace hi::v1
Defines widget.
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
A GUI widget which may exist anywhere on a window overlaid above any other widget.
Definition overlay_widget.hpp:38
overlay_widget(gui_window &window, widget *parent) noexcept
Constructs an empty overlay widget.
Widget & make_widget(Args &&...args) noexcept
Add a content widget directly to this overlay widget.
Definition overlay_widget.hpp:63
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
void scroll_to_show() noexcept
Scroll to show the important part of the widget.
Definition widget.hpp:313
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:48
The constraints of a widget.
Definition widget_constraints.hpp:26
The layout of a widget.
Definition widget_layout.hpp:37
T move(T... args)