lxgui
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
gui_frame.hpp
1 #ifndef LXGUI_GUI_FRAME_HPP
2 #define LXGUI_GUI_FRAME_HPP
3 
4 #include "lxgui/gui_backdrop.hpp"
5 #include "lxgui/gui_event_receiver.hpp"
6 #include "lxgui/gui_frame_core_attributes.hpp"
7 #include "lxgui/gui_layered_region.hpp"
8 #include "lxgui/gui_region.hpp"
9 #include "lxgui/gui_strata.hpp"
10 #include "lxgui/input_keys.hpp"
11 #include "lxgui/lxgui.hpp"
12 #include "lxgui/utils.hpp"
13 #include "lxgui/utils_meta.hpp"
14 #include "lxgui/utils_signal.hpp"
15 #include "lxgui/utils_view.hpp"
16 
17 #include <functional>
18 #include <limits>
19 #include <list>
20 #include <lxgui/extern_sol2_protected_function.hpp>
21 #include <magic_enum.hpp>
22 #include <optional>
23 #include <set>
24 #include <unordered_map>
25 #include <vector>
26 
27 namespace lxgui::gui {
28 
29 class frame_renderer;
30 class frame;
31 
34  bool is_disabled = false;
35  std::vector<utils::observer_ptr<layered_region>> region_list;
36 };
37 
39 struct script_info {
40  std::string file_name;
41  std::size_t line_nbr = 0;
42 };
43 
45 using script_signature = void(frame&, const event_data&);
46 
49 
52 
55 
255 class frame : public region {
256 public:
257  using base = region;
258 
268  using child_list = std::list<utils::owner_ptr<frame>>;
269  using child_list_view = utils::view::
270  adaptor<child_list, utils::view::smart_ptr_dereferencer, utils::view::non_null_filter>;
272  const child_list,
275 
285  using region_list = std::list<utils::owner_ptr<layered_region>>;
286  using region_list_view = utils::view::
287  adaptor<region_list, utils::view::smart_ptr_dereferencer, utils::view::non_null_filter>;
289  const region_list,
292 
294  explicit frame(utils::control_block& block, manager& mgr, const frame_core_attributes& attr);
295 
297  ~frame() override;
298 
300  void render() const override;
301 
309  void update(float delta) final;
310 
316  std::string serialize(const std::string& tab) const override;
317 
323  virtual bool can_use_script(const std::string& script_name) const;
324 
329  void copy_from(const region& obj) override;
330 
335  void create_title_region();
336 
342  void set_draw_layer_enabled(layer layer_id, bool enable) {
343  if (enable) {
344  enable_draw_layer(layer_id);
345  } else {
346  disable_draw_layer(layer_id);
347  }
348  }
349 
354  void disable_draw_layer(layer layer_id);
355 
360  void enable_draw_layer(layer layer_id);
361 
366  void set_mouse_enabled(bool is_mouse_enabled);
367 
372  void enable_mouse() {
373  set_mouse_enabled(true);
374  }
375 
380  void disable_mouse() {
381  set_mouse_enabled(false);
382  }
383 
388  void set_mouse_click_enabled(bool is_mouse_enabled);
389 
396  }
397 
404  }
405 
410  void set_mouse_move_enabled(bool is_mouse_enabled);
411 
418  }
419 
425  set_mouse_move_enabled(false);
426  }
427 
433 
440  }
441 
448  }
449 
462 
468  set_keyboard_enabled(true);
469  }
470 
476  set_keyboard_enabled(false);
477  }
478 
486  void set_key_capture_enabled(const std::string& key_name, bool enable) {
487  if (enable) {
488  enable_key_capture(key_name);
489  } else {
490  disable_key_capture(key_name);
491  }
492  }
493 
501  void set_key_capture_enabled(input::key key_id, bool enable) {
502  if (enable) {
503  enable_key_capture(key_id);
504  } else {
505  disable_key_capture(key_id);
506  }
507  }
508 
522  void enable_key_capture(const std::string& key_name);
523 
535  void enable_key_capture(input::key key_id);
536 
545  void disable_key_capture(const std::string& key_name);
546 
558  void disable_key_capture(input::key key_id);
559 
567  void disable_key_capture();
568 
574  bool has_script(const std::string& script_name) const;
575 
580  utils::observer_ptr<layered_region> add_region(utils::owner_ptr<layered_region> reg);
581 
586  template<
587  typename RegionType,
588  typename Enable =
589  typename std::enable_if<std::is_base_of<gui::layered_region, RegionType>::value>::type>
590  utils::observer_ptr<RegionType> add_region(utils::owner_ptr<RegionType> reg) {
591  return utils::static_pointer_cast<RegionType>(
592  add_region(utils::static_pointer_cast<layered_region>(std::move(reg))));
593  }
594 
600  utils::owner_ptr<layered_region> remove_region(const utils::observer_ptr<layered_region>& reg);
601 
612  utils::observer_ptr<layered_region>
614 
625  template<
626  typename RegionType,
627  typename Enable =
628  typename std::enable_if<std::is_base_of<gui::layered_region, RegionType>::value>::type>
629  utils::observer_ptr<RegionType>
631  attr.object_type = RegionType::class_name;
632 
633  return utils::static_pointer_cast<RegionType>(
634  create_layered_region(layer_id, std::move(attr)));
635  }
636 
647  template<
648  typename RegionType,
649  typename Enable =
650  typename std::enable_if<std::is_base_of<gui::layered_region, RegionType>::value>::type>
651  utils::observer_ptr<RegionType> create_layered_region(layer layer_id, const std::string& name) {
653  attr.name = name;
654  attr.object_type = RegionType::class_name;
655 
656  return utils::static_pointer_cast<RegionType>(
657  create_layered_region(layer_id, std::move(attr)));
658  }
659 
671  utils::observer_ptr<frame> create_child(frame_core_attributes attr);
672 
684  template<
685  typename FrameType,
686  typename Enable =
687  typename std::enable_if<std::is_base_of<gui::frame, FrameType>::value>::type>
688  utils::observer_ptr<FrameType> create_child(frame_core_attributes attr) {
689  attr.object_type = FrameType::class_name;
690 
691  return utils::static_pointer_cast<FrameType>(create_child(std::move(attr)));
692  }
693 
705  template<
706  typename FrameType,
707  typename Enable =
708  typename std::enable_if<std::is_base_of<gui::frame, FrameType>::value>::type>
709  utils::observer_ptr<FrameType> create_child(const std::string& name) {
711  attr.name = name;
712  attr.object_type = FrameType::class_name;
713 
714  return utils::static_pointer_cast<FrameType>(create_child(std::move(attr)));
715  }
716 
721  utils::observer_ptr<frame> add_child(utils::owner_ptr<frame> child);
722 
727  template<
728  typename FrameType,
729  typename Enable =
730  typename std::enable_if<std::is_base_of<gui::frame, FrameType>::value>::type>
731  utils::observer_ptr<FrameType> add_child(utils::owner_ptr<FrameType> child) {
732  return utils::static_pointer_cast<FrameType>(
733  add_child(utils::static_pointer_cast<frame>(std::move(child))));
734  }
735 
741  utils::owner_ptr<frame> remove_child(const utils::observer_ptr<frame>& child);
742 
748 
754 
764  utils::observer_ptr<const frame> get_child(const std::string& name) const;
765 
775  utils::observer_ptr<frame> get_child(const std::string& name) {
776  return utils::const_pointer_cast<frame>(const_cast<const frame*>(this)->get_child(name));
777  }
778 
788  template<
789  typename FrameType,
790  typename Enable =
791  typename std::enable_if<std::is_base_of<gui::frame, FrameType>::value>::type>
792  utils::observer_ptr<const FrameType> get_child(const std::string& name) const {
793  return down_cast<FrameType>(get_child(name));
794  }
795 
805  template<
806  typename FrameType,
807  typename Enable =
808  typename std::enable_if<std::is_base_of<gui::frame, FrameType>::value>::type>
809  utils::observer_ptr<FrameType> get_child(const std::string& name) {
810  return down_cast<FrameType>(get_child(name));
811  }
812 
818 
824 
834  utils::observer_ptr<const layered_region> get_region(const std::string& name) const;
835 
845  utils::observer_ptr<layered_region> get_region(const std::string& name) {
846  return utils::const_pointer_cast<layered_region>(
847  const_cast<const frame*>(this)->get_region(name));
848  }
849 
859  template<
860  typename RegionType,
861  typename Enable =
862  typename std::enable_if<std::is_base_of<gui::layered_region, RegionType>::value>::type>
863  utils::observer_ptr<RegionType> get_region(const std::string& name) {
864  return down_cast<RegionType>(get_region(name));
865  }
866 
871  float get_effective_scale() const;
872 
877  int get_level() const;
878 
884  std::optional<strata> get_strata() const;
885 
891 
896  utils::observer_ptr<const frame> get_top_level_parent() const;
897 
902  utils::observer_ptr<frame> get_top_level_parent() {
903  return utils::const_pointer_cast<frame>(
904  const_cast<const frame*>(this)->get_top_level_parent());
905  }
906 
911  const backdrop* get_backdrop() const;
912 
918 
924 
929  const bounds2f& get_abs_hit_rect_insets() const;
930 
935  const bounds2f& get_rel_hit_rect_insets() const;
936 
942 
948 
955  std::size_t get_child_count() const;
956 
964  std::size_t get_child_count_upper_bound() const;
965 
972  std::size_t get_layered_region_count() const;
973 
981  std::size_t get_layered_region_count_upper_bound() const;
982 
989  float get_scale() const;
990 
992  utils::observer_ptr<const region> get_title_region() const {
993  return title_region_;
994  }
995 
997  utils::observer_ptr<region> get_title_region() {
998  return title_region_;
999  }
1000 
1005  bool is_clamped_to_screen() const;
1006 
1012  bool is_in_region(const vector2f& position) const override;
1013 
1022  virtual utils::observer_ptr<const frame>
1023  find_topmost_frame(const std::function<bool(const frame&)>& predicate) const;
1024 
1033  utils::observer_ptr<frame>
1034  find_topmost_frame(const std::function<bool(const frame&)>& predicate) {
1035  return utils::const_pointer_cast<frame>(
1036  const_cast<const frame*>(this)->find_topmost_frame(predicate));
1037  }
1038 
1043  bool is_mouse_move_enabled() const;
1044 
1049  bool is_mouse_click_enabled() const;
1050 
1055  bool is_mouse_wheel_enabled() const;
1056 
1062  bool is_drag_enabled(const std::string& button_name) const;
1063 
1072  bool is_key_capture_enabled(const std::string& key_name) const;
1073 
1081  bool is_keyboard_enabled() const;
1082 
1087  bool is_movable() const;
1088 
1093  bool is_resizable() const;
1094 
1099  bool is_top_level() const;
1100 
1105  bool is_user_placed() const;
1106 
1112  static std::string get_adjusted_script_name(const std::string& script_name);
1113 
1126  const std::string& script_name, std::string content, script_info info = script_info{}) {
1127  if (!check_script_(script_name))
1128  return {};
1129  return define_script_(script_name, content, true, info);
1130  }
1131 
1145  const std::string& script_name,
1146  sol::protected_function handler,
1147  script_info info = script_info{}) {
1148  if (!check_script_(script_name))
1149  return {};
1150  return define_script_(script_name, std::move(handler), true, info);
1151  }
1152 
1166  const std::string& script_name, script_function handler, script_info info = script_info{}) {
1167  if (!check_script_(script_name))
1168  return {};
1169  return define_script_(script_name, std::move(handler), true, info);
1170  }
1171 
1196  template<typename DerivedType = void, typename Function>
1198  const std::string& script_name, Function&& handler, script_info info = script_info{}) {
1199 
1200  return add_script(
1201  script_name,
1203  [handler = std::move(handler)](frame& self, const event_data& data) mutable {
1204  constexpr bool use_automatic_cast = std::is_same_v<DerivedType, void>;
1205 
1206  using derived_type = std::decay_t<std::conditional_t<
1207  use_automatic_cast, utils::first_function_argument<Function>, DerivedType>>;
1208 
1209  constexpr bool use_no_cast = std::is_same_v<derived_type, frame>;
1210 
1211  if constexpr (use_no_cast) {
1212  handler(self, data);
1213  } else if constexpr (use_automatic_cast) {
1214  handler(down_cast<derived_type>(self), data);
1215  } else {
1216  handler(static_cast<derived_type&>(self), data);
1217  }
1218  }),
1219  info);
1220  }
1221 
1234  const std::string& script_name, std::string content, script_info info = script_info{}) {
1235  if (!check_script_(script_name))
1236  return {};
1237  return define_script_(script_name, content, false, info);
1238  }
1239 
1253  const std::string& script_name,
1254  sol::protected_function handler,
1255  script_info info = script_info{}) {
1256  if (!check_script_(script_name))
1257  return {};
1258  return define_script_(script_name, std::move(handler), false, info);
1259  }
1260 
1274  const std::string& script_name, script_function handler, script_info info = script_info{}) {
1275  if (!check_script_(script_name))
1276  return {};
1277  return define_script_(script_name, std::move(handler), false, info);
1278  }
1279 
1304  template<typename DerivedType = void, typename Function>
1306  const std::string& script_name, Function&& handler, script_info info = script_info{}) {
1307 
1308  return set_script(
1309  script_name,
1311  [handler = std::move(handler)](frame& self, const event_data& data) mutable {
1312  constexpr bool use_automatic_cast = std::is_same_v<DerivedType, void>;
1313 
1314  using derived_type = std::decay_t<std::conditional_t<
1315  use_automatic_cast, utils::first_function_argument<Function>, DerivedType>>;
1316 
1317  constexpr bool use_no_cast = std::is_same_v<derived_type, frame>;
1318 
1319  if constexpr (use_no_cast) {
1320  handler(self, data);
1321  } else if constexpr (use_automatic_cast) {
1322  handler(down_cast<derived_type>(self), data);
1323  } else {
1324  handler(static_cast<derived_type&>(self), data);
1325  }
1326  }),
1327  info);
1328  }
1329 
1335  script_list_view get_script(const std::string& script_name) const;
1336 
1343  void remove_script(const std::string& script_name);
1344 
1353  virtual void fire_script(const std::string& script_name, const event_data& data = event_data{});
1354 
1366  void set_update_rate(float rate);
1367 
1372  float get_update_rate() const;
1373 
1378  void register_event(const std::string& event_name);
1379 
1384  void unregister_event(const std::string& event_name);
1385 
1391  void set_drag_enabled(const std::string& button_name, bool enable) {
1392  if (enable) {
1393  enable_drag(button_name);
1394  } else {
1395  disable_drag(button_name);
1396  }
1397  }
1398 
1404  void set_drag_enabled(input::mouse_button button_id, bool enable) {
1405  if (enable) {
1406  enable_drag(button_id);
1407  } else {
1408  disable_drag(button_id);
1409  }
1410  }
1411 
1416  void enable_drag(const std::string& button_name);
1417 
1422  void enable_drag(input::mouse_button button_id);
1423 
1428  void disable_drag(const std::string& button_name);
1429 
1434  void disable_drag(input::mouse_button button_id);
1435 
1439  void disable_drag();
1440 
1447 
1452  void set_strata(std::optional<strata> strata_id);
1453 
1458  void set_backdrop(std::unique_ptr<backdrop> bdrop);
1459 
1465  void set_abs_hit_rect_insets(const bounds2f& insets);
1466 
1472  void set_rel_hit_rect_insets(const bounds2f& insets);
1473 
1478  void set_level(int level_id);
1479 
1484  void set_max_dimensions(const vector2f& max);
1485 
1490  void set_min_dimensions(const vector2f& min);
1491 
1496  void set_max_height(float max_height);
1497 
1502  void set_max_width(float max_width);
1503 
1508  void set_min_height(float min_height);
1509 
1514  void set_min_width(float min_width);
1515 
1520  void set_movable(bool is_movable);
1521 
1527 
1532  void set_resizable(bool is_resizable);
1533 
1538  void set_scale(float scale);
1539 
1548  void set_top_level(bool is_top_level);
1549 
1555  void raise();
1556 
1561  void set_user_placed(bool is_user_placed);
1562 
1564  void start_moving();
1565 
1567  void stop_moving();
1568 
1573  void start_sizing(const point& p);
1574 
1576  void stop_sizing();
1577 
1582  void enable_auto_focus(bool enable);
1583 
1588  bool is_auto_focus_enabled() const;
1589 
1597  void set_focus(bool focus);
1598 
1603  bool has_focus() const;
1604 
1613  void set_frame_renderer(utils::observer_ptr<frame_renderer> rdr);
1614 
1620  utils::observer_ptr<const frame_renderer> get_frame_renderer() const {
1621  return frame_renderer_;
1622  }
1623 
1629  const utils::observer_ptr<frame_renderer>& get_frame_renderer() {
1630  return frame_renderer_;
1631  }
1632 
1638  utils::observer_ptr<const frame_renderer> get_effective_frame_renderer() const final;
1639 
1646  return utils::const_pointer_cast<frame_renderer>(
1647  const_cast<const frame*>(this)->get_effective_frame_renderer());
1648  }
1649 
1654  void notify_renderer_need_redraw() override;
1655 
1660  void set_dimensions(const vector2f& dimensions) override;
1661 
1666  void set_width(float abs_width) override;
1667 
1672  void set_height(float abs_height) override;
1673 
1682  virtual void notify_mouse_in_frame(bool mouse_in_frame, const vector2f& mouse_pos);
1683 
1688  void notify_visible() override;
1689 
1694  void notify_invisible() override;
1695 
1700  virtual void notify_focus(bool focus);
1701 
1706  void notify_loaded() override;
1707 
1714 
1716  void notify_scaling_factor_updated() override;
1717 
1725  void parse_layout(const layout_node& node) final;
1726 
1728  static void register_on_lua(sol::state& lua);
1729 
1730  static constexpr const char* class_name = "Frame";
1731 
1732 protected:
1733  // Layout parsing
1734  void parse_attributes_(const layout_node& node) override;
1735  virtual void parse_all_nodes_before_children_(const layout_node& node);
1736  virtual void parse_resize_bounds_node_(const layout_node& node);
1737  virtual void parse_title_region_node_(const layout_node& node);
1738  virtual void parse_backdrop_node_(const layout_node& node);
1739  virtual void parse_hit_rect_insets_node_(const layout_node& node);
1740  virtual void parse_layers_node_(const layout_node& node);
1741  virtual void parse_frames_node_(const layout_node& node);
1742  virtual void parse_scripts_node_(const layout_node& node);
1743 
1744  const std::vector<std::string>& get_type_list_() const override;
1745 
1746  utils::observer_ptr<layered_region>
1747  parse_region_(const layout_node& node, const std::string& layer_name, const std::string& type);
1748 
1749  utils::observer_ptr<frame> parse_child_(const layout_node& node, const std::string& type);
1750 
1751  virtual void update_(float delta);
1752 
1753  void check_position_();
1754 
1755  void add_level_(int amount);
1756 
1757  utils::observer_ptr<const frame_renderer> compute_top_level_frame_renderer_() const;
1758 
1759  utils::observer_ptr<frame_renderer> compute_top_level_frame_renderer_() {
1760  return utils::const_pointer_cast<frame_renderer>(
1761  const_cast<const frame*>(this)->compute_top_level_frame_renderer_());
1762  }
1763 
1765 
1766  void notify_strata_changed_(strata new_strata_id);
1767 
1768  void notify_frame_renderer_changed_(const utils::observer_ptr<frame_renderer>& new_renderer);
1769 
1770  void update_borders_() override;
1771 
1777  void set_parent_(utils::observer_ptr<frame> parent) override;
1778 
1779  bool check_script_(const std::string& script_name) const;
1780 
1782  const std::string& script_name,
1783  const std::string& content,
1784  bool append,
1785  const script_info& info);
1786 
1788  const std::string& script_name,
1789  sol::protected_function handler,
1790  bool append,
1791  const script_info& info);
1792 
1794  const std::string& script_name,
1795  script_function handler,
1796  bool append,
1797  const script_info& info);
1798 
1799  void on_event_(std::string_view event_name, const event_data& event);
1800 
1803 
1804  static constexpr std::size_t num_layers = magic_enum::enum_count<layer>();
1805 
1806  std::array<layer_container, num_layers> layer_list_;
1807 
1808  std::unordered_map<std::string, script_signal> signal_list_;
1810 
1811  std::set<std::string> reg_drag_list_;
1812  std::set<std::string> reg_key_list_;
1813 
1814  int level_ = 0;
1815  std::optional<strata> strata_;
1817  bool is_top_level_ = false;
1818 
1819  utils::observer_ptr<frame_renderer> frame_renderer_ = nullptr;
1820  utils::observer_ptr<frame_renderer> effective_frame_renderer_ = nullptr;
1821 
1822  std::unique_ptr<backdrop> backdrop_;
1823 
1827  bool is_keyboard_enabled_ = false;
1828  bool is_movable_ = false;
1830  bool is_resizable_ = false;
1831  bool is_user_placed_ = false;
1832 
1835 
1836  float min_width_ = 0.0f;
1837  float max_width_ = std::numeric_limits<float>::infinity();
1838  float min_height_ = 0.0f;
1839  float max_height_ = std::numeric_limits<float>::infinity();
1840 
1841  float scale_ = 1.0f;
1842 
1843  float update_rate_ = 0.0f;
1844  float time_since_last_update_ = std::numeric_limits<float>::infinity();
1845 
1846  bool is_mouse_in_frame_ = false;
1847 
1849 
1850  bool is_focused_ = false;
1851  bool is_auto_focus_ = false;
1852 };
1853 
1854 } // namespace lxgui::gui
1855 
1856 #endif
Draws borders and background of a frame.
Stores a variable number of arguments for an event.
Utility object to store and manage connections to event signals.
Abstract class for layering and rendering frames.
A region that can contain other regions and react to events.
Definition: gui_frame.hpp:255
bool check_script_(const std::string &script_name) const
Definition: gui_frame.cpp:946
bool is_auto_focus_enabled() const
Checks if automatic focus is enabled.
Definition: gui_frame.cpp:1314
utils::observer_ptr< frame_renderer > effective_frame_renderer_
Definition: gui_frame.hpp:1820
utils::observer_ptr< const region > get_title_region() const
Returns this frame's title region.
Definition: gui_frame.hpp:992
utils::observer_ptr< frame > add_child(utils::owner_ptr< frame > child)
Adds a frame to this frame's children.
Definition: gui_frame.cpp:678
void enable_keyboard()
Marks this frame as able to receive any keyboard input.
Definition: gui_frame.hpp:467
void remove_script(const std::string &script_name)
Removes a script from this frame.
Definition: gui_frame.cpp:1080
utils::view::adaptor< region_list, utils::view::smart_ptr_dereferencer, utils::view::non_null_filter > region_list_view
Definition: gui_frame.hpp:287
std::list< utils::owner_ptr< frame > > child_list
Type of the frame child list (internal).
Definition: gui_frame.hpp:268
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.
Definition: gui_frame.cpp:1072
void set_height(float abs_height) override
Changes this region's absolute height (in pixels).
Definition: gui_frame.cpp:355
void stop_moving()
ends moving this frame.
Definition: gui_frame.cpp:1367
virtual void parse_all_nodes_before_children_(const layout_node &node)
~frame() override
Destructor.
Definition: gui_frame.cpp:43
static void register_on_lua(sol::state &lua)
Registers this region class to the provided Lua state.
void notify_invisible() override
Notifies this region that it is no longer visible on screen.
Definition: gui_frame.cpp:1457
utils::connection add_script(const std::string &script_name, sol::protected_function handler, script_info info=script_info{})
Adds an additional handler script to this frame (executed after existing scripts).
Definition: gui_frame.hpp:1144
bounds2f abs_hit_rect_inset_list_
Definition: gui_frame.hpp:1833
utils::observer_ptr< const frame_renderer > compute_top_level_frame_renderer_() const
Definition: gui_frame.cpp:1414
vector2f get_min_dimensions() const
Returns this frame's min dimensions.
Definition: gui_frame.cpp:789
bool is_mouse_wheel_enabled() const
Checks if this frame can receive mouse wheel input.
Definition: gui_frame.cpp:847
void add_level_(int amount)
Definition: gui_frame.cpp:1342
std::string serialize(const std::string &tab) const override
Prints all relevant information about this region in a string.
Definition: gui_frame.cpp:84
utils::view::adaptor< const child_list, utils::view::smart_ptr_dereferencer, utils::view::non_null_filter > const_child_list_view
Definition: gui_frame.hpp:274
void render() const override
Renders this region on the current render target.
Definition: gui_frame.cpp:62
virtual void parse_hit_rect_insets_node_(const layout_node &node)
void disable_mouse_click()
Marks this frame as unable to receive mouse click input.
Definition: gui_frame.hpp:402
float get_scale() const
Returns this frame's scale.
Definition: gui_frame.cpp:811
utils::observer_ptr< RegionType > add_region(utils::owner_ptr< RegionType > reg)
Adds a layered_region to this frame's children.
Definition: gui_frame.hpp:590
strata effective_strata_
Definition: gui_frame.hpp:1816
bool is_movable() const
Checks if this frame can be moved.
Definition: gui_frame.cpp:863
void set_key_capture_enabled(const std::string &key_name, bool enable)
Marks this frame as able to receive keyboard input from a specific key.
Definition: gui_frame.hpp:486
utils::observer_ptr< frame > get_child(const std::string &name)
Returns one of this frame's children.
Definition: gui_frame.hpp:775
utils::owner_ptr< region > release_from_parent() override
Removes this region from its parent and return an owning pointer.
Definition: gui_frame.cpp:1264
utils::observer_ptr< RegionType > create_layered_region(layer layer_id, const std::string &name)
Creates a new region as child of this frame.
Definition: gui_frame.hpp:651
utils::observer_ptr< frame_renderer > compute_top_level_frame_renderer_()
Definition: gui_frame.hpp:1759
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.
Definition: gui_frame.cpp:1310
std::optional< strata > strata_
Definition: gui_frame.hpp:1815
void stop_sizing()
ends resizing this frame.
Definition: gui_frame.cpp:1380
child_list_view get_children()
Returns the child list.
Definition: gui_frame.cpp:712
const std::vector< std::string > & get_type_list_() const override
Definition: gui_frame.cpp:1614
bool is_resizable() const
Checks if this frame can be resized.
Definition: gui_frame.cpp:867
bool is_user_placed() const
Checks if this frame has been moved by the user.
Definition: gui_frame.cpp:875
static std::string get_adjusted_script_name(const std::string &script_name)
Returns the "adjusted" script name: "OnEvent" becomes "on_event".
Definition: gui_frame.cpp:879
void set_backdrop(std::unique_ptr< backdrop > bdrop)
Sets this frames' backdrop.
Definition: gui_frame.cpp:1188
bool is_in_region(const vector2f &position) const override
Checks if the provided coordinates are inside this frame.
Definition: gui_frame.cpp:819
void copy_from(const region &obj) override
Copies a region's parameters into this frame (inheritance).
Definition: gui_frame.cpp:195
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.
Definition: gui_frame.cpp:1272
std::set< std::string > reg_drag_list_
Definition: gui_frame.hpp:1811
void unregister_event(const std::string &event_name)
Tells the frame not to react to a certain event.
Definition: gui_frame.cpp:1139
utils::connection set_script(const std::string &script_name, sol::protected_function handler, script_info info=script_info{})
Sets a new handler script for this frame (replacing existing scripts).
Definition: gui_frame.hpp:1252
void disable_drag()
Tells this frame to not react to mouse drag from any mouse button.
Definition: gui_frame.cpp:1170
std::array< layer_container, num_layers > layer_list_
Definition: gui_frame.hpp:1806
strata compute_effective_strata_() const
Definition: gui_frame.cpp:739
void set_key_capture_enabled(input::key key_id, bool enable)
Marks this frame as able to receive keyboard input from a specific key.
Definition: gui_frame.hpp:501
vector2f get_max_dimensions() const
Returns this frame's max dimensions.
Definition: gui_frame.cpp:785
utils::observer_ptr< layered_region > get_region(const std::string &name)
Returns one of this frame's region.
Definition: gui_frame.hpp:845
void set_clamped_to_screen(bool is_clamped_to_screen)
Sets if this frame is clamped to screen.
Definition: gui_frame.cpp:1174
utils::connection set_script(const std::string &script_name, Function &&handler, script_info info=script_info{})
Sets a new handler script for this frame (replacing existing scripts).
Definition: gui_frame.hpp:1305
utils::observer_ptr< RegionType > get_region(const std::string &name)
Returns one of this frame's region.
Definition: gui_frame.hpp:863
void set_max_width(float max_width)
Sets this frame's maximum width.
Definition: gui_frame.cpp:1233
void set_level(int level_id)
Sets this frame's level.
Definition: gui_frame.cpp:1201
void create_title_region()
Creates a new title region for this frame.
Definition: gui_frame.cpp:275
void set_max_height(float max_height)
Sets this frame's maximum height.
Definition: gui_frame.cpp:1222
backdrop & get_or_create_backdrop()
Returns this frame's backdrop, creating it if needed.
Definition: gui_frame.cpp:770
void set_draw_layer_enabled(layer layer_id, bool enable)
Enables or disables a layer.
Definition: gui_frame.hpp:342
void notify_layers_need_update()
Tells this frame to rebuild its layer list.
Definition: gui_frame.cpp:489
utils::observer_ptr< frame_renderer > frame_renderer_
Definition: gui_frame.hpp:1819
event_receiver event_receiver_
Definition: gui_frame.hpp:1809
void set_scale(float scale)
Sets this frame's scale.
Definition: gui_frame.cpp:1276
void enable_mouse()
Marks this frame as able to receive mouse input (click & move).
Definition: gui_frame.hpp:372
void start_sizing(const point &p)
Starts resizing this frame with the mouse.
Definition: gui_frame.cpp:1372
std::size_t get_layered_region_count() const
Returns the number of layered regions of this frame.
Definition: gui_frame.cpp:802
void enable_key_capture(const std::string &key_name)
Marks this frame as able to receive keyboard input from a specific key.
Definition: gui_frame.cpp:458
std::size_t get_layered_region_count_upper_bound() const
Returns the approximate number of regions of this frame.
Definition: gui_frame.cpp:807
void update(float delta) final
Updates this region's logic.
Definition: gui_frame.cpp:1543
region_list region_list_
Definition: gui_frame.hpp:1802
virtual void parse_title_region_node_(const layout_node &node)
bool has_script(const std::string &script_name) const
Checks if this frame has a script defined.
Definition: gui_frame.cpp:584
void notify_visible() override
Notifies this region that it is now visible on screen.
Definition: gui_frame.cpp:1423
void set_abs_hit_rect_insets(const bounds2f &insets)
Sets this frame's absolute hit rect insets.
Definition: gui_frame.cpp:1193
utils::observer_ptr< const frame > get_child(const std::string &name) const
Returns one of this frame's children.
Definition: gui_frame.cpp:305
void set_min_height(float min_height)
Sets this frame's minimum height.
Definition: gui_frame.cpp:1244
utils::observer_ptr< FrameType > add_child(utils::owner_ptr< FrameType > child)
Adds a frame to this frame's children.
Definition: gui_frame.hpp:731
void enable_mouse_move()
Marks this frame as able to receive mouse move input.
Definition: gui_frame.hpp:416
bool is_clamped_to_screen() const
Checks if this frame is clamped to screen.
Definition: gui_frame.cpp:815
utils::observer_ptr< const FrameType > get_child(const std::string &name) const
Returns one of this frame's children.
Definition: gui_frame.hpp:792
void parse_attributes_(const layout_node &node) override
bool is_drag_enabled(const std::string &button_name) const
Checks if this frame is registered for drag events with the provided mouse button.
Definition: gui_frame.cpp:851
void set_frame_renderer(utils::observer_ptr< frame_renderer > rdr)
Flags this object as rendered by another object.
Definition: gui_frame.cpp:1398
bool is_key_capture_enabled(const std::string &key_name) const
Checks if this frame can receive keyboard input from a specific key.
Definition: gui_frame.cpp:859
void set_dimensions(const vector2f &dimensions) override
Changes this region's absolute dimensions (in pixels).
Definition: gui_frame.cpp:345
void disable_key_capture()
Marks this frame as unable to receive keyboard input from any key.
Definition: gui_frame.cpp:474
void set_top_level(bool is_top_level)
Sets if this frame is at top level.
Definition: gui_frame.cpp:1282
void on_event_(std::string_view event_name, const event_data &event)
Definition: gui_frame.cpp:1096
void register_event(const std::string &event_name)
Tells this frame to react to a certain event.
Definition: gui_frame.cpp:1131
const backdrop * get_backdrop() const
Returns this frame's backdrop.
Definition: gui_frame.cpp:762
const bounds2f & get_abs_hit_rect_insets() const
Returns this frame's absolute hit rect insets.
Definition: gui_frame.cpp:777
utils::observer_ptr< region > get_title_region()
Returns this frame's title region.
Definition: gui_frame.hpp:997
std::set< std::string > reg_key_list_
Definition: gui_frame.hpp:1812
static constexpr std::size_t num_layers
Definition: gui_frame.hpp:1804
virtual void fire_script(const std::string &script_name, const event_data &data=event_data{})
Calls a script.
Definition: gui_frame.cpp:1105
void set_mouse_move_enabled(bool is_mouse_enabled)
Sets if this frame can receive mouse move input.
Definition: gui_frame.cpp:446
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).
Definition: gui_frame.hpp:1125
std::optional< strata > get_strata() const
Returns this frame's strata.
Definition: gui_frame.cpp:731
void set_width(float abs_width) override
Changes this region's absolute width (in pixels).
Definition: gui_frame.cpp:351
void enable_mouse_click()
Marks this frame as able to receive mouse click input.
Definition: gui_frame.hpp:394
bool is_mouse_click_enabled_
Definition: gui_frame.hpp:1824
void disable_mouse_wheel()
Marks this frame as unable to receive mouse wheel input.
Definition: gui_frame.hpp:446
utils::observer_ptr< FrameType > create_child(frame_core_attributes attr)
Creates a new frame as child of this frame.
Definition: gui_frame.hpp:688
const bounds2f & get_rel_hit_rect_insets() const
Returns this frame's relative hit rect insets.
Definition: gui_frame.cpp:781
void set_mouse_enabled(bool is_mouse_enabled)
Sets if this frame can receive mouse input (click & move).
Definition: gui_frame.cpp:437
const utils::observer_ptr< frame_renderer > & get_frame_renderer()
Returns the renderer of this object, nullptr if none.
Definition: gui_frame.hpp:1629
void enable_mouse_wheel()
Marks this frame as able to receive mouse wheel input.
Definition: gui_frame.hpp:438
std::unordered_map< std::string, script_signal > signal_list_
Definition: gui_frame.hpp:1808
utils::observer_ptr< layered_region > create_layered_region(layer layer_id, region_core_attributes attr)
Creates a new region as child of this frame.
Definition: gui_frame.cpp:652
bool is_top_level() const
Checks if this frame is at top level.
Definition: gui_frame.cpp:871
virtual void update_(float delta)
Definition: gui_frame.cpp:1561
utils::view::adaptor< const region_list, utils::view::smart_ptr_dereferencer, utils::view::non_null_filter > const_region_list_view
Definition: gui_frame.hpp:291
bounds2f rel_hit_rect_inset_list_
Definition: gui_frame.hpp:1834
utils::observer_ptr< frame > find_topmost_frame(const std::function< bool(const frame &)> &predicate)
Find the topmost frame matching the provided predicate.
Definition: gui_frame.hpp:1034
int get_level() const
Returns this frame's level.
Definition: gui_frame.cpp:727
void notify_renderer_need_redraw() override
Notifies the renderer of this region that it needs to be redrawn.
Definition: gui_frame.cpp:1481
utils::observer_ptr< RegionType > create_layered_region(layer layer_id, region_core_attributes attr)
Creates a new region as child of this frame.
Definition: gui_frame.hpp:630
void set_min_width(float min_width)
Sets this frame's minimum width.
Definition: gui_frame.cpp:1252
void set_keyboard_enabled(bool is_keyboard_enabled)
Sets if this frame can receive any keyboard input.
Definition: gui_frame.cpp:454
virtual bool can_use_script(const std::string &script_name) const
Returns 'true' if this frame can use a script.
Definition: gui_frame.cpp:183
utils::observer_ptr< const frame > get_top_level_parent() const
Returns this frame's top-level parent.
Definition: gui_frame.cpp:750
utils::connection add_script(const std::string &script_name, script_function handler, script_info info=script_info{})
Adds an additional handler script to this frame (executed after existing scripts).
Definition: gui_frame.hpp:1165
void set_min_dimensions(const vector2f &min)
Sets this frame's minimum size.
Definition: gui_frame.cpp:1217
void disable_keyboard()
Marks this frame as unable to receive any keyboard input.
Definition: gui_frame.hpp:475
void set_parent_(utils::observer_ptr< frame > parent) override
Changes this region's parent.
Definition: gui_frame.cpp:513
bool is_mouse_move_enabled() const
Checks if this frame can receive mouse movement input.
Definition: gui_frame.cpp:843
bool is_mouse_click_enabled() const
Checks if this frame can receive mouse click input.
Definition: gui_frame.cpp:839
virtual void parse_resize_bounds_node_(const layout_node &node)
void notify_loaded() override
Notifies this region that it has been fully loaded.
Definition: gui_frame.cpp:478
bool has_focus() const
Check if this frame currently has focus.
Definition: gui_frame.cpp:1326
utils::observer_ptr< FrameType > create_child(const std::string &name)
Creates a new frame as child of this frame.
Definition: gui_frame.hpp:709
void check_position_()
Definition: gui_frame.cpp:359
float get_effective_scale() const
Calculates effective scale.
Definition: gui_frame.cpp:720
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).
Definition: gui_frame.hpp:1233
void set_update_rate(float rate)
Sets a maximum update rate (in updates per seconds).
Definition: gui_frame.cpp:1146
strata get_effective_strata() const
Returns this frame's effective strata.
Definition: gui_frame.cpp:735
void parse_layout(const layout_node &node) final
Parses data from a layout_node.
utils::observer_ptr< FrameType > get_child(const std::string &name)
Returns one of this frame's children.
Definition: gui_frame.hpp:809
utils::owner_ptr< layered_region > remove_region(const utils::observer_ptr< layered_region > &reg)
Removes a layered_region from this frame's children.
Definition: gui_frame.cpp:617
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.
Definition: gui_frame.cpp:1197
std::size_t get_child_count() const
Returns the number of children of this frame.
Definition: gui_frame.cpp:793
std::list< utils::owner_ptr< layered_region > > region_list
Type of the region list (internal).
Definition: gui_frame.hpp:285
child_list child_list_
Definition: gui_frame.hpp:1801
bool is_mouse_wheel_enabled_
Definition: gui_frame.hpp:1826
void update_borders_() override
Definition: gui_frame.cpp:1519
bool is_keyboard_enabled() const
Checks if this frame can receive any keyboard input.
Definition: gui_frame.cpp:855
void set_user_placed(bool is_user_placed)
Sets if this frame has been moved by the user.
Definition: gui_frame.cpp:1355
void set_strata(std::optional< strata > strata_id)
Sets this frame's strata.
Definition: gui_frame.cpp:1178
void set_mouse_click_enabled(bool is_mouse_enabled)
Sets if this frame can receive mouse click input.
Definition: gui_frame.cpp:442
void set_drag_enabled(input::mouse_button button_id, bool enable)
Tells this frame whether to react to mouse drag or not.
Definition: gui_frame.hpp:1404
virtual void notify_focus(bool focus)
Notifies this frame that it has received or lost focus.
Definition: gui_frame.cpp:1330
utils::owner_ptr< frame > remove_child(const utils::observer_ptr< frame > &child)
Removes a frame from this frame's children.
Definition: gui_frame.cpp:690
void set_drag_enabled(const std::string &button_name, bool enable)
Tells this frame whether to react to mouse drag or not.
Definition: gui_frame.hpp:1391
void set_focus(bool focus)
Asks for focus for this frame.
Definition: gui_frame.cpp:1318
utils::observer_ptr< const frame_renderer > get_effective_frame_renderer() const final
Returns the renderer of this object or its parents, nullptr if none.
Definition: gui_frame.cpp:1410
std::unique_ptr< backdrop > backdrop_
Definition: gui_frame.hpp:1822
utils::observer_ptr< frame > parse_child_(const layout_node &node, const std::string &type)
utils::observer_ptr< const layered_region > get_region(const std::string &name) const
Returns one of this frame's region.
Definition: gui_frame.cpp:329
utils::connection set_script(const std::string &script_name, script_function handler, script_info info=script_info{})
Sets a new handler script for this frame (replacing existing scripts).
Definition: gui_frame.hpp:1273
utils::owner_ptr< region > title_region_
Definition: gui_frame.hpp:1848
void disable_mouse()
Marks this frame as unable to receive mouse input (click & move).
Definition: gui_frame.hpp:380
float get_update_rate() const
Gets the maximum update rate (in upates per seconds).
Definition: gui_frame.cpp:1150
void set_mouse_wheel_enabled(bool is_mouse_wheel_enabled)
Sets if this frame can receive mouse wheel input.
Definition: gui_frame.cpp:450
utils::observer_ptr< frame > get_top_level_parent()
Returns this frame's top-level parent.
Definition: gui_frame.hpp:902
void enable_draw_layer(layer layer_id)
Enables a layer.
Definition: gui_frame.cpp:429
utils::observer_ptr< const frame_renderer > get_frame_renderer() const
Returns the renderer of this object, nullptr if none.
Definition: gui_frame.hpp:1620
void set_movable(bool is_movable)
Sets if this frame can be moved by the user.
Definition: gui_frame.cpp:1260
void disable_mouse_move()
Marks this frame as unable to receive mouse move input.
Definition: gui_frame.hpp:424
virtual void notify_mouse_in_frame(bool mouse_in_frame, const vector2f &mouse_pos)
Tells this frame it is being hovered by the mouse.
Definition: gui_frame.cpp:1501
utils::observer_ptr< frame > create_child(frame_core_attributes attr)
Creates a new frame as child of this frame.
Definition: gui_frame.cpp:666
region_list_view get_regions()
Returns the region list.
Definition: gui_frame.cpp:321
float time_since_last_update_
Definition: gui_frame.hpp:1844
utils::connection add_script(const std::string &script_name, Function &&handler, script_info info=script_info{})
Adds an additional handler script to this frame (executed after existing scripts).
Definition: gui_frame.hpp:1197
virtual void parse_frames_node_(const layout_node &node)
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.
Definition: gui_frame.cpp:832
void set_max_dimensions(const vector2f &max)
Sets this frame's maximum size.
Definition: gui_frame.cpp:1212
std::size_t get_child_count_upper_bound() const
Returns the approximate number of children of this frame.
Definition: gui_frame.cpp:798
void notify_strata_changed_(strata new_strata_id)
Definition: gui_frame.cpp:567
utils::view::adaptor< child_list, utils::view::smart_ptr_dereferencer, utils::view::non_null_filter > child_list_view
Definition: gui_frame.hpp:270
static constexpr const char * class_name
Definition: gui_frame.hpp:1730
utils::observer_ptr< layered_region > add_region(utils::owner_ptr< layered_region > reg)
Adds a layered_region to this frame's children.
Definition: gui_frame.cpp:592
void notify_scaling_factor_updated() override
Tells this region that the global interface scaling factor has changed.
Definition: gui_frame.cpp:1488
void start_moving()
Starts moving this frame with the mouse.
Definition: gui_frame.cpp:1359
utils::connection define_script_(const std::string &script_name, const std::string &content, bool append, const script_info &info)
Definition: gui_frame.cpp:957
void notify_frame_renderer_changed_(const utils::observer_ptr< frame_renderer > &new_renderer)
Definition: gui_frame.cpp:1385
void disable_draw_layer(layer layer_id)
Disables a layer.
Definition: gui_frame.cpp:421
void enable_drag(const std::string &button_name)
Tells this frame to react to mouse drag.
Definition: gui_frame.cpp:1154
An node in a layout file.
Manages the user interface.
Definition: gui_manager.hpp:44
The base class of all elements in the GUI.
Definition: gui_region.hpp:161
region(utils::control_block &block, manager &mgr, const region_core_attributes &attr)
Contructor.
Definition: gui_region.cpp:21
Object representing the connection between a slot and a signal.
Generic class for observing and triggering events.
utils::view::adaptor< slot_list, slot_dereferencer, non_disconnected_filter > slot_list_view
Type of the view returned by slots().
std::function< T > function_type
Type of the callable function stored in a slot. Can use any function/delegate type here,...
Allow iterating over a container without access to the container itself.
Definition: utils_view.hpp:60
layer
ID of a layer for rendering inside a frame.
script_signal::function_type script_function
C++ function type for UI script handlers.
Definition: gui_frame.hpp:51
script_signal::slot_list_view script_list_view
View into all the connected scripts for a given event.
Definition: gui_frame.hpp:54
void(frame &, const event_data &) script_signature
Signature of frame scripts.
Definition: gui_frame.hpp:45
oup::observable_sealed_ptr< T > owner_ptr
typename impl::first_function_argument_< decltype(&std::decay_t< T >::operator())>::type first_function_argument
Definition: utils_meta.hpp:32
static const bounds2 zero
Definition: gui_bounds2.hpp:85
Struct holding all the core information about a frame necessary for its creation.
Contains gui::layered_region.
Definition: gui_frame.hpp:33
std::vector< utils::observer_ptr< layered_region > > region_list
Definition: gui_frame.hpp:35
Struct holding all the core information about a region necessary for its creation.
Holds file/line information for a script.
Definition: gui_frame.hpp:39
Convert unique_ptr or shared_ptr to standard pointer.
Definition: utils_view.hpp:21