lxgui
gui_edit_box_parser.cpp
1 #include "lxgui/gui_edit_box.hpp"
2 #include "lxgui/gui_font_string.hpp"
3 #include "lxgui/gui_layout_node.hpp"
4 #include "lxgui/gui_out.hpp"
5 #include "lxgui/gui_parser_common.hpp"
6 
7 namespace lxgui::gui {
10 
11  if (const auto attr = node.try_get_attribute_value<std::size_t>("letters"))
12  set_max_letters(attr.value());
13 
14  if (const auto attr = node.try_get_attribute_value<float>("blinkTime"))
15  set_blink_time(attr.value());
16 
17  if (const auto attr = node.try_get_attribute_value<bool>("numeric"))
18  set_numeric_only(attr.value());
19 
20  if (const auto attr = node.try_get_attribute_value<bool>("positive"))
21  set_positive_only(attr.value());
22 
23  if (const auto attr = node.try_get_attribute_value<bool>("integer"))
24  set_integer_only(attr.value());
25 
26  if (const auto attr = node.try_get_attribute_value<bool>("password"))
27  set_password_mode_enabled(attr.value());
28 
29  if (const auto attr = node.try_get_attribute_value<bool>("multiLine"))
30  set_multi_line(attr.value());
31 
32  if (const auto attr = node.try_get_attribute_value<std::size_t>("historyLines"))
33  set_max_history_lines(attr.value());
34 
35  if (const auto attr = node.try_get_attribute_value<bool>("ignoreArrows"))
36  set_arrows_ignored(attr.value());
37 }
38 
41 
44 
45  if (const layout_node* highlight_node = node.try_get_child("HighlightColor"))
46  set_highlight_color(parse_color_node_(*highlight_node));
47 }
48 
50  if (const layout_node* font_string_node = node.try_get_child("FontString")) {
51  layout_node defaulted = *font_string_node;
52  defaulted.get_or_set_attribute_value("name", "$parentFontString");
53 
54  auto fstr = parse_region_(defaulted, "ARTWORK", "FontString");
55  if (fstr) {
56  fstr->set_manually_inherited(true);
57  set_font_string(utils::static_pointer_cast<font_string>(fstr));
58  }
59 
60  if (const layout_node* error_node = defaulted.try_get_child("Anchors")) {
61  gui::out << gui::warning << error_node->get_location() << ": "
62  << "edit_box: font_string's anchors will be ignored." << std::endl;
63  }
64 
65  if (const layout_node* error_node = defaulted.try_get_child("Size")) {
66  gui::out << gui::warning << error_node->get_location() << ": "
67  << "edit_box: font_string's Size will be ignored." << std::endl;
68  }
69 
70  warn_for_not_accessed_node(defaulted);
71  font_string_node->bypass_access_check();
72  }
73 }
74 
76  if (const layout_node* text_insets_node = node.try_get_child("TextInsets")) {
78  text_insets_node->get_attribute_value_or<float>("left", 0.0f),
79  text_insets_node->get_attribute_value_or<float>("right", 0.0f),
80  text_insets_node->get_attribute_value_or<float>("top", 0.0f),
81  text_insets_node->get_attribute_value_or<float>("bottom", 0.0f)));
82  }
83 }
84 } // namespace lxgui::gui
void set_integer_only(bool integer_only)
Makes this edit_box allow integer numbers only.
void set_max_letters(std::size_t max_letters)
Sets the maximum number of letters to allow in this edit_box.
void set_text_insets(const bounds2f &insets)
Sets the insets used to render the content text.
void set_font_string(utils::observer_ptr< font_string > fstr)
Sets the font_string to use to render the content.
void parse_attributes_(const layout_node &node) override
void set_highlight_color(const color &c)
Sets the color of the highlight quad.
void parse_font_string_node_(const layout_node &node)
void set_positive_only(bool positive_only)
Makes this edit_box allow positive numbers only.
void parse_text_insets_node_(const layout_node &node)
void set_password_mode_enabled(bool enable)
Enables or disables password mode.
void set_numeric_only(bool numeric_only)
Makes this edit_box allow numeric characters only.
void set_arrows_ignored(bool arrows_ignored)
Sets whether keyboard arrows move the carret or not.
void set_blink_time(double blink_time)
Sets the carret's blink time.
void set_multi_line(bool multi_line)
Allows this edit_box to have several lines in it.
void set_max_history_lines(std::size_t max_history_lines)
Sets the maximum number of history lines this edit_box can keep.
void parse_all_nodes_before_children_(const layout_node &node) override
virtual void parse_all_nodes_before_children_(const layout_node &node)
void parse_attributes_(const layout_node &node) override
utils::observer_ptr< layered_region > parse_region_(const layout_node &node, const std::string &layer_name, const std::string &type)
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.
std::string_view get_or_set_attribute_value(std::string_view name, std::string_view value)
Returns the value of the attribute with the provided name, or set it 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.
color parse_color_node_(const layout_node &node)
bounds2< float > bounds2f
Holds 2D bounds of a region (as floats).
std::ostream out
const std::string warning
Definition: gui_out.cpp:6
void warn_for_not_accessed_node(const layout_node &node)
Emit a warning if this node (or any of its attributes/children) was not read.