ChatPlexSDK-BS 1.0.1-v6.2.0
C++ ChatPlex BeatSaber SDK
All Classes Namespaces Functions Variables Typedefs Enumerations Concepts
XUIHOrVLayout.hpp
1#pragma once
2
3#include "../../UI/Components/CHLayout.hpp"
4#include "../../UI/Components/CVLayout.hpp"
5#include "IXUIElementWithChilds.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 IXUIElementWithChilds<t_Base>,
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(_XUIHOrVLayout);
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 _XUIHOrVLayout(std::u16string_view p_Name, IXUIElement::ETypeID p_TypeID, const std::vector<std::shared_ptr<IXUIElement>>& p_Childs)
46 : IXUIElementWithChilds<t_Base>(p_Name, p_TypeID, p_Childs)
47 { }
49 virtual ~_XUIHOrVLayout() = default;
50
51 public:
54 virtual void BuildUI(_u::Transform* p_Parent) override
55 {
56 if constexpr (std::is_same_v<t_Component, _v::CHLayout>)
57 m_Element = _v::UISystem::HLayoutFactory->Create(IXUIElement::GetInitialName(), p_Parent);
58 else
59 m_Element = _v::UISystem::VLayoutFactory->Create(IXUIElement::GetInitialName(), p_Parent);
60
61 m_Element->SetSpacing(2.0f);
62 m_Element->SetPadding(_u::RectOffset::New_ctor(2, 2, 2, 2));
63
64 IXUIElementWithChilds<t_Base>::BuildUIChilds(m_Element->get_transform());
65
66 try { m_OnReady(m_Element.Ptr()); m_OnReady.Clear(); }
67 catch (const std::exception& l_Exception)
68 {
69 if constexpr (std::is_same_v<t_Component, _v::CHLayout>)
70 ChatPlexSDK::Logger()->Error(u"[CP_SDK.XUI][_XUIHOrVLayout<CHLayout>.BuildUI] Error OnReady:");
71 else
72 ChatPlexSDK::Logger()->Error(u"[CP_SDK.XUI][_XUIHOrVLayout<CVLayout}>.BuildUI] Error OnReady:");
73 ChatPlexSDK::Logger()->Error(l_Exception);
74 }
75 }
76
77 public:
80 virtual t_Base* OnReady(_v::CActionRef<t_Component*> p_Functor) override
81 {
82 if (m_Element) p_Functor(m_Element.Ptr());
83 else m_OnReady += p_Functor;
84 return reinterpret_cast<t_Base*>(this);
85 }
88 virtual t_Base* Bind(std::shared_ptr<t_Base>* p_Target) override
89 {
90 *p_Target = std::enable_shared_from_this<t_Base>::shared_from_this();
91 return reinterpret_cast<t_Base*>(this);
92 }
93
94 public:
97 t_Base* SetActive(bool p_Active) XUI_PROXY_IMPL_EX(t_Component, { x->get_gameObject()->SetActive(p_Active); })
98
99 public:
104 t_Base* SetBackground(bool p_Enabled, std::optional<_u::Color> p_Color = std::nullopt, bool p_RaycastTarget = false) XUI_PROXY_IMPL_EX(t_Component, { x->SetBackground(p_Enabled, p_Color, p_RaycastTarget); })
107 t_Base* SetBackgroundColor(float p_Color) XUI_PROXY_IMPL_EX(t_Component, { x->SetBackgroundColor(p_Color); })
108
111 t_Base* SetBackgroundFillMethod(_u::Image::FillMethod p_FillMethod) XUI_PROXY_IMPL_EX(t_Component, { x->SetBackgroundFillMethod(p_FillMethod); })
114 t_Base* SetBackgroundFillAmount(float p_FillAmount) XUI_PROXY_IMPL_EX(t_Component, { x->SetBackgroundFillAmount(p_FillAmount); })
118 t_Base* SetBackgroundSprite(_u::Sprite* p_Sprite, _u::Image::Type p_Type = _u::Image::Type::Simple) XUI_PROXY_IMPL_EX(t_Component, { x->SetBackgroundSprite(p_Sprite, p_Type); })
119
120 public:
123 t_Base* SetWidth(float p_Width) XUI_PROXY_IMPL_EX(t_Component, { x->SetWidth(p_Width); })
126 t_Base* SetHeight(float p_Height) XUI_PROXY_IMPL_EX(t_Component, { x->SetHeight(p_Height); })
127
128 public:
131 t_Base* SetMinWidth(float p_Width) XUI_PROXY_IMPL_EX(t_Component, { x->SetMinWidth(p_Width); })
134 t_Base* SetMinHeight(float p_Height) XUI_PROXY_IMPL_EX(t_Component, { x->SetMinHeight(p_Height); })
135
136 public:
139 t_Base* SetPadding(_u::RectOffset* p_Padding) XUI_PROXY_IMPL_EX(t_Component, { x->SetPadding(p_Padding); })
145 t_Base* SetPadding(int p_Top, int p_Right, int p_Bottom, int p_Left) XUI_PROXY_IMPL_EX(t_Component, { x->SetPadding(p_Top, p_Right, p_Bottom, p_Left); })
148 t_Base* SetPadding(int p_Padding) XUI_PROXY_IMPL_EX(t_Component, { x->SetPadding(p_Padding); })
149
150 public:
153 t_Base* SetSpacing(float p_Spacing) XUI_PROXY_IMPL_EX(t_Component, { x->SetSpacing(p_Spacing); })
154
155 };
156
157}
static Logging::ILogger * Logger()
Logger instance.
Event class helper.
Definition Event.hpp:100
CHOrVLayout abstract XUI Element.
t_Base t_Base t_Base t_Base * SetBackgroundFillAmount(float p_FillAmount) XUI_PROXY_IMPL_EX(t_Component
Set background fill amount.
t_Base * SetSpacing(float p_Spacing) XUI_PROXY_IMPL_EX(t_Component
Set spacing between elements.
virtual t_Base * OnReady(_v::CActionRef< t_Component * > p_Functor) override
IXUIElement OnReady functor interface.
virtual t_Base * Bind(std::shared_ptr< t_Base > *p_Target) override
On ready, bind.
virtual ~_XUIHOrVLayout()=default
Destructor.
t_Base * SetActive(bool p_Active) XUI_PROXY_IMPL_EX(t_Component
Set game object active state.
t_Base t_Base t_Base * SetPadding(int p_Padding) XUI_PROXY_IMPL_EX(t_Component
Set padding.
t_Base t_Base * SetPadding(int p_Top, int p_Right, int p_Bottom, int p_Left) XUI_PROXY_IMPL_EX(t_Component
Set padding.
_XUIHOrVLayout(std::u16string_view p_Name, IXUIElement::ETypeID p_TypeID, const std::vector< std::shared_ptr< IXUIElement > > &p_Childs)
Constructor.
t_Base t_Base * SetBackgroundColor(float p_Color) XUI_PROXY_IMPL_EX(t_Component
Set background color.
t_Base * SetPadding(_u::RectOffset *p_Padding) XUI_PROXY_IMPL_EX(t_Component
Set padding.
t_Base t_Base * SetMinHeight(float p_Height) XUI_PROXY_IMPL_EX(t_Component
Set min height.
t_Base t_Base t_Base * SetBackgroundFillMethod(_u::Image::FillMethod p_FillMethod) XUI_PROXY_IMPL_EX(t_Component
Set background fill method.
t_Base t_Base * SetHeight(float p_Height) XUI_PROXY_IMPL_EX(t_Component
Set preferred height.
t_Base t_Base t_Base t_Base t_Base * SetBackgroundSprite(_u::Sprite *p_Sprite, _u::Image::Type p_Type=_u::Image::Type::Simple) XUI_PROXY_IMPL_EX(t_Component
Set background sprite.
virtual void BuildUI(_u::Transform *p_Parent) override
BuildUI for this element into p_Parent transform.
t_Base * SetWidth(float p_Width) XUI_PROXY_IMPL_EX(t_Component
Set preferred width.
t_Base * SetMinWidth(float p_Width) XUI_PROXY_IMPL_EX(t_Component
Set min width.
t_Base * SetBackground(bool p_Enabled, std::optional< _u::Color > p_Color=std::nullopt, bool p_RaycastTarget=false) XUI_PROXY_IMPL_EX(t_Component
IXUIElement Bind interface.
std::u16string_view GetInitialName()
Get initial name.
IXUIElement OnReady functor interface.
IXUIElement with children abstract class.
void BuildUIChilds(_u::Transform *p_Parent)
BuildUI for children into p_Parent transform.
Tree like syntax CP_SDK::UI builder.