1 #ifndef LXGUI_GUI_REGION_TPL_HPP
2 #define LXGUI_GUI_REGION_TPL_HPP
4 #include "lxgui/gui_frame.hpp"
5 #include "lxgui/gui_manager.hpp"
6 #include "lxgui/gui_region.hpp"
7 #include "lxgui/gui_registry.hpp"
8 #include "lxgui/gui_root.hpp"
9 #include "lxgui/lxgui.hpp"
10 #include "lxgui/utils_observer.hpp"
11 #include "lxgui/utils_string.hpp"
13 #include <lxgui/extern_sol2_state.hpp>
20 struct unique_usertype_traits<
lxgui::utils::observer_ptr<T>> {
21 static T*
get(lua_State*,
const lxgui::utils::observer_ptr<T>& pointer) noexcept {
25 static bool is_null(lua_State*,
const lxgui::utils::observer_ptr<T>& pointer) noexcept {
26 return pointer.expired();
38 sol::types<T>, lua_State* lua,
int index, sol::stack::record& ) {
42 using RegionType = std::remove_pointer_t<T>;
44 sol::optional<lxgui::utils::observer_ptr<RegionType>&> optional =
45 sol::stack::check_get<lxgui::utils::observer_ptr<RegionType>&>(
46 lua, index, sol::no_panic );
48 if (!optional.has_value())
51 if (optional->expired())
52 throw sol::error(
"object has been deleted");
55 inline utils::observer_ptr<region>
58 [&](
const auto& value) -> utils::observer_ptr<region> {
59 using data_type = std::decay_t<decltype(value)>;
60 if constexpr (std::is_same_v<data_type, std::string>) {
61 if (utils::has_no_content(value))
66 throw sol::error(
"no region with name \"" + value +
"\"");
77 utils::observer_ptr<T>
get_object(
manager& mgr,
const std::variant<std::string, T*>& parent) {
79 [&](
const auto& value) -> utils::observer_ptr<T> {
80 using data_type = std::decay_t<decltype(value)>;
81 if constexpr (std::is_same_v<data_type, std::string>) {
82 if (utils::has_no_content(value))
87 throw sol::error(
"no region with name \"" + value +
"\"");
89 auto parent_obj = down_cast<T>(parent_object);
92 "region \"" + value +
"\" is not a " + std::string(T::class_name));
102 #if defined(LXGUI_COMPILER_EMSCRIPTEN)
106 template<
typename T, T F>
107 struct member_function_holder;
109 template<
typename R,
typename T,
typename... Args, R (T::*Function)(Args...)>
110 struct member_function_holder<R (T::*)(Args...), Function> {
111 static constexpr
auto make_free_function() {
112 return [](T&
self, Args... args) {
return (
self.*Function)(std::move(args)...); };
116 template<
typename R,
typename T,
typename... Args, R (T::*Function)(Args...)
const>
117 struct member_function_holder<R (T::*)(Args...) const, Function> {
118 static constexpr
auto make_free_function() {
119 return [](
const T&
self, Args... args) {
return (
self.*Function)(std::move(args)...); };
125 return member_function_holder<decltype(T), T>::make_free_function();
148 if constexpr (std::is_same_v<T, region>) {
153 static const std::vector<std::string> type = []() {
154 using base =
typename T::base;
155 auto list = get_type_list_impl_<base>();
156 list.push_back(T::class_name);
Manages the user interface.
root & get_root()
Returns the UI root object, which contains root frames.
void create_glue_(T &self)
void initialize_(T &self, const region_core_attributes &attr)
Set up function to call in all derived class constructors.
bool is_virtual() const
Checks if this region is virtual.
const std::string & get_name() const
Returns this region's name.
static const std::vector< std::string > & get_type_list_impl_()
static constexpr const char * class_name
utils::observer_ptr< const region > get_region_by_name(std::string_view name) const
Returns the region associated with the given name.
registry & get_registry()
Returns the UI object registry, which keeps track of all objects in the UI.
utils::observer_ptr< ObjectType > observer_from(ObjectType *self)
Obtain an observer pointer from a raw pointer (typically 'this')
utils::observer_ptr< region > get_object(manager &mgr, const std::variant< std::string, region * > &parent)
void sol_lua_check_access(sol::types< T >, lua_State *lua, int index, sol::stack::record &)
constexpr auto member_function()
T & get(variant &value)
Retrieve the value stored in an utils::variant.
Struct holding all the core information about a region necessary for its creation.