12#include "../macros.hpp"
15hi_export_module(hikogui.widgets.overlay_widget);
17hi_export
namespace hi {
58 new_widget->set_parent(
this);
60 auto old_widget = std::exchange(_content,
std::move(new_widget));
62 old_widget->set_parent(
nullptr);
65 ++global_counter<
"overlay_widget:set_widget:constrain">;
78 template<
typename Widget,
typename... Args>
81 hi_axiom(loop::main().on_thread());
82 hi_assert(_content ==
nullptr);
91 [[nodiscard]] generator<widget_intf&> children(
bool include_invisible)
noexcept override
101 _content_constraints = _content->update_constraints();
102 return _content_constraints;
105 void set_layout(widget_layout
const& context)
noexcept override
110 _layout.clipping_rectangle = context.rectangle() + theme().border_width();
112 auto const content_rectangle = context.rectangle();
113 _content_shape = box_shape{_content_constraints, content_rectangle, theme().baseline_adjustment()};
116 _content->set_layout(_layout.transform(_content_shape, context.rectangle()));
119 void draw(draw_context
const& context)
noexcept override
122 if (overlaps(context,
layout())) {
123 draw_background(context);
125 _content->draw(context);
129 [[nodiscard]]
color background_color() const noexcept
override
131 return theme().fill_color(_layout.layer + 1);
134 [[nodiscard]]
color foreground_color() const noexcept
override
136 return theme().border_color(_layout.layer + 1);
145 [[nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
147 hi_axiom(loop::main().on_thread());
150 return _content->hitbox_test_from_parent(position);
156 bool handle_event(gui_event
const& event)
noexcept override
163 std::unique_ptr<widget> _content;
164 box_constraints _content_constraints;
165 box_shape _content_shape;
167 void draw_background(draw_context
const& context)
noexcept
@ window_reconstrain
Request that widget get constraint on the next frame.
Definition gui_event_type.hpp:48
@ rectangle
The gui_event has rectangle data.
Definition gui_event_variant.hpp:44
@ partial
A widget is partially enabled.
Definition widget_state.hpp:73
@ invisible
The widget is invisible.
Definition widget_state.hpp:41
The HikoGUI namespace.
Definition array_generic.hpp:21
The HikoGUI API version 1.
Definition array_generic.hpp:22
@ color
A color value was modified.
Definition style_modify_mask.hpp:27
@ outside
The border is drawn outside the edge of a quad.
Definition draw_context_intf.hpp:39
widget_layout const & layout() const noexcept
Get the current layout for this widget.
Definition widget_intf.hpp:241
A GUI widget which may exist anywhere on a window overlaid above any other widget.
Definition overlay_widget.hpp:43
overlay_widget() noexcept
Constructs an empty overlay widget.
Definition overlay_widget.hpp:53
Widget & emplace(Args &&... args) noexcept
Add a content widget directly to this overlay widget.
Definition overlay_widget.hpp:79
void scroll_to_show() noexcept
Scroll to show the important part of the widget.
Definition widget_intf.hpp:347
widget() noexcept
Constructor for creating sub views.
Definition widget.hpp:50
box_constraints update_constraints() noexcept override
Update the constraints of the widget.
Definition widget.hpp:110
bool process_event(gui_event const &event) const noexcept override
Send a event to the window.
Definition widget.hpp:125