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
50 void set_widget(std::unique_ptr<widget> new_widget) noexcept;
51
61 template<typename Widget, typename... Args>
62 Widget& make_widget(Args&&...args) noexcept
63 {
64 hi_axiom(loop::main().on_thread());
65 hi_assert(_content == nullptr);
66
67 auto tmp = std::make_unique<Widget>(this, std::forward<Args>(args)...);
68 auto& ref = *tmp;
69 set_widget(std::move(tmp));
70 return ref;
71 }
72
74 [[nodiscard]] generator<widget const &> children(bool include_invisible) const noexcept override
75 {
76 co_yield *_content;
77 }
78
79 [[nodiscard]] box_constraints update_constraints() noexcept override;
80 void set_layout(widget_layout const& context) noexcept override;
81 void draw(draw_context const& context) noexcept override;
82 [[nodiscard]] color background_color() const noexcept override;
83 [[nodiscard]] color foreground_color() const noexcept override;
84 void scroll_to_show(hi::aarectanglei rectangle) noexcept override;
85 [[nodiscard]] hitbox hitbox_test(point2i position) const noexcept override;
87private:
88 std::unique_ptr<widget> _content;
89 box_constraints _content_constraints;
90 box_shape _content_shape;
91
92 void draw_background(draw_context const& context) noexcept;
93};
94
95}} // namespace hi::v1
Defines widget.
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:184
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
@ rectangle
The gui_event has rectangle data.
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
This is a RGBA floating point color.
Definition color.hpp:42
Draw context for drawing using the HikoGUI shaders.
Definition draw_context.hpp:211
2D constraints.
Definition box_constraints.hpp:22
Definition box_shape.hpp:15
A GUI widget which may exist anywhere on a window overlaid above any other widget.
Definition overlay_widget.hpp:38
overlay_widget(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:62
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
void scroll_to_show() noexcept
Scroll to show the important part of the widget.
Definition widget.hpp:301
The layout of a widget.
Definition widget_layout.hpp:38
T move(T... args)