ChatPlexSDK-BS 1.0.1-v6.2.0
C++ ChatPlex BeatSaber SDK
Loading...
Searching...
No Matches
XUIHOrVSpacer.hpp
1#pragma once
2
3#include "../../UI/Components/CHLayout.hpp"
4#include "../../UI/Components/CVLayout.hpp"
5#include "IXUIElement.hpp"
6#include "IXUIBindable.hpp"
7#include "IXUIElementReady.hpp"
8
9namespace CP_SDK::XUI {
10
14 template<class t_Base, class t_Component>
16 : public IXUIElement,
17 public IXUIElementReady<t_Base, t_Component>,
18 public IXUIBindable<t_Base>,
19 public std::enable_shared_from_this<t_Base>
20 {
21 CP_SDK_NO_COPYMOVE_CTORS(_XUIHOrVSpacer);
22
23 private:
25
27
28 public:
29 std::shared_ptr<t_Base> AsShared() { return std::enable_shared_from_this<t_Base>::shared_from_this(); }
30
31 virtual _v::UIFieldRef<_u::RectTransform> RTransform() override
32 {
33 return m_Element ? m_Element->RTransform() : _v::UIFieldDefault<_u::RectTransform>::Value;
34 }
35 virtual _v::UIFieldRef<t_Component> Element()
36 {
37 return m_Element;
38 }
39
40 protected:
45 _XUIHOrVSpacer(std::u16string_view p_Name, IXUIElement::ETypeID p_TypeID, float p_Spacing)
46 : IXUIElement(p_Name, p_TypeID)
47 {
48 SetSpacing(p_Spacing);
49 }
51 virtual ~_XUIHOrVSpacer() = default;
52
53 public:
56 virtual void BuildUI(_u::Transform* p_Parent) override
57 {
58 if constexpr (std::is_same_v<t_Component, _v::CHLayout>)
59 m_Element = _v::UISystem::HLayoutFactory->Create(IXUIElement::GetInitialName(), p_Parent);
60 else
61 m_Element = _v::UISystem::VLayoutFactory->Create(IXUIElement::GetInitialName(), p_Parent);
62
63 try { m_OnReady(m_Element.Ptr()); m_OnReady.Clear(); }
64 catch (const std::exception& l_Exception)
65 {
66 ChatPlexSDK::Logger()->Error(u"[CP_SDK.XUI][_XUIHOrVSpacer<{typeof(t_Component).Name}>.BuildUI] Error OnReady:");
67 ChatPlexSDK::Logger()->Error(l_Exception);
68 }
69 }
70
71 public:
74 virtual t_Base* OnReady(_v::CActionRef<t_Component*> p_Functor) override
75 {
76 if (m_Element) p_Functor(m_Element.Ptr());
77 else m_OnReady += p_Functor;
78 return reinterpret_cast<t_Base*>(this);
79 }
82 virtual t_Base* Bind(std::shared_ptr<t_Base>* p_Target) override
83 {
84 *p_Target = std::enable_shared_from_this<t_Base>::shared_from_this();
85 return reinterpret_cast<t_Base*>(this);
86 }
87
88 public:
91 t_Base* SetActive(bool p_Active) XUI_PROXY_IMPL_EX(t_Component, { x->get_gameObject()->SetActive(p_Active); })
92
93 public:
96 t_Base* SetSpacing(float p_Spacing) XUI_PROXY_IMPL_EX(t_Component, {
97 if constexpr (std::is_same_v<t_Component, _v::CHLayout>)
98 { x->SetMinWidth(p_Spacing); x->SetWidth(p_Spacing); }
99 else
100 { x->SetMinHeight(p_Spacing); x->SetHeight(p_Spacing); }
101 })
102
103 };
104
105}
static Logging::ILogger * Logger()
Logger instance.
Event class helper.
Definition Event.hpp:100
IHOrVLayout abstract XUI Element.
virtual ~_XUIHOrVSpacer()=default
Destructor.
virtual void BuildUI(_u::Transform *p_Parent) override
BuildUI for this element into p_Parent transform.
virtual t_Base * Bind(std::shared_ptr< t_Base > *p_Target) override
On ready, bind.
_XUIHOrVSpacer(std::u16string_view p_Name, IXUIElement::ETypeID p_TypeID, float p_Spacing)
Constructor.
t_Base * SetActive(bool p_Active) XUI_PROXY_IMPL_EX(t_Component
Set game object active state.
virtual t_Base * OnReady(_v::CActionRef< t_Component * > p_Functor) override
IXUIElement OnReady functor interface.
t_Base * SetSpacing(float p_Spacing) XUI_PROXY_IMPL_EX(t_Component
Set spacing between elements.
IXUIElement Bind interface.
Element interface.
std::u16string_view GetInitialName()
Get initial name.
IXUIElement OnReady functor interface.
Tree like syntax CP_SDK::UI builder.