lxgui
Loading...
Searching...
No Matches
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/magic_enum.hpp>
22#include <optional>
23#include <set>
24#include <unordered_map>
25#include <vector>
26
27namespace lxgui::gui {
28
29class frame_renderer;
30class frame;
31
34 bool is_disabled = false;
35 std::vector<utils::observer_ptr<layered_region>> region_list;
36};
37
40 std::string file_name;
41 std::size_t line_nbr = 0;
42};
43
45using script_signature = void(frame&, const event_data&);
46
49
52
55
255class frame : public region {
256public:
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
373 set_mouse_enabled(true);
374 }
375
381 set_mouse_enabled(false);
382 }
383
388 void set_mouse_click_enabled(bool is_mouse_enabled);
389
397
405
410 void set_mouse_move_enabled(bool is_mouse_enabled);
411
418 }
419
426 }
427
433
441
449
462
469 }
470
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
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
1732protected:
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
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
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.
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 enable_keyboard()
Marks this frame as able to receive any keyboard input.
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
std::list< utils::owner_ptr< frame > > child_list
Type of the frame child list (internal).
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.
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.
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).
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.
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
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.
float get_scale() const
Returns this frame's scale.
bool is_movable() const
Checks if this frame can be moved.
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.
utils::observer_ptr< RegionType > create_layered_region(layer layer_id, region_core_attributes attr)
Creates a new region as child of this frame.
utils::owner_ptr< region > release_from_parent() override
Removes this region from its parent and return an owning pointer.
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.
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).
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.
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.
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).
void disable_drag()
Tells this frame to not react to mouse drag from any mouse button.
std::array< layer_container, num_layers > layer_list_
utils::observer_ptr< RegionType > get_region(const std::string &name)
Returns one of this frame's region.
utils::observer_ptr< const FrameType > get_child(const std::string &name) const
Returns one of this frame's children.
strata compute_effective_strata_() const
void set_key_capture_enabled(input::key key_id, bool enable)
Marks this frame as able to receive keyboard input from a specific key.
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.
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).
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 set_draw_layer_enabled(layer layer_id, bool enable)
Enables or disables a layer.
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 enable_mouse()
Marks this frame as able to receive mouse input (click & move).
utils::observer_ptr< const frame_renderer > get_frame_renderer() const
Returns the renderer of this object, nullptr if none.
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.
region_list region_list_
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.
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.
void enable_mouse_move()
Marks this frame as able to receive mouse move input.
bool is_clamped_to_screen() const
Checks if this frame is clamped to screen.
void parse_attributes_(const layout_node &node) override
utils::observer_ptr< frame_renderer > compute_top_level_frame_renderer_()
bool is_drag_enabled(const std::string &button_name) const
Checks if this frame is registered for drag events with the provided mouse button.
utils::observer_ptr< FrameType > create_child(const std::string &name)
Creates a new frame as child of this frame.
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 utils::observer_ptr< frame_renderer > & get_frame_renderer()
Returns the renderer of this object, nullptr if none.
const bounds2f & get_abs_hit_rect_insets() const
Returns this frame's absolute hit rect insets.
std::set< std::string > reg_key_list_
static constexpr std::size_t num_layers
virtual void fire_script(const std::string &script_name, const event_data &data=event_data{})
Calls a script.
utils::observer_ptr< RegionType > add_region(utils::owner_ptr< RegionType > reg)
Adds a layered_region to this frame's children.
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).
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).
void enable_mouse_click()
Marks this frame as able to receive mouse click input.
void disable_mouse_wheel()
Marks this frame as unable to receive mouse wheel input.
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).
void enable_mouse_wheel()
Marks this frame as able to receive mouse wheel input.
std::unordered_map< std::string, script_signal > signal_list_
utils::observer_ptr< FrameType > get_child(const std::string &name)
Returns one of this frame's children.
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.
void set_keyboard_enabled(bool is_keyboard_enabled)
Sets if this frame can receive any keyboard input.
utils::observer_ptr< const region > get_title_region() const
Returns this frame's title region.
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.
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).
void set_min_dimensions(const vector2f &min)
Sets this frame's minimum size.
void disable_keyboard()
Marks this frame as unable to receive any keyboard input.
utils::observer_ptr< frame > find_topmost_frame(const std::function< bool(const frame &)> &predicate)
Find the topmost frame matching the provided predicate.
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.
utils::observer_ptr< FrameType > add_child(utils::owner_ptr< FrameType > child)
Adds a frame to this frame's children.
utils::observer_ptr< layered_region > get_region(const std::string &name)
Returns one of this frame's region.
virtual void parse_resize_bounds_node_(const layout_node &node)
void notify_loaded() override
Notifies this region that it has been fully loaded.
utils::observer_ptr< frame > get_top_level_parent()
Returns this frame's top-level parent.
bool has_focus() const
Check if this frame currently has focus.
utils::observer_ptr< FrameType > create_child(frame_core_attributes attr)
Creates a new frame as child of this frame.
float get_effective_scale() const
Calculates effective scale.
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).
strata get_effective_strata() const
Returns this frame's effective strata.
utils::observer_ptr< frame > get_child(const std::string &name)
Returns one of this frame's children.
void parse_layout(const layout_node &node) final
Parses data from a layout_node.
utils::owner_ptr< layered_region > remove_region(const utils::observer_ptr< layered_region > &reg)
Removes a layered_region from this frame's children.
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.
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).
child_list child_list_
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.
void set_drag_enabled(input::mouse_button button_id, bool enable)
Tells this frame whether to react to mouse drag or not.
virtual void notify_focus(bool focus)
Notifies this frame that it has received or lost focus.
utils::observer_ptr< RegionType > create_layered_region(layer layer_id, const std::string &name)
Creates a new region as child of this frame.
utils::owner_ptr< frame > remove_child(const utils::observer_ptr< frame > &child)
Removes a frame from this frame's children.
void set_drag_enabled(const std::string &button_name, bool enable)
Tells this frame whether to react to mouse drag or not.
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< 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.
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).
utils::owner_ptr< region > title_region_
utils::observer_ptr< region > get_title_region()
Returns this frame's title region.
void disable_mouse()
Marks this frame as unable to receive mouse input (click & move).
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.
void disable_mouse_move()
Marks this frame as unable to receive mouse move input.
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.
region_list_view get_regions()
Returns the region list.
float time_since_last_update_
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).
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.
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
static constexpr const char * class_name
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.
An node in a layout file.
Manages the user interface.
The base class of all elements in the GUI.
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.
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
static const bounds2 zero
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.