1 #include "lxgui/gui_backdrop.hpp"
2 #include "lxgui/gui_frame.hpp"
3 #include "lxgui/gui_layered_region.hpp"
4 #include "lxgui/gui_layout_node.hpp"
5 #include "lxgui/gui_manager.hpp"
6 #include "lxgui/gui_out.hpp"
7 #include "lxgui/gui_parser_common.hpp"
8 #include "lxgui/gui_root.hpp"
9 #include "lxgui/gui_virtual_root.hpp"
10 #include "lxgui/utils_string.hpp"
53 std::string level = utils::to_lower(std::string(attr->get_value()));
54 if (level !=
"parent") {
55 if (
const auto val = attr->try_get_value<
int>())
60 <<
"\"level\" is not allowed for virtual regions. Ignored." << std::endl;
86 bool has_x = dimensions.second.x.has_value();
87 bool has_y = dimensions.second.y.has_value();
91 vector2f(dimensions.second.x.value(), dimensions.second.y.value()));
98 <<
"\"RelDimension\" for ResizeBounds:Min is not yet supported. Skipped."
105 bool has_x = dimensions.second.x.has_value();
106 bool has_y = dimensions.second.y.has_value();
108 if (has_x && has_y) {
110 vector2f(dimensions.second.x.value(), dimensions.second.y.value()));
117 <<
"\"RelDimension\" for ResizeBounds:Max is not yet supported. Skipped."
135 std::unique_ptr<backdrop> bdrop(
new backdrop(*
this));
137 bdrop->set_background(
138 parse_file_name(backdrop_node->get_attribute_value_or<std::string>(
"bgFile",
"")));
141 parse_file_name(backdrop_node->get_attribute_value_or<std::string>(
"edgeFile",
"")));
143 bdrop->set_background_tilling(backdrop_node->get_attribute_value_or<
bool>(
"tile",
false));
149 if (abs_inset_node && rel_inset_node) {
151 <<
": BackgroundInsets node can only contain one of AbsInset or "
152 "RelInset, but not both. RelInset ignored."
156 if (!abs_inset_node && !rel_inset_node) {
158 <<
": BackgroundInsets node must contain one of AbsInset or RelInset."
163 if (abs_inset_node) {
164 bdrop->set_background_insets(
bounds2f(
171 <<
"RelInset for Backdrop:BackgroundInsets is not yet supported (" <<
name_
172 <<
")." << std::endl;
180 if (abs_inset_node && rel_inset_node) {
182 <<
": EdgeInsets node can only contain one of AbsInset or RelInset, but "
183 "not both. RelInset ignored."
187 if (!abs_inset_node && !rel_inset_node) {
189 <<
": EdgeInsets node must contain one of AbsInset or RelInset."
194 if (abs_inset_node) {
202 <<
"RelInset for Backdrop:EdgeInsets is not yet supported (" <<
name_
203 <<
")." << std::endl;
217 if (abs_value_node && rel_value_node) {
219 <<
": EdgeSize node can only contain one of AbsValue or RelValue, but "
220 "not both. RelValue ignored."
224 if (!abs_value_node && !rel_value_node) {
226 <<
": EdgeSize node must contain one of AbsValue or RelValue."
231 if (abs_value_node) {
235 <<
"RelValue for Backdrop:EdgeSize is not yet supported (" <<
name_ <<
")."
244 if (abs_value_node && rel_value_node) {
246 <<
": TileSize node can only contain one of AbsValue or RelValue, but "
247 "not both. RelValue ignored."
251 if (!abs_value_node && !rel_value_node) {
253 <<
": TileSize node must contain one of AbsValue or RelValue."
258 if (abs_value_node) {
262 <<
"RelValue for Backdrop:TileSize is not yet supported (" <<
name_ <<
")."
276 if (abs_inset_node && rel_inset_node) {
278 <<
": HitRectInsets node can only contain one of AbsInset or RelInset, but "
279 "not both. RelInset ignored."
283 if (!abs_inset_node && !rel_inset_node) {
285 <<
": HitRectInsets node must contain one of AbsInset or RelInset."
290 if (abs_inset_node) {
307 const layout_node& node,
const std::string& layer_name,
const std::string& type) {
314 attr.object_type = type;
316 auto layer_id = utils::from_string<layer>(layer_name);
317 if (!layer_id.has_value()) {
319 <<
"Unknown layer type: \"" << layer_name <<
"\". Using \"ARTWORK\"."
328 reg->parse_layout(node);
329 reg->notify_loaded();
332 reg->release_from_parent();
345 if (layer_node.get_name() !=
"Layer" && layer_node.get_name() !=
"") {
347 <<
"unexpected node '" << layer_node.get_name() <<
"'; ignored."
352 std::string level = layer_node.get_attribute_value_or<std::string>(
"level",
"ARTWORK");
367 attr.object_type = type;
375 obj->parse_layout(node);
376 obj->notify_loaded();
379 obj->release_from_parent();
400 std::string name = std::string(script_node.get_name());
403 if (
const layout_attribute* run_node = script_node.try_get_attribute(
"run"))
404 actual_script_node = run_node;
406 std::string script = std::string(actual_script_node->
get_value());
411 if (script_node.get_attribute_value_or<
bool>(
"override",
false))
412 set_script(name, std::move(script), std::move(info));
414 add_script(name, std::move(script), std::move(info));
Draws borders and background of a frame.
Exception to be thrown by GUI code.
virtual void parse_all_nodes_before_children_(const layout_node &node)
virtual void parse_hit_rect_insets_node_(const layout_node &node)
virtual void parse_scripts_node_(const layout_node &node)
void enable_auto_focus(bool enable)
Enables automatic focus when this frame is shown or raised.
void set_backdrop(std::unique_ptr< backdrop > bdrop)
Sets this frames' backdrop.
virtual void parse_layers_node_(const layout_node &node)
void set_resizable(bool is_resizable)
Sets if this frame can be resized by the user.
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.
virtual void parse_title_region_node_(const layout_node &node)
void set_abs_hit_rect_insets(const bounds2f &insets)
Sets this frame's absolute hit rect insets.
void set_min_height(float min_height)
Sets this frame's minimum height.
void parse_attributes_(const layout_node &node) override
void set_top_level(bool is_top_level)
Sets if this frame is at top level.
void set_mouse_move_enabled(bool is_mouse_enabled)
Sets if this frame can receive mouse move input.
utils::observer_ptr< layered_region > parse_region_(const layout_node &node, const std::string &layer_name, const std::string &type)
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).
void set_mouse_enabled(bool is_mouse_enabled)
Sets if this frame can receive mouse input (click & move).
utils::observer_ptr< layered_region > create_layered_region(layer layer_id, region_core_attributes attr)
Creates a new region as child of this frame.
void set_min_width(float min_width)
Sets this frame's minimum width.
void set_keyboard_enabled(bool is_keyboard_enabled)
Sets if this frame can receive any keyboard input.
void set_min_dimensions(const vector2f &min)
Sets this frame's minimum size.
virtual void parse_resize_bounds_node_(const layout_node &node)
utils::connection set_script(const std::string &script_name, std::string content, script_info info=script_info{})
Sets a new handler script for this frame (replacing existing scripts).
void set_update_rate(float rate)
Sets a maximum update rate (in updates per seconds).
void parse_layout(const layout_node &node) final
Parses data from a layout_node.
virtual void parse_backdrop_node_(const layout_node &node)
void set_rel_hit_rect_insets(const bounds2f &insets)
Sets this frame's relative hit rect insets.
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.
utils::observer_ptr< frame > parse_child_(const layout_node &node, const std::string &type)
utils::owner_ptr< region > title_region_
void set_mouse_wheel_enabled(bool is_mouse_wheel_enabled)
Sets if this frame can receive mouse wheel input.
void set_movable(bool is_movable)
Sets if this frame can be moved by the user.
utils::observer_ptr< frame > create_child(frame_core_attributes attr)
Creates a new frame as child of this frame.
virtual void parse_frames_node_(const layout_node &node)
void set_max_dimensions(const vector2f &max)
Sets this frame's maximum size.
An attribute in a layout file.
std::size_t get_value_line_number() const noexcept
Returns the line number on which this node's value is located.
std::string_view get_value() const noexcept
Returns this node's value as string.
std::string_view get_filename() const noexcept
Returns the file in which this node is located.
std::string_view get_location() const noexcept
Returns this node's location in the file as {file}:{line}.
An node in a layout file.
std::optional< std::string_view > try_get_attribute_value(std::string_view name) const noexcept
Returns the value of the attribute with the provided name, nullopt if not found.
children_view get_children() const noexcept
Returns a view to the list of children.
const layout_attribute * try_get_attribute(std::string_view name) const noexcept
Returns the attribute with the provided name, or null if none.
const layout_node * try_get_child(std::string_view name) const noexcept
Returns the first child with a given name, or null if none.
T get_attribute_value_or(std::string_view name, T fallback) const noexcept
Returns the value of the attribute with the provided name, or a default if not found or parsing faile...
void set_shown(bool is_shown)
shows/hides this region.
void set_all_anchors(const utils::observer_ptr< region > &obj)
Adjusts this regions anchors to fit the provided region.
color parse_color_node_(const layout_node &node)
registry & get_registry()
Returns the UI object registry, which keeps track of all objects in the UI.
virtual void parse_size_node_(const layout_node &node)
std::pair< anchor_type, vector2< std::optional< float > > > parse_dimension_node_(const layout_node &node)
manager & get_manager()
Returns this region's manager.
void set_alpha(float alpha)
Changes this region's alpha (opacity).
const addon * get_addon() const
Returns this frame's addon.
virtual void parse_anchor_node_(const layout_node &node)
std::string parse_file_name(const std::string &file_name) const
Convert an addon-relative file path to a application-relative path.
const std::string & get_description() const
Returns the message of the exception.
vector2< float > vector2f
Holds 2D coordinates (as floats)
bounds2< float > bounds2f
Holds 2D bounds of a region (as floats).
utils::observer_ptr< ObjectType > observer_from(ObjectType *self)
Obtain an observer pointer from a raw pointer (typically 'this')
region_core_attributes parse_core_attributes(registry ®, virtual_registry &vreg, const layout_node &node, utils::observer_ptr< frame > parent)
Parse "core" attributes from a layout node, before creating a frame.
const std::string warning
Struct holding all the core information about a frame necessary for its creation.
Holds file/line information for a script.