1 #include "lxgui/gui_anchor.hpp"
2 #include "lxgui/gui_color.hpp"
3 #include "lxgui/gui_layout_node.hpp"
4 #include "lxgui/gui_out.hpp"
5 #include "lxgui/gui_region.hpp"
6 #include "lxgui/utils_std.hpp"
12 const std::string& s = attr.value();
13 if (!s.empty() && s[0] ==
'#')
34 std::pair<anchor_type, vector2<std::optional<float>>>
39 if (abs_dim_node && rel_dim_node) {
41 <<
" node can only contain one of AbsDimension or RelDimension, but not both. "
42 "RelDimension ignored."
46 if (!abs_dim_node && !rel_dim_node) {
48 <<
" node must contain one of AbsDimension or RelDimension." << std::endl;
56 chosen_node = abs_dim_node;
59 chosen_node = rel_dim_node;
68 bool has_x = dimensions.second.x.has_value();
69 bool has_y = dimensions.second.y.has_value();
80 vector2f(dimensions.second.x.value(), dimensions.second.y.value()));
91 std::vector<point> found_points;
92 for (
const auto& anchor_node : anchors_node->get_children()) {
93 if (anchor_node.get_name() !=
"Anchor" && anchor_node.get_name() !=
"") {
95 <<
"unexpected node '" << anchor_node.get_name() <<
"'; ignored."
101 std::string parent = anchor_node.get_attribute_value_or<std::string>(
103 point relative_point = anchor_node.get_attribute_value_or<
point>(
"relativePoint", pt);
105 if (
utils::find(found_points, pt) != found_points.end()) {
107 <<
"anchor point \"" << utils::to_string(pt)
108 <<
"\" has already been defined for \"" <<
name_ <<
"\". anchor skipped."
117 a.
type = dimensions.first;
119 dimensions.second.x.value_or(0.0f), dimensions.second.y.value_or(0.0f));
Holds a single color (float RGBA, 128 bits)
std::string_view get_name() const noexcept
Returns this node's name.
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.
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...
virtual void set_width(float abs_width)
Changes this region's absolute width (in pixels).
void set_all_anchors(const utils::observer_ptr< region > &obj)
Adjusts this regions anchors to fit the provided region.
void set_anchor(const anchor_data &a)
Adds/replaces an anchor.
color parse_color_node_(const layout_node &node)
virtual void parse_layout(const layout_node &node)
Parses data from a layout_node.
bool is_virtual() const
Checks if this region is virtual.
virtual void parse_size_node_(const layout_node &node)
std::pair< anchor_type, vector2< std::optional< float > > > parse_dimension_node_(const layout_node &node)
utils::observer_ptr< frame > parent_
virtual void set_height(float abs_height)
Changes this region's absolute height (in pixels).
void set_relative_height(float rel_height)
Changes this region's height (relative to its parent).
virtual void parse_attributes_(const layout_node &node)
vector2< std::optional< float > > parse_offset_node_(const layout_node &node)
virtual void set_dimensions(const vector2f &dimensions)
Changes this region's absolute dimensions (in pixels).
void set_relative_width(float rel_width)
Changes this region's width (relative to its parent).
void set_relative_dimensions(const vector2f &dimensions)
Changes this region's dimensions (relative to its parent).
vector2< float > parse_offset_node_or_(const layout_node &node, float fallback)
virtual void parse_anchor_node_(const layout_node &node)
vector2< float > vector2f
Holds 2D coordinates (as floats)
const std::string warning
auto find(C &v, const T &s)
Raw data of an anchor (value type)