lxgui
Loading...
Searching...
No Matches
gui_registry.hpp
1#ifndef LXGUI_GUI_REGISTRY_HPP
2#define LXGUI_GUI_REGISTRY_HPP
3
4#include "lxgui/lxgui.hpp"
5#include "lxgui/utils_observer.hpp"
6
7#include <string>
8#include <string_view>
9#include <unordered_map>
10
11namespace lxgui::gui {
12
13class region;
14
16class registry {
17public:
18 registry() = default;
19 virtual ~registry() = default;
20
21 registry(const registry&) = default;
22 registry(registry&&) = default;
23 registry& operator=(const registry&) = default;
25
31 bool check_region_name(std::string_view name) const;
32
38 bool add_region(utils::observer_ptr<region> obj);
39
44 void remove_region(const region& obj);
45
51 utils::observer_ptr<const region> get_region_by_name(std::string_view name) const;
52
58 utils::observer_ptr<region> get_region_by_name(std::string_view name) {
59 return utils::const_pointer_cast<region>(
60 const_cast<const registry*>(this)->get_region_by_name(name));
61 }
62
63private:
64 template<typename T>
65 using string_map = std::unordered_map<std::string, T>;
66
67 string_map<utils::observer_ptr<region>> named_object_list_;
68};
69
70} // namespace lxgui::gui
71
72#endif
The base class of all elements in the GUI.
Keeps track of created UI objects and records their names for lookup.
registry(const registry &)=default
virtual ~registry()=default
registry & operator=(registry &&)=default
void remove_region(const region &obj)
Removes a region from this registry.
utils::observer_ptr< region > get_region_by_name(std::string_view name)
Returns the region associated with the given name.
registry & operator=(const registry &)=default
registry(registry &&)=default
bool add_region(utils::observer_ptr< region > obj)
Adds a region to be handled by this registry.
bool check_region_name(std::string_view name) const
Checks the provided string is suitable for naming a region.
utils::observer_ptr< const region > get_region_by_name(std::string_view name) const
Returns the region associated with the given name.