1 #include "lxgui/gui_frame.hpp"
3 #include "lxgui/gui_addon_registry.hpp"
4 #include "lxgui/gui_alive_checker.hpp"
5 #include "lxgui/gui_backdrop.hpp"
6 #include "lxgui/gui_event_emitter.hpp"
7 #include "lxgui/gui_factory.hpp"
8 #include "lxgui/gui_frame_renderer.hpp"
9 #include "lxgui/gui_layered_region.hpp"
10 #include "lxgui/gui_manager.hpp"
11 #include "lxgui/gui_out.hpp"
12 #include "lxgui/gui_region_tpl.hpp"
13 #include "lxgui/utils_range.hpp"
14 #include "lxgui/utils_std.hpp"
15 #include "lxgui/utils_string.hpp"
18 #include <lxgui/extern_sol2_as_args.hpp>
19 #include <lxgui/extern_sol2_state.hpp>
20 #include <lxgui/extern_sol2_variadic_args.hpp>
26 base(block, mgr, attr), event_receiver_(mgr.get_event_emitter()), frame_renderer_(attr.rdr) {
74 if (
layer.is_disabled) {
78 for (
const auto& reg :
layer.region_list) {
85 std::ostringstream str;
89 str << tab <<
" # Man. render: " <<
frame_renderer->get_name() <<
"\n";
90 str << tab <<
" # Strata : "
91 << (
strata_.has_value() ? utils::to_string(
strata_.value()) :
"parent") <<
"\n";
92 str << tab <<
" # Level : " <<
level_ <<
"\n";
99 str << tab <<
" # Inputs : none\n";
101 str << tab <<
" # Inputs :\n";
102 str << tab <<
" |-###\n";
104 str << tab <<
" | # mouse click\n";
106 str << tab <<
" | # mouse move\n";
108 str << tab <<
" | # mouse wheel\n";
109 str << tab <<
" |-###\n";
111 str << tab <<
" # Movable : " <<
is_movable_ <<
"\n";
114 str << tab <<
" # HRect inset :\n";
115 str << tab <<
" |-###\n";
120 str << tab <<
" |-###\n";
121 str << tab <<
" # Min width : " <<
min_width_ <<
"\n";
122 str << tab <<
" # Max width : " <<
max_width_ <<
"\n";
123 str << tab <<
" # Min height : " <<
min_height_ <<
"\n";
124 str << tab <<
" # Max height : " <<
max_height_ <<
"\n";
125 str << tab <<
" # Scale : " <<
scale_ <<
"\n";
126 str << tab <<
" # Update rate : " <<
update_rate_ <<
"\n";
128 str << tab <<
" # Title reg. :\n";
129 str << tab <<
" |-###\n";
131 str << tab <<
" |-###\n";
136 str << tab <<
" # Backdrop :\n";
137 str << tab <<
" |-###\n";
138 str << tab <<
" | # Background: " <<
backdrop_->get_background_file() <<
"\n";
139 str << tab <<
" | # Tilling : " <<
backdrop_->is_background_tilling() <<
"\n";
141 str << tab <<
" | # Tile size : " <<
backdrop_->get_tile_size() <<
"\n";
142 str << tab <<
" | # BG Insets :\n";
143 str << tab <<
" | |-###\n";
144 str << tab <<
" | | # left : " << insets.
left <<
"\n";
145 str << tab <<
" | | # right : " << insets.
right <<
"\n";
146 str << tab <<
" | | # top : " << insets.
top <<
"\n";
147 str << tab <<
" | | # bottom: " << insets.
bottom <<
"\n";
148 str << tab <<
" | |-###\n";
149 str << tab <<
" | # Edge : " <<
backdrop_->get_edge_file() <<
"\n";
150 str << tab <<
" | # Edge size : " <<
backdrop_->get_edge_size() <<
"\n";
151 str << tab <<
" |-###\n";
156 str << tab <<
" # Region: \n";
158 str << tab <<
" # Regions : " <<
region_list_.size() <<
"\n";
159 str << tab <<
" |-###\n";
162 str << obj.serialize(tab +
" | ");
163 str << tab <<
" |-###\n";
169 str << tab <<
" # Child: \n";
171 str << tab <<
" # Children : " <<
child_list_.size() <<
"\n";
172 str << tab <<
" |-###\n";
175 str << child.serialize(tab +
" | ");
176 str << tab <<
" |-###\n";
184 return script_name ==
"OnChar" || script_name ==
"OnDragStart" || script_name ==
"OnDragStop" ||
185 script_name ==
"OnDragMove" || script_name ==
"OnEnter" || script_name ==
"OnEvent" ||
186 script_name ==
"OnFocusGained" || script_name ==
"OnFocusLost" ||
187 script_name ==
"OnHide" || script_name ==
"OnKeyDown" || script_name ==
"OnKeyUp" ||
188 script_name ==
"OnKeyRepeat" || script_name ==
"OnLeave" || script_name ==
"OnLoad" ||
189 script_name ==
"OnMouseDown" || script_name ==
"OnMouseUp" ||
190 script_name ==
"OnMouseMove" || script_name ==
"OnDoubleClick" ||
191 script_name ==
"OnMouseWheel" || script_name ==
"OnReceiveDrag" ||
192 script_name ==
"OnShow" || script_name ==
"OnSizeChanged" || script_name ==
"OnUpdate";
198 const frame* frame_obj = down_cast<frame>(&obj);
203 for (
const auto&
function : frame_obj->
get_script(item.first)) {
232 if (!art || art->is_manually_inherited())
237 attr.
name = art->get_raw_name();
244 new_art->notify_loaded();
259 if (!child || child->is_manually_inherited())
264 attr.
name = child->get_raw_name();
271 new_child->notify_loaded();
278 <<
"\" already has a title region." << std::endl;
285 attr.
name =
"$parentTitleRegion";
293 title_region->set_manually_inherited(
true);
295 if (!title_region->is_virtual()) {
298 lua[
get_name()][
"TitleRegion"] = lua[title_region->get_name()];
310 if (child->get_name() == name)
313 const std::string& raw_name = child->get_raw_name();
314 if (utils::starts_with(raw_name,
"$parent") && raw_name.substr(7) == name)
334 if (reg->get_name() == name)
337 const std::string& raw_name = reg->get_raw_name();
338 if (utils::starts_with(raw_name,
"$parent") && raw_name.substr(7) == name)
377 if (width > screen_dimensions.
x) {
399 if (height > screen_dimensions.
y) {
410 if (height > screen_dimensions.
y) {
423 if (!
layer.is_disabled) {
424 layer.is_disabled =
true;
431 if (!
layer.is_disabled) {
432 layer.is_disabled =
false;
492 layer.region_list.clear();
504 layer.region_list.begin(),
layer.region_list.end(),
505 [](
const auto& reg1,
const auto& reg2) {
506 return reg1->get_region_level() < reg2->get_region_level();
514 auto* raw_new_parent = parent.get();
518 if (raw_prev_parent) {
521 if (utils::starts_with(raw_name,
"$parent")) {
522 raw_name.erase(0, std::string(
"$parent").size());
524 lua[raw_prev_parent->get_name()][raw_name] = sol::lua_nil;
533 if (raw_new_parent) {
534 if (raw_new_parent->is_visible() &&
is_shown())
545 if (raw_new_parent) {
548 if (utils::starts_with(raw_name,
"$parent")) {
549 raw_name.erase(0, std::string(
"$parent").size());
551 lua[raw_new_parent->get_name()][raw_name] = lua[
get_name()];
579 if (!child->get_strata().has_value())
580 child->notify_strata_changed_(new_strata_id);
589 return !iter->second.empty();
598 utils::observer_ptr<layered_region> added_region = reg;
605 std::string raw_name = added_region->get_raw_name();
606 if (utils::starts_with(raw_name,
"$parent")) {
607 raw_name.erase(0, std::string(
"$parent").size());
609 lua[
get_name()][raw_name] = lua[added_region->get_name()];
627 <<
"Trying to remove \"" << reg->get_name() <<
"\" from \"" <<
name_
628 <<
"\"'s children, but it was not one of this frame's children." << std::endl;
633 auto removed_region = std::move(*iter);
636 removed_region->set_parent_(
nullptr);
640 std::string raw_name = removed_region->get_raw_name();
641 if (utils::starts_with(raw_name,
"$parent")) {
642 raw_name.erase(0, std::string(
"$parent").size());
644 lua[
get_name()][raw_name] = sol::lua_nil;
648 return removed_region;
651 utils::observer_ptr<layered_region>
661 reg->set_draw_layer(layer_id);
684 utils::observer_ptr<frame> added_child = child;
694 frame* raw_pointer = child.get();
699 <<
"Trying to remove \"" << child->get_name() <<
"\" from \"" <<
name_
700 <<
"\"'s children, but it was not one of this frame's children." << std::endl;
705 auto removed_child = std::move(*iter);
707 removed_child->set_parent_(
nullptr);
709 return removed_child;
744 return parent_->get_effective_strata();
753 if (obj->is_top_level())
756 obj = obj->get_parent();
794 return std::count_if(
803 return std::count_if(
828 return is_in_x_range && is_in_y_range;
831 utils::observer_ptr<const frame>
833 if (predicate(*
this))
880 std::string adjusted_name = script_name;
881 for (
auto iter = adjusted_name.begin(); iter != adjusted_name.end(); ++iter) {
882 if (
'A' <= *iter && *iter <=
'Z') {
883 *iter = std::tolower(*iter);
884 if (iter != adjusted_name.begin())
885 iter = adjusted_name.insert(iter,
'_');
889 return adjusted_name;
894 auto pos1 = original_message.find(
"[string \"" + file);
895 if (pos1 == std::string::npos)
896 return original_message;
898 auto pos2 = original_message.find_first_of(
'"', pos1 + 9);
899 if (pos2 == std::string::npos)
900 return original_message;
902 original_message.erase(pos1, pos2 - pos1 + 2);
903 original_message.insert(pos1, file);
905 auto pos3 = original_message.find_first_of(
':', pos1 + file.size());
906 if (pos3 == std::string::npos)
907 return original_message;
909 auto pos4 = original_message.find_first_of(
":>", pos3 + 1);
910 if (pos4 == std::string::npos)
911 return original_message;
914 utils::from_string<std::size_t>(original_message.substr(pos3 + 1, pos4 - pos3 - 1));
915 if (!offset.has_value())
916 return original_message;
918 original_message.erase(pos3 + 1, pos4 - pos3 - 1);
919 original_message.insert(pos3 + 1, utils::to_string(line_nbr + offset.value() - 1));
920 pos4 = original_message.find_first_of(
':', pos3 + 1);
922 auto pos5 = original_message.find(
"[string \"" + file, pos4);
923 if (pos5 == std::string::npos)
924 return original_message;
926 std::string message = original_message.substr(pos4 + 1);
927 original_message.erase(pos4 + 1);
930 return original_message;
934 std::string_view original_message,
const std::string& file, std::size_t line_nbr) {
935 std::string new_error;
936 for (
auto line : utils::cut(original_message,
"\n")) {
937 if (!new_error.empty())
949 <<
"\"" <<
get_name() <<
"\" cannot use script \"" << script_name <<
"\"."
958 const std::string& script_name,
959 const std::string& content,
966 std::string str =
"return function(self";
968 constexpr std::size_t max_args = 9;
969 for (std::size_t i = 0; i < max_args; ++i)
970 str +=
", arg" + utils::to_string(i + 1);
972 str +=
") " + content +
" end";
974 auto result = lua.do_string(str, info.
file_name);
976 if (!result.valid()) {
986 sol::protected_function handler = result;
989 return define_script_(script_name, std::move(handler), append, info);
993 const std::string& script_name,
994 sol::protected_function handler,
998 auto wrapped_handler = [handler = std::move(handler),
1000 sol::state& lua =
self.get_manager().get_lua();
1001 lua_State* lua_raw = lua.lua_state();
1003 std::vector<sol::object> lua_args;
1006 for (std::size_t i = 0; i < args.get_param_count(); ++i) {
1008 if (std::holds_alternative<utils::empty>(arg))
1009 lua_args.emplace_back(sol::lua_nil);
1011 lua_args.emplace_back(lua_raw, sol::in_place, arg);
1015 sol::object self_lua = lua[
self.get_name()];
1016 if (self_lua == sol::lua_nil)
1020 auto result = handler(self_lua, sol::as_args(lua_args));
1025 if (!result.valid()) {
1031 return define_script_(script_name, std::move(wrapped_handler), append, info);
1035 const std::string& script_name,
1045 [=](
frame&
self, sol::variadic_args v_args) {
1047 for (
auto&& arg : v_args) {
1049 if (!arg.is<sol::lua_nil_t>())
1052 data.
add(std::move(variant));
1055 self.fire_script(script_name, data);
1064 handler_list.disconnect_all();
1069 return handler_list.connect(std::move(handler));
1077 return iter_h->second.slots();
1088 iter_h->second.disconnect_all();
1098 data.
add(std::string(event_name));
1099 for (std::size_t i = 0; i <
event.get_param_count(); ++i)
1121 iter_h->second(*
this, data);
1122 }
catch (
const std::exception& e) {
1123 std::string err = e.what();
1205 std::swap(level_id,
level_);
1223 if (max_height < 0.0f)
1224 max_height = std::numeric_limits<float>::infinity();
1234 if (max_width < 0.0f)
1235 max_width = std::numeric_limits<float>::infinity();
1267 return parent_->remove_child(
self);
1294 if (old_level == top_level) {
1300 int diff =
level_ - old_level;
1307 child.add_level_(diff);
1352 child.add_level_(amount);
1386 const utils::observer_ptr<frame_renderer>& new_renderer) {
1393 if (
auto* raw_ptr = child.get(); raw_ptr && !raw_ptr->get_frame_renderer())
1394 child->notify_frame_renderer_changed_(new_renderer);
1418 return parent_->get_effective_frame_renderer();
1435 if (obj.is_shown()) {
1436 obj.notify_visible();
1443 if (child.is_shown()) {
1444 child.notify_visible();
1467 if (child.is_shown()) {
1468 child.notify_invisible();
1495 child.notify_scaling_factor_updated();
1498 obj.notify_scaling_factor_updated();
1521 const auto old_border_list =
borders_;
1580 auto iter_remove = std::remove_if(
1588 child.update(delta);
1595 auto iter_remove = std::remove_if(
1605 if (iter_list->second.empty()) {
1615 return get_type_list_impl_<frame>();
const addon * get_current_addon()
Returns the addon that is being parsed.
void set_current_addon(const addon *a)
Sets the current addon.
Utility class for safe checking of region validity.
bool is_alive() const
Check if the wrapped region is still alive.
Draws borders and background of a frame.
Stores a variable number of arguments for an event.
const utils::variant & get(std::size_t index) const
Returns a parameter of this event.
void add(T &&value)
Adds a parameter to this event.
Generates events and keep tracks of registered callbacks.
void fire_event(const std::string &event_name, event_data data=event_data{})
Emmit a new event.
void register_event(const std::string &event_name, event_handler_function callback)
Enables reaction to an event.
void unregister_event(const std::string &event_name)
Disables reaction to an event.
Exception to be thrown by GUI code.
utils::owner_ptr< layered_region > create_layered_region(registry ®, const region_core_attributes &attr)
Creates a new layered_region.
utils::owner_ptr< region > create_region(registry ®, const region_core_attributes &attr)
Creates a new region.
utils::owner_ptr< frame > create_frame(registry ®, const frame_core_attributes &attr)
Creates a new frame.
utils::owner_ptr< frame > remove_root_frame(const utils::observer_ptr< frame > &obj)
Remove a frame from the list of frames owned by this frame_container.
Abstract class for layering and rendering frames.
A region that can contain other regions and react to events.
bool check_script_(const std::string &script_name) const
bool is_auto_focus_enabled() const
Checks if automatic focus is enabled.
utils::observer_ptr< frame_renderer > effective_frame_renderer_
utils::observer_ptr< frame > add_child(utils::owner_ptr< frame > child)
Adds a frame to this frame's children.
void remove_script(const std::string &script_name)
Removes a script from this frame.
utils::view::adaptor< region_list, utils::view::smart_ptr_dereferencer, utils::view::non_null_filter > region_list_view
script_list_view get_script(const std::string &script_name) const
Return a view into this frame's handler scripts, registered for the given event.
void set_height(float abs_height) override
Changes this region's absolute height (in pixels).
void stop_moving()
ends moving this frame.
~frame() override
Destructor.
void notify_invisible() override
Notifies this region that it is no longer visible on screen.
bounds2f abs_hit_rect_inset_list_
utils::observer_ptr< const frame_renderer > compute_top_level_frame_renderer_() const
vector2f get_min_dimensions() const
Returns this frame's min dimensions.
bool is_mouse_wheel_enabled() const
Checks if this frame can receive mouse wheel input.
void add_level_(int amount)
std::string serialize(const std::string &tab) const override
Prints all relevant information about this region in a string.
utils::view::adaptor< const child_list, utils::view::smart_ptr_dereferencer, utils::view::non_null_filter > const_child_list_view
void render() const override
Renders this region on the current render target.
float get_scale() const
Returns this frame's scale.
bool is_movable() const
Checks if this frame can be moved.
utils::owner_ptr< region > release_from_parent() override
Removes this region from its parent and return an owning pointer.
void enable_auto_focus(bool enable)
Enables automatic focus when this frame is shown or raised.
std::optional< strata > strata_
void stop_sizing()
ends resizing this frame.
child_list_view get_children()
Returns the child list.
const std::vector< std::string > & get_type_list_() const override
bool is_resizable() const
Checks if this frame can be resized.
bool is_user_placed() const
Checks if this frame has been moved by the user.
static std::string get_adjusted_script_name(const std::string &script_name)
Returns the "adjusted" script name: "OnEvent" becomes "on_event".
void set_backdrop(std::unique_ptr< backdrop > bdrop)
Sets this frames' backdrop.
bool is_in_region(const vector2f &position) const override
Checks if the provided coordinates are inside this frame.
void copy_from(const region &obj) override
Copies a region's parameters into this frame (inheritance).
void set_resizable(bool is_resizable)
Sets if this frame can be resized by the user.
std::set< std::string > reg_drag_list_
void unregister_event(const std::string &event_name)
Tells the frame not to react to a certain event.
void disable_drag()
Tells this frame to not react to mouse drag from any mouse button.
std::array< layer_container, num_layers > layer_list_
strata compute_effective_strata_() const
vector2f get_max_dimensions() const
Returns this frame's max dimensions.
void set_clamped_to_screen(bool is_clamped_to_screen)
Sets if this frame is clamped to screen.
void set_max_width(float max_width)
Sets this frame's maximum width.
void set_level(int level_id)
Sets this frame's level.
void create_title_region()
Creates a new title region for this frame.
void set_max_height(float max_height)
Sets this frame's maximum height.
backdrop & get_or_create_backdrop()
Returns this frame's backdrop, creating it if needed.
void notify_layers_need_update()
Tells this frame to rebuild its layer list.
utils::observer_ptr< frame_renderer > frame_renderer_
event_receiver event_receiver_
void set_scale(float scale)
Sets this frame's scale.
void start_sizing(const point &p)
Starts resizing this frame with the mouse.
std::size_t get_layered_region_count() const
Returns the number of layered regions of this frame.
void enable_key_capture(const std::string &key_name)
Marks this frame as able to receive keyboard input from a specific key.
std::size_t get_layered_region_count_upper_bound() const
Returns the approximate number of regions of this frame.
void update(float delta) final
Updates this region's logic.
bool has_script(const std::string &script_name) const
Checks if this frame has a script defined.
void notify_visible() override
Notifies this region that it is now visible on screen.
void set_abs_hit_rect_insets(const bounds2f &insets)
Sets this frame's absolute hit rect insets.
utils::observer_ptr< const frame > get_child(const std::string &name) const
Returns one of this frame's children.
void set_min_height(float min_height)
Sets this frame's minimum height.
bool is_clamped_to_screen() const
Checks if this frame is clamped to screen.
bool is_drag_enabled(const std::string &button_name) const
Checks if this frame is registered for drag events with the provided mouse button.
void set_frame_renderer(utils::observer_ptr< frame_renderer > rdr)
Flags this object as rendered by another object.
bool is_key_capture_enabled(const std::string &key_name) const
Checks if this frame can receive keyboard input from a specific key.
void set_dimensions(const vector2f &dimensions) override
Changes this region's absolute dimensions (in pixels).
void disable_key_capture()
Marks this frame as unable to receive keyboard input from any key.
void set_top_level(bool is_top_level)
Sets if this frame is at top level.
void on_event_(std::string_view event_name, const event_data &event)
void register_event(const std::string &event_name)
Tells this frame to react to a certain event.
const backdrop * get_backdrop() const
Returns this frame's backdrop.
const bounds2f & get_abs_hit_rect_insets() const
Returns this frame's absolute hit rect insets.
std::set< std::string > reg_key_list_
virtual void fire_script(const std::string &script_name, const event_data &data=event_data{})
Calls a script.
void set_mouse_move_enabled(bool is_mouse_enabled)
Sets if this frame can receive mouse move input.
utils::connection add_script(const std::string &script_name, std::string content, script_info info=script_info{})
Adds an additional handler script to this frame (executed after existing scripts).
std::optional< strata > get_strata() const
Returns this frame's strata.
void set_width(float abs_width) override
Changes this region's absolute width (in pixels).
bool is_mouse_click_enabled_
const bounds2f & get_rel_hit_rect_insets() const
Returns this frame's relative hit rect insets.
void set_mouse_enabled(bool is_mouse_enabled)
Sets if this frame can receive mouse input (click & move).
std::unordered_map< std::string, script_signal > signal_list_
utils::observer_ptr< layered_region > create_layered_region(layer layer_id, region_core_attributes attr)
Creates a new region as child of this frame.
bool is_top_level() const
Checks if this frame is at top level.
virtual void update_(float delta)
utils::view::adaptor< const region_list, utils::view::smart_ptr_dereferencer, utils::view::non_null_filter > const_region_list_view
bounds2f rel_hit_rect_inset_list_
int get_level() const
Returns this frame's level.
void notify_renderer_need_redraw() override
Notifies the renderer of this region that it needs to be redrawn.
void set_min_width(float min_width)
Sets this frame's minimum width.
bool is_clamped_to_screen_
void set_keyboard_enabled(bool is_keyboard_enabled)
Sets if this frame can receive any keyboard input.
virtual bool can_use_script(const std::string &script_name) const
Returns 'true' if this frame can use a script.
utils::observer_ptr< const frame > get_top_level_parent() const
Returns this frame's top-level parent.
void set_min_dimensions(const vector2f &min)
Sets this frame's minimum size.
void set_parent_(utils::observer_ptr< frame > parent) override
Changes this region's parent.
bool is_mouse_move_enabled() const
Checks if this frame can receive mouse movement input.
bool is_mouse_click_enabled() const
Checks if this frame can receive mouse click input.
void notify_loaded() override
Notifies this region that it has been fully loaded.
bool is_mouse_move_enabled_
bool has_focus() const
Check if this frame currently has focus.
float get_effective_scale() const
Calculates effective scale.
void set_update_rate(float rate)
Sets a maximum update rate (in updates per seconds).
strata get_effective_strata() const
Returns this frame's effective strata.
utils::owner_ptr< layered_region > remove_region(const utils::observer_ptr< layered_region > ®)
Removes a layered_region from this frame's children.
void set_rel_hit_rect_insets(const bounds2f &insets)
Sets this frame's relative hit rect insets.
std::size_t get_child_count() const
Returns the number of children of this frame.
std::list< utils::owner_ptr< layered_region > > region_list
Type of the region list (internal).
bool is_mouse_wheel_enabled_
void update_borders_() override
bool is_keyboard_enabled() const
Checks if this frame can receive any keyboard input.
void set_user_placed(bool is_user_placed)
Sets if this frame has been moved by the user.
void set_strata(std::optional< strata > strata_id)
Sets this frame's strata.
void set_mouse_click_enabled(bool is_mouse_enabled)
Sets if this frame can receive mouse click input.
virtual void notify_focus(bool focus)
Notifies this frame that it has received or lost focus.
utils::owner_ptr< frame > remove_child(const utils::observer_ptr< frame > &child)
Removes a frame from this frame's children.
void set_focus(bool focus)
Asks for focus for this frame.
utils::observer_ptr< const frame_renderer > get_effective_frame_renderer() const final
Returns the renderer of this object or its parents, nullptr if none.
std::unique_ptr< backdrop > backdrop_
utils::observer_ptr< const layered_region > get_region(const std::string &name) const
Returns one of this frame's region.
utils::owner_ptr< region > title_region_
float get_update_rate() const
Gets the maximum update rate (in upates per seconds).
void set_mouse_wheel_enabled(bool is_mouse_wheel_enabled)
Sets if this frame can receive mouse wheel input.
void enable_draw_layer(layer layer_id)
Enables a layer.
void set_movable(bool is_movable)
Sets if this frame can be moved by the user.
virtual void notify_mouse_in_frame(bool mouse_in_frame, const vector2f &mouse_pos)
Tells this frame it is being hovered by the mouse.
utils::observer_ptr< frame > create_child(frame_core_attributes attr)
Creates a new frame as child of this frame.
bool is_keyboard_enabled_
region_list_view get_regions()
Returns the region list.
float time_since_last_update_
virtual utils::observer_ptr< const frame > find_topmost_frame(const std::function< bool(const frame &)> &predicate) const
Find the topmost frame matching the provided predicate.
void set_max_dimensions(const vector2f &max)
Sets this frame's maximum size.
std::size_t get_child_count_upper_bound() const
Returns the approximate number of children of this frame.
void notify_strata_changed_(strata new_strata_id)
utils::view::adaptor< child_list, utils::view::smart_ptr_dereferencer, utils::view::non_null_filter > child_list_view
utils::observer_ptr< layered_region > add_region(utils::owner_ptr< layered_region > reg)
Adds a layered_region to this frame's children.
void notify_scaling_factor_updated() override
Tells this region that the global interface scaling factor has changed.
void start_moving()
Starts moving this frame with the mouse.
utils::connection define_script_(const std::string &script_name, const std::string &content, bool append, const script_info &info)
void notify_frame_renderer_changed_(const utils::observer_ptr< frame_renderer > &new_renderer)
void disable_draw_layer(layer layer_id)
Disables a layer.
void enable_drag(const std::string &button_name)
Tells this frame to react to mouse drag.
void raise()
Increases this frame's level so it's the highest of the strata.
A region that can be rendered in a layer.
Manages the user interface.
const event_emitter & get_event_emitter() const
Returns the gui event emitter.
factory & get_factory()
Returns the UI object factory, which is used to create new objects.
addon_registry * get_addon_registry()
Returns the addon registry, which keeps track of loaded addons.
root & get_root()
Returns the UI root object, which contains root frames.
The base class of all elements in the GUI.
virtual void set_width(float abs_width)
Changes this region's absolute width (in pixels).
virtual void set_parent_(utils::observer_ptr< frame > parent)
Changes this region's parent.
const std::string & get_region_type() const
Returns the type of this region.
void initialize_(T &self, const region_core_attributes &attr)
Set up function to call in all derived class constructors.
bool is_virtual() const
Checks if this region is virtual.
registry & get_registry()
Returns the UI object registry, which keeps track of all objects in the UI.
bool is_visible() const
Checks if this region can be seen on the screen.
utils::observer_ptr< frame > parent_
manager & get_manager()
Returns this region's manager.
virtual void notify_loaded()
Notifies this region that it has been fully loaded.
virtual void notify_visible()
Notifies this region that it is now visible on screen.
virtual void render() const
Renders this region on the current render target.
virtual void set_height(float abs_height)
Changes this region's absolute height (in pixels).
const std::string & get_name() const
Returns this region's name.
bool is_shown() const
Checks if this region is shown.
virtual void notify_invisible()
Notifies this region that it is no longer visible on screen.
const std::string & get_raw_name() const
Returns this region's raw name.
virtual void set_dimensions(const vector2f &dimensions)
Changes this region's absolute dimensions (in pixels).
virtual void update(float delta)
Updates this region's logic.
utils::observer_ptr< const frame > get_parent() const
Returns this region's parent.
bool is_loaded() const
Checks if this region has been fully loaded.
virtual void notify_borders_need_update()
Tells this region that its borders need updating.
virtual void copy_from(const region &obj)
Copies a region's parameters into this region (inheritance).
const addon * get_addon() const
Returns this frame's addon.
virtual std::string serialize(const std::string &tab) const
Prints all relevant information about this region in a string.
virtual void notify_scaling_factor_updated()
Tells this region that the global interface scaling factor has changed.
virtual void update_borders_()
Root of the UI object hierarchy.
void start_moving(utils::observer_ptr< region > obj, anchor *a=nullptr, constraint constraint=constraint::none, std::function< void()> apply_constraint_func=nullptr)
Start manually moving a region with the mouse.
void stop_sizing()
Stops sizing for the current object.
void request_focus(utils::observer_ptr< frame > receiver)
Sets whether keyboard input should be focused.
void notify_hovered_frame_dirty()
Notifies the root that it should update the hovered frame.
void start_sizing(utils::observer_ptr< region > obj, point p)
Starts manually resizing a region with the mouse.
void stop_moving()
Stops movement for the current object.
void release_focus(const frame &receiver)
Give up focus of keyboard input.
Object representing the connection between a slot and a signal.
Allow iterating over a container without access to the container itself.
layer
ID of a layer for rendering inside a frame.
vector2< float > vector2f
Holds 2D coordinates (as floats)
script_signal::function_type script_function
C++ function type for UI script handlers.
utils::observer_ptr< ObjectType > observer_from(ObjectType *self)
Obtain an observer pointer from a raw pointer (typically 'this')
const std::string warning
std::string hijack_sol_error_line(std::string original_message, const std::string &file, std::size_t line_nbr)
std::string hijack_sol_error_message(std::string_view original_message, const std::string &file, std::size_t line_nbr)
std::variant< empty, bool, std::int64_t, std::int32_t, std::int16_t, std::int8_t, std::uint64_t, std::uint32_t, std::uint16_t, std::uint8_t, double, float, std::string > variant
Type-erased value for passing arguments to events.
auto find_if(C &v, T &&f)
oup::observable_sealed_ptr< T > owner_ptr
T height() const noexcept
Struct holding all the core information about a frame necessary for its creation.
Contains gui::layered_region.
Struct holding all the core information about a region necessary for its creation.
std::vector< utils::observer_ptr< const region > > inheritance
utils::observer_ptr< frame > parent
Holds file/line information for a script.