diff options
65 files changed, 278 insertions, 403 deletions
diff --git a/include/cru/platform/gui/win/Keyboard.h b/include/cru/platform/gui/win/Keyboard.h index c98c49a3..8b02d0e7 100644 --- a/include/cru/platform/gui/win/Keyboard.h +++ b/include/cru/platform/gui/win/Keyboard.h @@ -5,5 +5,5 @@ namespace cru::platform::gui::win { KeyCode CRU_WIN_GUI_API VirtualKeyToKeyCode(int virtual_key); -KeyModifier CRU_WIN_GUI_API RetrieveKeyMofifier(); +KeyModifier CRU_WIN_GUI_API RetrieveKeyModifier(); } // namespace cru::platform::gui::win diff --git a/include/cru/ui/components/Component.h b/include/cru/ui/components/Component.h index 1e002e5f..86012e59 100644 --- a/include/cru/ui/components/Component.h +++ b/include/cru/ui/components/Component.h @@ -15,7 +15,7 @@ class CRU_UI_API Component public: virtual controls::Control* GetRootControl() = 0; - bool IsDeleteByParent() const { return delete_by_parent_; } + bool IsDeleteByParent() { return delete_by_parent_; } void SetDeleteByParent(bool delete_by_parent) { delete_by_parent_ = delete_by_parent; } diff --git a/include/cru/ui/components/Input.h b/include/cru/ui/components/Input.h index 0f077983..3d56f5fa 100644 --- a/include/cru/ui/components/Input.h +++ b/include/cru/ui/components/Input.h @@ -9,7 +9,7 @@ struct CRU_UI_API InputValidateResult { }; struct CRU_UI_API IInputValidator : public virtual Interface { - virtual InputValidateResult Validate(std::string_view text) const = 0; + virtual InputValidateResult Validate(std::string_view text) = 0; }; struct CRU_UI_API InputChangeEventArgs { @@ -26,14 +26,14 @@ class CRU_UI_API Input : public Component { public: controls::Control* GetRootControl() override; - std::string GetText() const; + std::string GetText(); void SetText(std::string text); - IInputValidator* GetValidator() const; + IInputValidator* GetValidator(); void SetValidator(IInputValidator* validator); InputValidateResult Validate(); - InputValidateResult GetLastValidateResult() const; + InputValidateResult GetLastValidateResult(); IEvent<InputChangeEventArgs>* ChangeEvent() { return &change_event_; } @@ -48,7 +48,7 @@ class CRU_UI_API Input : public Component { class CRU_UI_API FloatInputValidator : public Object, public virtual IInputValidator { public: - InputValidateResult Validate(std::string_view text) const override; + InputValidateResult Validate(std::string_view text) override; std::optional<float> min; std::optional<float> max; @@ -60,13 +60,13 @@ class CRU_UI_API FloatInput : public Input { ~FloatInput() override; public: - float GetValue() const; + float GetValue(); void SetValue(float value); - std::optional<float> GetMax() const; + std::optional<float> GetMax(); void SetMax(std::optional<float> max); - std::optional<float> GetMin() const; + std::optional<float> GetMin(); void SetMin(std::optional<float> min); private: diff --git a/include/cru/ui/components/Menu.h b/include/cru/ui/components/Menu.h index a8a90ed7..aee23894 100644 --- a/include/cru/ui/components/Menu.h +++ b/include/cru/ui/components/Menu.h @@ -38,7 +38,7 @@ class CRU_UI_API Menu : public Component { public: controls::Control* GetRootControl() override { return &container_; } - Index GetItemCount() const { return static_cast<Index>(items_.size()); } + Index GetItemCount() { return static_cast<Index>(items_.size()); } void AddItem(Component* component) { AddItemAt(component, GetItemCount()); } void AddItemAt(Component* component, Index index); diff --git a/include/cru/ui/components/PopupButton.h b/include/cru/ui/components/PopupButton.h index 0e3d5314..61ac6280 100644 --- a/include/cru/ui/components/PopupButton.h +++ b/include/cru/ui/components/PopupButton.h @@ -18,7 +18,9 @@ class CRU_UI_API PopupMenuTextButton : public Component { ui::controls::Button* GetButton() { return &button_; } std::string GetButtonText() { return button_text_.GetText(); } - void SetButtonText(std::string text) { button_text_.SetText(std::move(text)); } + void SetButtonText(std::string text) { + button_text_.SetText(std::move(text)); + } void SetButtonTextColor(const Color& color) { button_text_.SetTextColor(color); diff --git a/include/cru/ui/components/Select.h b/include/cru/ui/components/Select.h index 9efe9a04..67b18383 100644 --- a/include/cru/ui/components/Select.h +++ b/include/cru/ui/components/Select.h @@ -13,10 +13,10 @@ class CRU_UI_API Select : public Component { public: ui::controls::Control* GetRootControl() override { return &button_; } - std::vector<std::string> GetItems() const { return items_; } + std::vector<std::string> GetItems() { return items_; } void SetItems(std::vector<std::string> items); - Index GetSelectedIndex() const { return selected_index_; } + Index GetSelectedIndex() { return selected_index_; } void SetSelectedIndex(Index index); IEvent<Index>* ItemSelectedEvent() { return &item_selected_event_; } diff --git a/include/cru/ui/controls/Button.h b/include/cru/ui/controls/Button.h index 64b9bba0..80d21d08 100644 --- a/include/cru/ui/controls/Button.h +++ b/include/cru/ui/controls/Button.h @@ -1,25 +1,21 @@ #pragma once -#include "SingleChildControl.h" - #include "../helper/ClickDetector.h" #include "../render/BorderRenderObject.h" #include "IBorderControl.h" #include "IClickableControl.h" -#include "cru/base/Event.h" +#include "SingleChildControl.h" namespace cru::ui::controls { class CRU_UI_API Button : public SingleChildControl<render::BorderRenderObject>, public virtual IClickableControl, public virtual IBorderControl { public: - static constexpr std::string_view kControlType = "Button"; + static constexpr auto kControlName = "Button"; public: Button(); ~Button() override; - std::string GetControlType() const final { return std::string(kControlType); } - public: helper::ClickState GetClickState() override { return click_detector_.GetState(); @@ -29,7 +25,7 @@ class CRU_UI_API Button : public SingleChildControl<render::BorderRenderObject>, return click_detector_.StateChangeEvent(); } - IEvent<const helper::ClickEventArgs&>* ClickEvent() { + IEvent<const helper::ClickEventArgs&>* ClickEvent() override { return click_detector_.ClickEvent(); } diff --git a/include/cru/ui/controls/CheckBox.h b/include/cru/ui/controls/CheckBox.h index 6f4eae2e..2e4685d5 100644 --- a/include/cru/ui/controls/CheckBox.h +++ b/include/cru/ui/controls/CheckBox.h @@ -12,20 +12,16 @@ class CRU_UI_API CheckBox : public Control, public virtual ICheckableControl, public virtual IClickableControl { public: - static constexpr std::string_view kControlType = "CheckBox"; + static constexpr auto kControlName = "CheckBox"; CheckBox(); ~CheckBox() override; - std::string GetControlType() const override { - return std::string(kControlType); + render::RenderObject* GetRenderObject() override { + return &container_render_object_; } - render::RenderObject* GetRenderObject() const override { - return container_render_object_.get(); - } - - bool IsChecked() const override { return checked_; } + bool IsChecked() override { return checked_; } void SetChecked(bool checked) override; void Toggle() { SetChecked(!checked_); } @@ -41,11 +37,15 @@ class CRU_UI_API CheckBox : public Control, return click_detector_.StateChangeEvent(); } + IEvent<const helper::ClickEventArgs&>* ClickEvent() override { + return click_detector_.ClickEvent(); + } + private: - bool checked_ = false; + bool checked_; Event<bool> checked_change_event_; - std::unique_ptr<render::BorderRenderObject> container_render_object_; + render::BorderRenderObject container_render_object_; helper::ClickDetector click_detector_; }; diff --git a/include/cru/ui/controls/Container.h b/include/cru/ui/controls/Container.h index 4fee178d..ba7dbd18 100644 --- a/include/cru/ui/controls/Container.h +++ b/include/cru/ui/controls/Container.h @@ -1,31 +1,26 @@ #pragma once -#include "SingleChildControl.h" - #include "../render/BorderRenderObject.h" #include "IBorderControl.h" +#include "SingleChildControl.h" namespace cru::ui::controls { class CRU_UI_API Container : public SingleChildControl<render::BorderRenderObject>, public virtual IBorderControl { - static constexpr std::string_view kControlType = "Container"; + static constexpr auto kControlName = "Container"; public: Container(); - CRU_DELETE_COPY(Container) - CRU_DELETE_MOVE(Container) - - ~Container() override; public: - bool IsBorderEnabled() const { + bool IsBorderEnabled() { return GetContainerRenderObject()->IsBorderEnabled(); } void SetBorderEnabled(bool enabled) { GetContainerRenderObject()->SetBorderEnabled(enabled); } - std::shared_ptr<platform::graphics::IBrush> GetForegroundBrush() const { + std::shared_ptr<platform::graphics::IBrush> GetForegroundBrush() { return GetContainerRenderObject()->GetForegroundBrush(); } void SetForegroundBrush( @@ -33,7 +28,7 @@ class CRU_UI_API Container GetContainerRenderObject()->SetForegroundBrush(brush); } - std::shared_ptr<platform::graphics::IBrush> GetBackgroundBrush() const { + std::shared_ptr<platform::graphics::IBrush> GetBackgroundBrush() { return GetContainerRenderObject()->GetBackgroundBrush(); } void SetBackgroundBrush( @@ -44,8 +39,5 @@ class CRU_UI_API Container void ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) override { GetContainerRenderObject()->ApplyBorderStyle(style); } - - public: - std::string GetControlType() const final { return std::string(kControlType); } }; } // namespace cru::ui::controls diff --git a/include/cru/ui/controls/Control.h b/include/cru/ui/controls/Control.h index 6a85d25a..544d33e6 100644 --- a/include/cru/ui/controls/Control.h +++ b/include/cru/ui/controls/Control.h @@ -17,9 +17,6 @@ namespace cru::ui::controls { * methods: * - GetControlType() * - GetRenderObject() - * - ForEachChild(const std::function<void(Control*)>& predicate) - * - RemoveChild(Control* child) - * The last two methods are totally for convenient control tree management. */ class CRU_UI_API Control : public Object, public cru::platform::gui::DeleteLaterImpl<Control>, @@ -29,15 +26,14 @@ class CRU_UI_API Control : public Object, CRU_DEFINE_CLASS_LOG_TAG("cru::ui::controls::Control") protected: - Control(); + explicit Control(std::string name); public: ~Control() override; public: - virtual std::string GetControlType() const = 0; - - std::string GetDebugId() const; + std::string GetName(); + std::string GetDebugId(); //*************** region: tree *************** public: @@ -46,6 +42,10 @@ class CRU_UI_API Control : public Object, Control* GetParent(); bool HasAncestor(Control* control); const std::vector<Control*>& GetChildren(); + Index GetChildCount() { return GetChildren().size(); } + Control* GetChildAt(Index index) { return GetChildren()[index]; } + Index IndexOfChild(Control* control); + void RemoveChild(Control* child); void RemoveAllChild(); void RemoveFromParent(); @@ -69,23 +69,21 @@ class CRU_UI_API Control : public Object, void AddChild(Control* control); public: - virtual render::RenderObject* GetRenderObject() const = 0; + virtual render::RenderObject* GetRenderObject() = 0; - virtual render::MeasureSize GetPreferredSize() const { + virtual render::MeasureSize GetPreferredSize() { return GetRenderObject()->GetPreferredSize(); } virtual void SetPreferredSize(const render::MeasureSize& size) { GetRenderObject()->SetPreferredSize(size); } - virtual Thickness GetMargin() const { return GetRenderObject()->GetMargin(); } + virtual Thickness GetMargin() { return GetRenderObject()->GetMargin(); } virtual void SetMargin(const Thickness& margin) { GetRenderObject()->SetMargin(margin); } - virtual Thickness GetPadding() const { - return GetRenderObject()->GetPadding(); - } + virtual Thickness GetPadding() { return GetRenderObject()->GetPadding(); } virtual void SetPadding(const Thickness& padding) { GetRenderObject()->SetPadding(padding); } @@ -123,10 +121,10 @@ class CRU_UI_API Control : public Object, //*************** region: events *************** public: - // Raised when mouse enter the control. Even when the control itself captures - // the mouse, this event is raised as regular. But if mouse is captured by - // another control, the control will not receive any mouse enter event. You - // can use `IsMouseCaptured` to get more info. + // Raised when mouse enter the control. Even when the control itself + // captures the mouse, this event is raised as regular. But if mouse is + // captured by another control, the control will not receive any mouse enter + // event. You can use `IsMouseCaptured` to get more info. CRU_DEFINE_ROUTED_EVENT(MouseEnter, events::MouseEventArgs) // Raised when mouse is leave the control. Even when the control itself @@ -151,11 +149,12 @@ class CRU_UI_API Control : public Object, virtual void OnChildRemoved(Control* control, Index index); private: - ControlHost* host_ = nullptr; - Control* parent_ = nullptr; + std::string name_; + ControlHost* host_; + Control* parent_; std::vector<Control*> children_; - std::shared_ptr<platform::gui::ICursor> cursor_ = nullptr; + std::shared_ptr<platform::gui::ICursor> cursor_; std::shared_ptr<style::StyleRuleSet> style_rule_set_; std::unique_ptr<style::StyleRuleSetBind> style_rule_set_bind_; diff --git a/include/cru/ui/controls/FlexLayout.h b/include/cru/ui/controls/FlexLayout.h index 8940e38e..e5ea0703 100644 --- a/include/cru/ui/controls/FlexLayout.h +++ b/include/cru/ui/controls/FlexLayout.h @@ -13,25 +13,18 @@ using render::FlexMainAlignment; class CRU_UI_API FlexLayout : public LayoutControl<render::FlexLayoutRenderObject> { public: - static constexpr std::string_view kControlType = "FlexLayout"; + static constexpr auto kControlName = "FlexLayout"; public: FlexLayout(); - FlexLayout(const FlexLayout& other) = delete; - FlexLayout(FlexLayout&& other) = delete; - FlexLayout& operator=(const FlexLayout& other) = delete; - FlexLayout& operator=(FlexLayout&& other) = delete; - ~FlexLayout() override; - std::string GetControlType() const final { return std::string(kControlType); } - - FlexMainAlignment GetContentMainAlign() const; + FlexMainAlignment GetContentMainAlign(); void SetContentMainAlign(FlexMainAlignment value); - FlexDirection GetFlexDirection() const; + FlexDirection GetFlexDirection(); void SetFlexDirection(FlexDirection direction); - FlexCrossAlignment GetItemCrossAlign() const; + FlexCrossAlignment GetItemCrossAlign(); void SetItemCrossAlign(FlexCrossAlignment alignment); }; } // namespace cru::ui::controls diff --git a/include/cru/ui/controls/ICheckableControl.h b/include/cru/ui/controls/ICheckableControl.h index 7a6d7b8e..b58a3f8c 100644 --- a/include/cru/ui/controls/ICheckableControl.h +++ b/include/cru/ui/controls/ICheckableControl.h @@ -4,7 +4,7 @@ namespace cru::ui::controls { struct CRU_UI_API ICheckableControl : virtual Interface { - virtual bool IsChecked() const = 0; + virtual bool IsChecked() = 0; virtual void SetChecked(bool checked) = 0; virtual IEvent<bool>* CheckedChangeEvent() = 0; }; diff --git a/include/cru/ui/controls/IClickableControl.h b/include/cru/ui/controls/IClickableControl.h index 4ddea730..1cf29f84 100644 --- a/include/cru/ui/controls/IClickableControl.h +++ b/include/cru/ui/controls/IClickableControl.h @@ -7,5 +7,6 @@ namespace cru::ui::controls { struct CRU_UI_API IClickableControl : virtual Interface { virtual helper::ClickState GetClickState() = 0; virtual IEvent<helper::ClickState>* ClickStateChangeEvent() = 0; + virtual IEvent<const helper::ClickEventArgs&>* ClickEvent() = 0; }; } // namespace cru::ui::controls diff --git a/include/cru/ui/controls/IContentBrushControl.h b/include/cru/ui/controls/IContentBrushControl.h index d7a4c1b8..1c872e7a 100644 --- a/include/cru/ui/controls/IContentBrushControl.h +++ b/include/cru/ui/controls/IContentBrushControl.h @@ -4,8 +4,7 @@ namespace cru::ui::controls { struct CRU_UI_API IContentBrushControl : virtual Interface { - virtual std::shared_ptr<platform::graphics::IBrush> GetContentBrush() - const = 0; + virtual std::shared_ptr<platform::graphics::IBrush> GetContentBrush() = 0; virtual void SetContentBrush( std::shared_ptr<platform::graphics::IBrush> brush) = 0; }; diff --git a/include/cru/ui/controls/IFontControl.h b/include/cru/ui/controls/IFontControl.h index 4167de27..33a3f954 100644 --- a/include/cru/ui/controls/IFontControl.h +++ b/include/cru/ui/controls/IFontControl.h @@ -1,10 +1,11 @@ #pragma once #include "../Base.h" -#include "cru/platform/graphics/Font.h" + +#include <cru/platform/graphics/Font.h> namespace cru::ui::controls { struct CRU_UI_API IFontControl : virtual Interface { - virtual std::shared_ptr<platform::graphics::IFont> GetFont() const = 0; + virtual std::shared_ptr<platform::graphics::IFont> GetFont() = 0; virtual void SetFont(std::shared_ptr<platform::graphics::IFont> font) = 0; }; } // namespace cru::ui::controls diff --git a/include/cru/ui/controls/IconButton.h b/include/cru/ui/controls/IconButton.h index 0bbda327..b061bc87 100644 --- a/include/cru/ui/controls/IconButton.h +++ b/include/cru/ui/controls/IconButton.h @@ -16,17 +16,15 @@ class CRU_UI_API IconButton : public Control, public virtual IBorderControl, public virtual IContentBrushControl { public: - static constexpr std::string_view kControlType = "IconButton"; + static constexpr auto kControlName = "IconButton"; public: IconButton(); IconButton(std::string_view icon_svg_path_data_string, const Rect& view_port); ~IconButton() override; - std::string GetControlType() const final { return std::string(kControlType); } - - render::RenderObject* GetRenderObject() const override { - return container_render_object_.get(); + render::RenderObject* GetRenderObject() override { + return &container_render_object_; } public: @@ -38,48 +36,46 @@ class CRU_UI_API IconButton : public Control, return click_detector_.StateChangeEvent(); } - IEvent<const helper::ClickEventArgs&>* ClickEvent() { + IEvent<const helper::ClickEventArgs&>* ClickEvent() override { return click_detector_.ClickEvent(); } void ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) override { - container_render_object_->ApplyBorderStyle(style); + container_render_object_.ApplyBorderStyle(style); } - std::shared_ptr<platform::graphics::IGeometry> GetIconGeometry() const { - return geometry_render_object_->GetGeometry(); + std::shared_ptr<platform::graphics::IGeometry> GetIconGeometry() { + return geometry_render_object_.GetGeometry(); } void SetIconGeometry(std::shared_ptr<platform::graphics::IGeometry> geometry, std::optional<Rect> view_port = std::nullopt) { - geometry_render_object_->SetGeometry(std::move(geometry), view_port); + geometry_render_object_.SetGeometry(std::move(geometry), view_port); } - Rect GetIconViewPort() const { - return geometry_render_object_->GetViewPort(); - } + Rect GetIconViewPort() { return geometry_render_object_.GetViewPort(); } void SetIconViewPort(const Rect& view_port) { - geometry_render_object_->SetViewPort(view_port); + geometry_render_object_.SetViewPort(view_port); } - std::shared_ptr<platform::graphics::IBrush> GetIconFillBrush() const { - return geometry_render_object_->GetFillBrush(); + std::shared_ptr<platform::graphics::IBrush> GetIconFillBrush() { + return geometry_render_object_.GetFillBrush(); } void SetIconFillBrush(std::shared_ptr<platform::graphics::IBrush> brush) { - geometry_render_object_->SetFillBrush(std::move(brush)); + geometry_render_object_.SetFillBrush(std::move(brush)); } - std::shared_ptr<platform::graphics::IBrush> GetIconStrokeBrush() const { - return geometry_render_object_->GetStrokeBrush(); + std::shared_ptr<platform::graphics::IBrush> GetIconStrokeBrush() { + return geometry_render_object_.GetStrokeBrush(); } void SetIconStrokeBrush(std::shared_ptr<platform::graphics::IBrush> brush) { - geometry_render_object_->SetStrokeBrush(std::move(brush)); + geometry_render_object_.SetStrokeBrush(std::move(brush)); } - float GetIconStrokeWidth() const { - return geometry_render_object_->GetStrokeWidth(); + float GetIconStrokeWidth() { + return geometry_render_object_.GetStrokeWidth(); } void SetIconStrokeWidth(float width) { - geometry_render_object_->SetStrokeWidth(width); + geometry_render_object_.SetStrokeWidth(width); } void SetIconFillColor(const Color& color); @@ -89,7 +85,7 @@ class CRU_UI_API IconButton : public Control, std::string_view icon_svg_path_data_string_resource_key, const Rect& view_port); - std::shared_ptr<platform::graphics::IBrush> GetContentBrush() const override { + std::shared_ptr<platform::graphics::IBrush> GetContentBrush() override { return GetIconFillBrush(); } @@ -99,8 +95,8 @@ class CRU_UI_API IconButton : public Control, } private: - std::unique_ptr<render::BorderRenderObject> container_render_object_; - std::unique_ptr<render::GeometryRenderObject> geometry_render_object_; + render::BorderRenderObject container_render_object_; + render::GeometryRenderObject geometry_render_object_; helper::ClickDetector click_detector_; }; } // namespace cru::ui::controls diff --git a/include/cru/ui/controls/LayoutControl.h b/include/cru/ui/controls/LayoutControl.h index fad86530..866a8c03 100644 --- a/include/cru/ui/controls/LayoutControl.h +++ b/include/cru/ui/controls/LayoutControl.h @@ -5,8 +5,8 @@ namespace cru::ui::controls { template <typename TRenderObject> class LayoutControl : public Control { protected: - LayoutControl() : container_render_object_(new TRenderObject()) { - container_render_object_->SetAttachedControl(this); + LayoutControl(std::string name) : Control(std::move(name)) { + container_render_object_.SetAttachedControl(this); } public: @@ -14,47 +14,34 @@ class LayoutControl : public Control { using Control::InsertChildAt; using Control::RemoveChildAt; - Index GetChildCount() const { return children_.size(); } - Control* GetChildAt(Index index) const { return children_[index]; } - - Index IndexOfChild(Control* control) const { - auto it = std::find(children_.begin(), children_.end(), control); - if (it == children_.end()) { - return -1; - } - return it - children_.begin(); - } - - render::RenderObject* GetRenderObject() const override { - return container_render_object_.get(); + render::RenderObject* GetRenderObject() override { + return &container_render_object_; } - TRenderObject* GetContainerRenderObject() const { - return container_render_object_.get(); + TRenderObject* GetContainerRenderObject() { + return &container_render_object_; } const typename TRenderObject::ChildLayoutData& GetChildLayoutData( Index position) { - return container_render_object_->GetChildLayoutDataAt(position); + return container_render_object_.GetChildLayoutDataAt(position); } void SetChildLayoutData(Index position, typename TRenderObject::ChildLayoutData data) { - container_render_object_->SetChildLayoutDataAt(position, data); + container_render_object_.SetChildLayoutDataAt(position, data); } protected: void OnChildInserted(Control* control, Index index) override { - container_render_object_->AddChild(control->GetRenderObject(), index); + container_render_object_.AddChild(control->GetRenderObject(), index); } void OnChildRemoved([[maybe_unused]] Control* control, Index index) override { - container_render_object_->RemoveChild(index); + container_render_object_.RemoveChild(index); } private: - std::unique_ptr<TRenderObject> container_render_object_; - - std::vector<Control*> children_; + TRenderObject container_render_object_; }; } // namespace cru::ui::controls diff --git a/include/cru/ui/controls/ScrollView.h b/include/cru/ui/controls/ScrollView.h index cefda747..181f4ba5 100644 --- a/include/cru/ui/controls/ScrollView.h +++ b/include/cru/ui/controls/ScrollView.h @@ -1,20 +1,13 @@ #pragma once #include "SingleChildControl.h" - #include "cru/ui/render/ScrollRenderObject.h" namespace cru::ui::controls { class CRU_UI_API ScrollView : public SingleChildControl<render::ScrollRenderObject> { public: - static constexpr std::string_view kControlType = "ScrollView"; + static constexpr auto kControlName = "ScrollView"; ScrollView(); - CRU_DELETE_COPY(ScrollView) - CRU_DELETE_MOVE(ScrollView) - ~ScrollView() override; - - public: - std::string GetControlType() const override { return std::string(kControlType); } }; } // namespace cru::ui::controls diff --git a/include/cru/ui/controls/SingleChildControl.h b/include/cru/ui/controls/SingleChildControl.h index f748a38d..684b8403 100644 --- a/include/cru/ui/controls/SingleChildControl.h +++ b/include/cru/ui/controls/SingleChildControl.h @@ -1,41 +1,46 @@ #pragma once #include "Control.h" +#include <cassert> + namespace cru::ui::controls { template <typename TRenderObject> class SingleChildControl : public Control { protected: - SingleChildControl() : container_render_object_(new TRenderObject()) { - container_render_object_->SetAttachedControl(this); + SingleChildControl(std::string name) : Control(std::move(name)) { + container_render_object_.SetAttachedControl(this); } public: Control* GetChild() { - return GetChildren().empty() ? nullptr : GetChildren().front(); + const auto& children = GetChildren(); + assert(children.empty() || children.size() == 1); + return children.empty() ? nullptr : children.front(); } void SetChild(Control* child) { - if (GetChild() == child) return; - if (!GetChildren().empty()) { + auto old_child = GetChild(); + if (old_child == child) return; + if (old_child) { RemoveChildAt(0); } if (child) { InsertChildAt(child, 0); } - container_render_object_->SetChild( - child == nullptr ? nullptr : child->GetRenderObject()); + container_render_object_.SetChild(child ? child->GetRenderObject() + : nullptr); } - render::RenderObject* GetRenderObject() const override { - return container_render_object_.get(); + render::RenderObject* GetRenderObject() override { + return &container_render_object_; } - TRenderObject* GetContainerRenderObject() const { - return container_render_object_.get(); + TRenderObject* GetContainerRenderObject() { + return &container_render_object_; } private: - std::unique_ptr<TRenderObject> container_render_object_; + TRenderObject container_render_object_; }; } // namespace cru::ui::controls diff --git a/include/cru/ui/controls/StackLayout.h b/include/cru/ui/controls/StackLayout.h index db646807..455a99be 100644 --- a/include/cru/ui/controls/StackLayout.h +++ b/include/cru/ui/controls/StackLayout.h @@ -1,6 +1,5 @@ #pragma once #include "LayoutControl.h" - #include "../render/StackLayoutRenderObject.h" namespace cru::ui::controls { @@ -9,13 +8,8 @@ using render::StackChildLayoutData; class CRU_UI_API StackLayout : public LayoutControl<render::StackLayoutRenderObject> { public: - static constexpr std::string_view kControlType = "StackLayout"; + static constexpr auto kControlName = "StackLayout"; StackLayout(); - CRU_DELETE_COPY(StackLayout) - CRU_DELETE_MOVE(StackLayout) - ~StackLayout() override; - - std::string GetControlType() const final { return std::string(kControlType); } }; } // namespace cru::ui::controls diff --git a/include/cru/ui/controls/TextBlock.h b/include/cru/ui/controls/TextBlock.h index af9865c4..9b8875e6 100644 --- a/include/cru/ui/controls/TextBlock.h +++ b/include/cru/ui/controls/TextBlock.h @@ -1,6 +1,6 @@ #pragma once -#include "Control.h" #include "../render/TextRenderObject.h" +#include "Control.h" #include "IContentBrushControl.h" #include "IFontControl.h" #include "TextHostControlService.h" @@ -14,7 +14,7 @@ class CRU_UI_API TextBlock : public Control, public virtual IFontControl, public virtual IContentBrushControl { public: - static constexpr std::string_view kControlType = "TextBlock"; + static constexpr auto kControlName = "TextBlock"; static std::unique_ptr<TextBlock> Create(std::string text, bool selectable = false) { @@ -26,23 +26,16 @@ class CRU_UI_API TextBlock : public Control, public: TextBlock(); - TextBlock(const TextBlock& other) = delete; - TextBlock(TextBlock&& other) = delete; - TextBlock& operator=(const TextBlock& other) = delete; - TextBlock& operator=(TextBlock&& other) = delete; - ~TextBlock() override; - std::string GetControlType() const final { return std::string(kControlType); } + render::RenderObject* GetRenderObject() override; - render::RenderObject* GetRenderObject() const override; - - std::string GetText() const; + std::string GetText(); void SetText(std::string text); - bool IsSelectable() const; + bool IsSelectable(); void SetSelectable(bool value); - std::shared_ptr<platform::graphics::IBrush> GetTextBrush() const { + std::shared_ptr<platform::graphics::IBrush> GetTextBrush() { return text_render_object_->GetBrush(); } void SetTextBrush(std::shared_ptr<platform::graphics::IBrush> brush) { @@ -55,14 +48,14 @@ class CRU_UI_API TextBlock : public Control, return nullptr; } - std::shared_ptr<platform::graphics::IFont> GetFont() const override { + std::shared_ptr<platform::graphics::IFont> GetFont() override { return text_render_object_->GetFont(); } void SetFont(std::shared_ptr<platform::graphics::IFont> font) override { text_render_object_->SetFont(std::move(font)); } - std::shared_ptr<platform::graphics::IBrush> GetContentBrush() const override { + std::shared_ptr<platform::graphics::IBrush> GetContentBrush() override { return GetTextBrush(); } @@ -73,7 +66,6 @@ class CRU_UI_API TextBlock : public Control, private: std::unique_ptr<render::TextRenderObject> text_render_object_; - std::unique_ptr<TextHostControlService> service_; }; } // namespace cru::ui::controls diff --git a/include/cru/ui/controls/TextBox.h b/include/cru/ui/controls/TextBox.h index 4c6ef384..7b3ab323 100644 --- a/include/cru/ui/controls/TextBox.h +++ b/include/cru/ui/controls/TextBox.h @@ -1,5 +1,6 @@ #pragma once #include "../render/BorderRenderObject.h" +#include "../render/ScrollRenderObject.h" #include "../render/TextRenderObject.h" #include "Control.h" #include "IBorderControl.h" @@ -18,48 +19,43 @@ class CRU_UI_API TextBox : public Control, public virtual IContentBrushControl, public virtual IFontControl { public: - static constexpr std::string_view control_type = "TextBox"; + static constexpr auto kControlName = "TextBox"; TextBox(); - CRU_DELETE_COPY(TextBox) - CRU_DELETE_MOVE(TextBox) - ~TextBox() override; - std::string GetControlType() const final { return std::string(control_type); } - - render::RenderObject* GetRenderObject() const override; + render::RenderObject* GetRenderObject() override; render::TextRenderObject* GetTextRenderObject() override; render::ScrollRenderObject* GetScrollRenderObject() override; - bool GetMultiLine() const; + bool GetMultiLine(); void SetMultiLine(bool value); void ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) override; - std::string GetText() const { return service_->GetText(); } - std::string_view GetTextView() const { return service_->GetTextView(); } + std::string GetText() { return service_->GetText(); } + std::string_view GetTextView() { return service_->GetTextView(); } void SetText(std::string text) { service_->SetText(std::move(text)); } IEvent<std::nullptr_t>* TextChangeEvent() { return service_->TextChangeEvent(); } - std::shared_ptr<platform::graphics::IFont> GetFont() const override { + std::shared_ptr<platform::graphics::IFont> GetFont() override { return text_render_object_->GetFont(); } void SetFont(std::shared_ptr<platform::graphics::IFont> font) override { text_render_object_->SetFont(std::move(font)); } - std::shared_ptr<platform::graphics::IBrush> GetTextBrush() const { + std::shared_ptr<platform::graphics::IBrush> GetTextBrush() { return text_render_object_->GetBrush(); } void SetTextBrush(std::shared_ptr<platform::graphics::IBrush> brush) { text_render_object_->SetBrush(std::move(brush)); } - std::shared_ptr<platform::graphics::IBrush> GetContentBrush() const override { + std::shared_ptr<platform::graphics::IBrush> GetContentBrush() override { return GetTextBrush(); } diff --git a/include/cru/ui/controls/TreeView.h b/include/cru/ui/controls/TreeView.h index 62b1c69b..08b62c1a 100644 --- a/include/cru/ui/controls/TreeView.h +++ b/include/cru/ui/controls/TreeView.h @@ -54,17 +54,11 @@ class CRU_UI_API TreeView : public Control { using Control::AddChild; public: - constexpr static std::string_view kControlType = "TreeView"; + constexpr static auto kControlType = "TreeView"; TreeView(); - CRU_DELETE_COPY(TreeView) - CRU_DELETE_MOVE(TreeView) - ~TreeView() override; - std::string GetControlType() const override { - return std::string(kControlType); - } - render::TreeRenderObject* GetRenderObject() { return &render_object_; } + render::TreeRenderObject* GetRenderObject() override { return &render_object_; } TreeViewItem* GetRootItem() { return &root_item_; } diff --git a/include/cru/ui/controls/Window.h b/include/cru/ui/controls/Window.h index 3d3ff0b0..2c650c41 100644 --- a/include/cru/ui/controls/Window.h +++ b/include/cru/ui/controls/Window.h @@ -19,14 +19,12 @@ class CRU_UI_API Window friend Control; public: - static constexpr std::string_view kControlType = "Window"; + static constexpr auto kControlName = "Window"; Window(); static Window* CreatePopup(); - std::string GetControlType() const override; - void SetAttachedControl(Control* control); platform::gui::INativeWindow* GetNativeWindow(); diff --git a/src/ThemeBuilder/components/HeadBodyEditor.h b/src/ThemeBuilder/components/HeadBodyEditor.h index c8671841..1337bd4d 100644 --- a/src/ThemeBuilder/components/HeadBodyEditor.h +++ b/src/ThemeBuilder/components/HeadBodyEditor.h @@ -1,14 +1,13 @@ #pragma once #include "Editor.h" +#include "LabeledMixin.h" #include "cru/base/Event.h" #include "cru/ui/controls/Container.h" #include "cru/ui/controls/FlexLayout.h" #include "cru/ui/controls/IconButton.h" -#include "cru/ui/controls/TextBlock.h" -#include "cru/ui/style/Styler.h" namespace cru::theme_builder::components { -class HeadBodyEditor : public Editor { +class HeadBodyEditor : public Editor, public LabeledMixin { public: HeadBodyEditor(); ~HeadBodyEditor() override; @@ -19,16 +18,12 @@ class HeadBodyEditor : public Editor { ui::controls::FlexLayout* GetContainer() { return &container_; } ui::controls::FlexLayout* GetHeadContainer() { return &head_container_; } - std::string GetLabel() const { return label_.GetText(); } - void SetLabel(std::string label) { label_.SetText(std::move(label)); } - IEvent<std::nullptr_t>* RemoveEvent() { return &remove_event_; } private: ui::controls::Container border_; ui::controls::FlexLayout container_; ui::controls::FlexLayout head_container_; - ui::controls::TextBlock label_; ui::controls::IconButton remove_button_; Event<std::nullptr_t> remove_event_; diff --git a/src/ThemeBuilder/components/LabeledMixin.h b/src/ThemeBuilder/components/LabeledMixin.h new file mode 100644 index 00000000..867bb4ad --- /dev/null +++ b/src/ThemeBuilder/components/LabeledMixin.h @@ -0,0 +1,13 @@ +#pragma once +#include "cru/ui/controls/TextBlock.h" + +namespace cru::theme_builder { +class LabeledMixin { + public: + std::string GetLabel() { return label_.GetText(); } + void SetLabel(std::string label) { label_.SetText(std::move(label)); } + + protected: + ui::controls::TextBlock label_; +}; +} // namespace cru::theme_builder diff --git a/src/ThemeBuilder/components/conditions/CheckedConditionEditor.cpp b/src/ThemeBuilder/components/conditions/CheckedConditionEditor.cpp index e207c761..b45006db 100644 --- a/src/ThemeBuilder/components/conditions/CheckedConditionEditor.cpp +++ b/src/ThemeBuilder/components/conditions/CheckedConditionEditor.cpp @@ -14,8 +14,7 @@ CheckedConditionEditor::CheckedConditionEditor() { CheckedConditionEditor::~CheckedConditionEditor() {} -ClonePtr<ui::style::CheckedCondition> CheckedConditionEditor::GetValue() - const { +ClonePtr<ui::style::CheckedCondition> CheckedConditionEditor::GetValue() { return ui::style::CheckedCondition::Create(checked_check_box_.GetValue()); } diff --git a/src/ThemeBuilder/components/conditions/CheckedConditionEditor.h b/src/ThemeBuilder/components/conditions/CheckedConditionEditor.h index c83a1cff..6fc6f97f 100644 --- a/src/ThemeBuilder/components/conditions/CheckedConditionEditor.h +++ b/src/ThemeBuilder/components/conditions/CheckedConditionEditor.h @@ -11,16 +11,14 @@ class CheckedConditionEditor : public ConditionEditor { ~CheckedConditionEditor() override; public: - ClonePtr<ui::style::CheckedCondition> GetValue() const; + ClonePtr<ui::style::CheckedCondition> GetValue(); void SetValue(ui::style::CheckedCondition* value, bool trigger_change = true); void SetValue(const ClonePtr<ui::style::CheckedCondition>& value, bool trigger_change = true) { SetValue(value.get(), trigger_change); } - ClonePtr<ui::style::Condition> GetCondition() override { - return GetValue(); - } + ClonePtr<ui::style::Condition> GetCondition() override { return GetValue(); } private: properties::CheckBoxPropertyEditor checked_check_box_; diff --git a/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.cpp b/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.cpp index 24e83a0e..4862fd47 100644 --- a/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.cpp +++ b/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.cpp @@ -55,8 +55,7 @@ ClickStateConditionEditor::ClickStateConditionEditor() { ClickStateConditionEditor::~ClickStateConditionEditor() {} -ClonePtr<ui::style::ClickStateCondition> -ClickStateConditionEditor::GetValue() const { +ClonePtr<ui::style::ClickStateCondition> ClickStateConditionEditor::GetValue() { return ui::style::ClickStateCondition::Create( ConvertIndexToClickState(click_state_select_.GetSelectedIndex())); } diff --git a/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.h b/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.h index 24d60f7b..6929732c 100644 --- a/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.h +++ b/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.h @@ -2,7 +2,6 @@ #include "../properties/SelectPropertyEditor.h" #include "ConditionEditor.h" #include "cru/base/ClonePtr.h" -#include "cru/base/Event.h" #include "cru/ui/style/Condition.h" namespace cru::theme_builder::components::conditions { @@ -12,7 +11,7 @@ class ClickStateConditionEditor : public ConditionEditor { ~ClickStateConditionEditor(); public: - ClonePtr<ui::style::ClickStateCondition> GetValue() const; + ClonePtr<ui::style::ClickStateCondition> GetValue(); void SetValue(ui::style::ClickStateCondition* value, bool trigger_change = true); void SetValue(const ClonePtr<ui::style::ClickStateCondition>& value, @@ -20,9 +19,7 @@ class ClickStateConditionEditor : public ConditionEditor { SetValue(value.get(), trigger_change); } - ClonePtr<ui::style::Condition> GetCondition() override { - return GetValue(); - } + ClonePtr<ui::style::Condition> GetCondition() override { return GetValue(); } private: properties::SelectPropertyEditor click_state_select_; diff --git a/src/ThemeBuilder/components/conditions/CompoundConditionEditor.h b/src/ThemeBuilder/components/conditions/CompoundConditionEditor.h index c0f0891a..6c1beeac 100644 --- a/src/ThemeBuilder/components/conditions/CompoundConditionEditor.h +++ b/src/ThemeBuilder/components/conditions/CompoundConditionEditor.h @@ -1,12 +1,8 @@ #pragma once #include "ConditionEditor.h" #include "cru/base/ClonePtr.h" -#include "cru/base/Event.h" -#include "cru/ui/components/Component.h" #include "cru/ui/components/PopupButton.h" -#include "cru/ui/controls/Button.h" #include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/TextBlock.h" #include "cru/ui/style/Condition.h" namespace cru::theme_builder::components::conditions { @@ -28,10 +24,6 @@ class CompoundConditionEditor : public ConditionEditor { class AndConditionEditor : public CompoundConditionEditor { public: - AndConditionEditor() = default; - ~AndConditionEditor() override = default; - - public: ClonePtr<ui::style::AndCondition> GetValue() { return ui::style::AndCondition::Create(GetChildren()); } @@ -50,10 +42,6 @@ class AndConditionEditor : public CompoundConditionEditor { class OrConditionEditor : public CompoundConditionEditor { public: - OrConditionEditor() = default; - ~OrConditionEditor() override = default; - - public: ClonePtr<ui::style::OrCondition> GetValue() { return ui::style::OrCondition::Create(GetChildren()); } diff --git a/src/ThemeBuilder/components/conditions/FocusConditionEditor.cpp b/src/ThemeBuilder/components/conditions/FocusConditionEditor.cpp index 67a660d1..356f42ef 100644 --- a/src/ThemeBuilder/components/conditions/FocusConditionEditor.cpp +++ b/src/ThemeBuilder/components/conditions/FocusConditionEditor.cpp @@ -14,7 +14,7 @@ FocusConditionEditor::FocusConditionEditor() { FocusConditionEditor::~FocusConditionEditor() {} -ClonePtr<ui::style::FocusCondition> FocusConditionEditor::GetValue() const { +ClonePtr<ui::style::FocusCondition> FocusConditionEditor::GetValue() { return ui::style::FocusCondition::Create(focus_check_box_.GetValue()); } diff --git a/src/ThemeBuilder/components/conditions/FocusConditionEditor.h b/src/ThemeBuilder/components/conditions/FocusConditionEditor.h index c9c8018e..1cfb883f 100644 --- a/src/ThemeBuilder/components/conditions/FocusConditionEditor.h +++ b/src/ThemeBuilder/components/conditions/FocusConditionEditor.h @@ -11,16 +11,14 @@ class FocusConditionEditor : public ConditionEditor { ~FocusConditionEditor() override; public: - ClonePtr<ui::style::FocusCondition> GetValue() const; + ClonePtr<ui::style::FocusCondition> GetValue(); void SetValue(ui::style::FocusCondition* value, bool trigger_change = true); void SetValue(const ClonePtr<ui::style::FocusCondition>& value, bool trigger_change = true) { SetValue(value.get(), trigger_change); } - ClonePtr<ui::style::Condition> GetCondition() override { - return GetValue(); - } + ClonePtr<ui::style::Condition> GetCondition() override { return GetValue(); } private: properties::CheckBoxPropertyEditor focus_check_box_; diff --git a/src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.h b/src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.h index 8cdd541b..8673a285 100644 --- a/src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.h +++ b/src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.h @@ -1,11 +1,11 @@ #pragma once #include "../Editor.h" +#include "../LabeledMixin.h" #include "cru/ui/controls/CheckBox.h" #include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/TextBlock.h" namespace cru::theme_builder::components::properties { -class CheckBoxPropertyEditor : public Editor { +class CheckBoxPropertyEditor : public Editor, public LabeledMixin { public: using PropertyType = bool; @@ -15,15 +15,11 @@ class CheckBoxPropertyEditor : public Editor { public: ui::controls::Control* GetRootControl() override { return &container_; } - std::string GetLabel() const { return label_.GetText(); } - void SetLabel(std::string label) { label_.SetText(std::move(label)); } - - bool GetValue() const { return check_box_.IsChecked(); } + bool GetValue() { return check_box_.IsChecked(); } void SetValue(bool value, bool trigger_change = true); private: ui::controls::FlexLayout container_; - ui::controls::TextBlock label_; ui::controls::CheckBox check_box_; }; } // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/ColorPropertyEditor.h b/src/ThemeBuilder/components/properties/ColorPropertyEditor.h index 7c76297b..a0f784e9 100644 --- a/src/ThemeBuilder/components/properties/ColorPropertyEditor.h +++ b/src/ThemeBuilder/components/properties/ColorPropertyEditor.h @@ -1,13 +1,13 @@ #pragma once #include "../Editor.h" +#include "../LabeledMixin.h" #include "cru/platform/graphics/Base.h" #include "cru/ui/controls/Container.h" #include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/TextBlock.h" #include "cru/ui/controls/TextBox.h" namespace cru::theme_builder::components::properties { -class ColorPropertyEditor : public Editor { +class ColorPropertyEditor : public Editor, public LabeledMixin { public: using PropertyType = ui::Color; @@ -17,17 +17,13 @@ class ColorPropertyEditor : public Editor { public: ui::controls::Control* GetRootControl() override { return &container_; } - std::string GetLabel() const { return label_.GetText(); } - void SetLabel(std::string label) { label_.SetText(std::move(label)); } - - ui::Color GetValue() const { return color_; } + ui::Color GetValue() { return color_; } void SetValue(const ui::Color& color, bool trigger_change = true); private: ui::Color color_ = ui::colors::transparent; ui::controls::FlexLayout container_; - ui::controls::TextBlock label_; ui::controls::Container color_cube_; std::shared_ptr<platform::graphics::ISolidColorBrush> color_cube_brush_; ui::controls::TextBox color_text_; diff --git a/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.cpp b/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.cpp index 47a51ddd..5b50ad38 100644 --- a/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.cpp +++ b/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.cpp @@ -25,7 +25,7 @@ CornerRadiusPropertyEditor::CornerRadiusPropertyEditor() { CornerRadiusPropertyEditor::~CornerRadiusPropertyEditor() {} -ui::CornerRadius CornerRadiusPropertyEditor::GetValue() const { +ui::CornerRadius CornerRadiusPropertyEditor::GetValue() { return ui::CornerRadius( left_top_editor_.GetValue(), right_top_editor_.GetValue(), left_bottom_editor_.GetValue(), right_bottom_editor_.GetValue()); diff --git a/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.h b/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.h index 6b6833d1..376a2f30 100644 --- a/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.h +++ b/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.h @@ -14,7 +14,7 @@ class CornerRadiusPropertyEditor : public Editor { ui::controls::Control* GetRootControl() override { return &container_; } - ui::CornerRadius GetValue() const; + ui::CornerRadius GetValue(); void SetValue(const ui::CornerRadius& corner_radius, bool trigger_change = true); diff --git a/src/ThemeBuilder/components/properties/FontPropertyEditor.cpp b/src/ThemeBuilder/components/properties/FontPropertyEditor.cpp index 231e45dd..1024f446 100644 --- a/src/ThemeBuilder/components/properties/FontPropertyEditor.cpp +++ b/src/ThemeBuilder/components/properties/FontPropertyEditor.cpp @@ -3,7 +3,6 @@ #include "cru/platform/graphics/Font.h" #include "cru/platform/gui/UiApplication.h" #include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/render/FlexLayoutRenderObject.h" namespace cru::theme_builder::components::properties { using namespace cru::ui::controls; @@ -39,8 +38,7 @@ FontPropertyEditor::~FontPropertyEditor() {} Control* FontPropertyEditor::GetRootControl() { return &main_container_; } -std::shared_ptr<platform::graphics::IFont> FontPropertyEditor::GetValue() - const { +std::shared_ptr<platform::graphics::IFont> FontPropertyEditor::GetValue() { return platform::gui::IUiApplication::GetInstance() ->GetGraphicsFactory() ->CreateFont(font_family_text_.GetText(), font_size_input_.GetValue()); diff --git a/src/ThemeBuilder/components/properties/FontPropertyEditor.h b/src/ThemeBuilder/components/properties/FontPropertyEditor.h index ec6a6b56..4a6c601c 100644 --- a/src/ThemeBuilder/components/properties/FontPropertyEditor.h +++ b/src/ThemeBuilder/components/properties/FontPropertyEditor.h @@ -1,5 +1,6 @@ #pragma once #include "../Editor.h" +#include "../LabeledMixin.h" #include "cru/platform/graphics/Font.h" #include "cru/ui/components/Input.h" #include "cru/ui/controls/Control.h" @@ -8,7 +9,7 @@ #include "cru/ui/controls/TextBox.h" namespace cru::theme_builder::components::properties { -class FontPropertyEditor : public Editor { +class FontPropertyEditor : public Editor, public LabeledMixin { public: using PropertyType = std::shared_ptr<platform::graphics::IFont>; @@ -17,16 +18,12 @@ class FontPropertyEditor : public Editor { ui::controls::Control* GetRootControl() override; - std::string GetLabelText() const { return label_.GetText(); } - void SetLabelText(std::string label) { label_.SetText(std::move(label)); } - - std::shared_ptr<platform::graphics::IFont> GetValue() const; + std::shared_ptr<platform::graphics::IFont> GetValue(); void SetValue(std::shared_ptr<platform::graphics::IFont> value, bool trigger_change = true); private: ui::controls::FlexLayout main_container_; - ui::controls::TextBlock label_; ui::controls::FlexLayout right_container_; ui::controls::FlexLayout font_family_container_; ui::controls::TextBlock font_family_label_; diff --git a/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h b/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h index ee99579f..dd4101bf 100644 --- a/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h +++ b/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h @@ -1,14 +1,12 @@ #pragma once #include "../Editor.h" -#include "cru/platform/graphics/Base.h" -#include "cru/ui/controls/Container.h" +#include "../LabeledMixin.h" #include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/TextBlock.h" #include "cru/ui/controls/TextBox.h" #include "cru/ui/render/MeasureRequirement.h" namespace cru::theme_builder::components::properties { -class MeasureLengthPropertyEditor : public Editor { +class MeasureLengthPropertyEditor : public Editor, public LabeledMixin { public: using PropertyType = ui::render::MeasureLength; @@ -18,9 +16,6 @@ class MeasureLengthPropertyEditor : public Editor { public: ui::controls::Control* GetRootControl() override { return &container_; } - std::string GetLabel() const { return label_.GetText(); } - void SetLabel(std::string label) { label_.SetText(std::move(label)); } - PropertyType GetValue() const { return measure_length_; } void SetValue(const PropertyType& value, bool trigger_change = true); @@ -28,7 +23,6 @@ class MeasureLengthPropertyEditor : public Editor { PropertyType measure_length_; ui::controls::FlexLayout container_; - ui::controls::TextBlock label_; ui::controls::TextBox text_; bool is_text_valid_; }; diff --git a/src/ThemeBuilder/components/properties/OptionalPropertyEditor.h b/src/ThemeBuilder/components/properties/OptionalPropertyEditor.h index 8db14114..b44b3b1b 100644 --- a/src/ThemeBuilder/components/properties/OptionalPropertyEditor.h +++ b/src/ThemeBuilder/components/properties/OptionalPropertyEditor.h @@ -1,14 +1,14 @@ #pragma once #include "../Editor.h" +#include "../LabeledMixin.h" #include "cru/ui/controls/CheckBox.h" #include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/TextBlock.h" #include <optional> namespace cru::theme_builder::components::properties { template <typename TEditor> -class OptionalPropertyEditor : public Editor { +class OptionalPropertyEditor : public Editor, public LabeledMixin { public: using PropertyType = typename TEditor::PropertyType; @@ -28,10 +28,7 @@ class OptionalPropertyEditor : public Editor { ui::controls::Control* GetRootControl() override { return &container_; } - std::string GetLabel() const { return label_.GetText(); } - void SetLabel(std::string label) { label_.SetText(std::move(label)); } - - bool IsEnabled() const { return check_box_.IsChecked(); } + bool IsEnabled() { return check_box_.IsChecked(); } void SetEnabled(bool enabled, bool trigger_change = true) { check_box_.SetChecked(enabled); if (trigger_change) { @@ -39,7 +36,7 @@ class OptionalPropertyEditor : public Editor { } } - std::optional<PropertyType> GetValue() const { + std::optional<PropertyType> GetValue() { return IsEnabled() ? std::optional<PropertyType>(editor_.GetValue()) : std::nullopt; } @@ -58,7 +55,6 @@ class OptionalPropertyEditor : public Editor { private: ui::controls::FlexLayout container_; - ui::controls::TextBlock label_; ui::controls::CheckBox check_box_; TEditor editor_; }; diff --git a/src/ThemeBuilder/components/properties/PointPropertyEditor.cpp b/src/ThemeBuilder/components/properties/PointPropertyEditor.cpp index 82fee18f..51d6892e 100644 --- a/src/ThemeBuilder/components/properties/PointPropertyEditor.cpp +++ b/src/ThemeBuilder/components/properties/PointPropertyEditor.cpp @@ -1,6 +1,5 @@ #include "PointPropertyEditor.h" #include "cru/ui/mapper/MapperRegistry.h" -#include "cru/ui/mapper/PointMapper.h" #include <format> diff --git a/src/ThemeBuilder/components/properties/PointPropertyEditor.h b/src/ThemeBuilder/components/properties/PointPropertyEditor.h index 4f078c8b..299505dd 100644 --- a/src/ThemeBuilder/components/properties/PointPropertyEditor.h +++ b/src/ThemeBuilder/components/properties/PointPropertyEditor.h @@ -1,11 +1,11 @@ #pragma once #include "../Editor.h" +#include "../LabeledMixin.h" #include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/TextBlock.h" #include "cru/ui/controls/TextBox.h" namespace cru::theme_builder::components::properties { -class PointPropertyEditor : public Editor { +class PointPropertyEditor : public Editor, public LabeledMixin { public: using PropertyType = ui::Point; @@ -15,10 +15,7 @@ class PointPropertyEditor : public Editor { public: ui::controls::Control* GetRootControl() override { return &container_; } - std::string GetLabel() const { return label_.GetText(); } - void SetLabel(std::string label) { label_.SetText(std::move(label)); } - - ui::Point GetValue() const { return point_; } + ui::Point GetValue() { return point_; } void SetValue(const ui::Point& point, bool trigger_change = true); private: @@ -28,7 +25,6 @@ class PointPropertyEditor : public Editor { ui::Point point_; ui::controls::FlexLayout container_; - ui::controls::TextBlock label_; ui::controls::TextBox text_; bool is_text_valid_; }; diff --git a/src/ThemeBuilder/components/properties/SelectPropertyEditor.h b/src/ThemeBuilder/components/properties/SelectPropertyEditor.h index 0d6cbfcd..c58c1829 100644 --- a/src/ThemeBuilder/components/properties/SelectPropertyEditor.h +++ b/src/ThemeBuilder/components/properties/SelectPropertyEditor.h @@ -1,11 +1,11 @@ #pragma once #include "../Editor.h" +#include "../LabeledMixin.h" #include "cru/ui/components/Select.h" #include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/TextBlock.h" namespace cru::theme_builder::components::properties { -class SelectPropertyEditor : public Editor { +class SelectPropertyEditor : public Editor, public LabeledMixin { public: using PropertyType = Index; @@ -15,28 +15,24 @@ class SelectPropertyEditor : public Editor { public: ui::controls::Control* GetRootControl() override { return &container_; } - std::string GetLabel() const { return label_.GetText(); } - void SetLabel(std::string label) { label_.SetText(std::move(label)); } - - Index GetSelectedIndex() const { return select_.GetSelectedIndex(); } + Index GetSelectedIndex() { return select_.GetSelectedIndex(); } void SetSelectedIndex(Index index, bool trigger_change = true) { if (trigger_change == false) SuppressNextChangeEvent(); select_.SetSelectedIndex(index); } - std::vector<std::string> GetItems() const { return select_.GetItems(); } + std::vector<std::string> GetItems() { return select_.GetItems(); } void SetItems(std::vector<std::string> items) { select_.SetItems(std::move(items)); } - Index GetValue() const { return GetSelectedIndex(); } + Index GetValue() { return GetSelectedIndex(); } void SetValue(Index value, bool trigger_change = true) { SetSelectedIndex(value, trigger_change); } private: ui::controls::FlexLayout container_; - ui::controls::TextBlock label_; ui::components::Select select_; }; } // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/TextPropertyEditor.h b/src/ThemeBuilder/components/properties/TextPropertyEditor.h index 040f776a..433143cd 100644 --- a/src/ThemeBuilder/components/properties/TextPropertyEditor.h +++ b/src/ThemeBuilder/components/properties/TextPropertyEditor.h @@ -1,22 +1,21 @@ #pragma once +#include "../LabeledMixin.h" #include "cru/ui/components/Component.h" #include "cru/ui/controls/FlexLayout.h" #include "cru/ui/controls/TextBlock.h" #include "cru/ui/controls/TextBox.h" namespace cru::theme_builder::components::properties { -class TextPropertyEditor : public ui::components::Component { +class TextPropertyEditor : public ui::components::Component, + public LabeledMixin { public: TextPropertyEditor(); ~TextPropertyEditor() override; ui::controls::Control* GetRootControl() override { return &container_; } - std::string GetLabel() const { return label_.GetText(); } - void SetLabel(std::string label) { label_.SetText(std::move(label)); } - - std::string GetText() const { return editor_.GetText(); } - std::string_view GetTextView() const { return editor_.GetTextView(); } + std::string GetText() { return editor_.GetText(); } + std::string_view GetTextView() { return editor_.GetTextView(); } void SetText(std::string text) { editor_.SetText(std::move(text)); } protected: diff --git a/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.h b/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.h index dae2e612..106e0e9e 100644 --- a/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.h +++ b/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.h @@ -1,11 +1,11 @@ #pragma once #include "../Editor.h" +#include "../LabeledMixin.h" #include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/TextBlock.h" #include "cru/ui/controls/TextBox.h" namespace cru::theme_builder::components::properties { -class ThicknessPropertyEditor : public Editor { +class ThicknessPropertyEditor : public Editor, public LabeledMixin { public: using PropertyType = ui::Thickness; @@ -14,17 +14,13 @@ class ThicknessPropertyEditor : public Editor { ui::controls::Control* GetRootControl() override { return &container_; } - std::string GetLabel() const { return label_.GetText(); } - void SetLabel(std::string label) { label_.SetText(std::move(label)); } - - ui::Thickness GetValue() const { return thickness_; } + ui::Thickness GetValue() { return thickness_; } void SetValue(const ui::Thickness& thickness, bool trigger_change = true); private: ui::Thickness thickness_; ui::controls::FlexLayout container_; - ui::controls::TextBlock label_; ui::controls::TextBox text_; bool is_text_valid_; }; diff --git a/src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.cpp b/src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.cpp index 00b40d10..98bc14b7 100644 --- a/src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.cpp +++ b/src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.cpp @@ -12,8 +12,7 @@ ContentBrushStylerEditor::ContentBrushStylerEditor() { ContentBrushStylerEditor::~ContentBrushStylerEditor() {} -ClonePtr<ui::style::ContentBrushStyler> ContentBrushStylerEditor::GetValue() - const { +ClonePtr<ui::style::ContentBrushStyler> ContentBrushStylerEditor::GetValue() { return ui::style::ContentBrushStyler::Create( platform::gui::IUiApplication::GetInstance() ->GetGraphicsFactory() diff --git a/src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.h b/src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.h index 91e8adc2..b1b179a1 100644 --- a/src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.h +++ b/src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.h @@ -1,5 +1,4 @@ #pragma once -#include "../Editor.h" #include "../properties/ColorPropertyEditor.h" #include "StylerEditor.h" #include "cru/base/ClonePtr.h" @@ -12,7 +11,7 @@ class ContentBrushStylerEditor : public StylerEditor { ~ContentBrushStylerEditor(); public: - ClonePtr<ui::style::ContentBrushStyler> GetValue() const; + ClonePtr<ui::style::ContentBrushStyler> GetValue(); void SetValue(ui::style::ContentBrushStyler* value, bool trigger_change = true); diff --git a/src/ThemeBuilder/components/stylers/FontStylerEditor.cpp b/src/ThemeBuilder/components/stylers/FontStylerEditor.cpp index c8687e6d..e84a439c 100644 --- a/src/ThemeBuilder/components/stylers/FontStylerEditor.cpp +++ b/src/ThemeBuilder/components/stylers/FontStylerEditor.cpp @@ -1,6 +1,4 @@ #include "FontStylerEditor.h" -#include "cru/platform/graphics/Factory.h" -#include "cru/platform/gui/UiApplication.h" #include "cru/ui/style/Styler.h" namespace cru::theme_builder::components::stylers { @@ -12,7 +10,7 @@ FontStylerEditor::FontStylerEditor() { FontStylerEditor::~FontStylerEditor() {} -ClonePtr<ui::style::FontStyler> FontStylerEditor::GetValue() const { +ClonePtr<ui::style::FontStyler> FontStylerEditor::GetValue() { return ui::style::FontStyler::Create(font_editor_.GetValue()); } diff --git a/src/ThemeBuilder/components/stylers/FontStylerEditor.h b/src/ThemeBuilder/components/stylers/FontStylerEditor.h index a5145e31..11c931d3 100644 --- a/src/ThemeBuilder/components/stylers/FontStylerEditor.h +++ b/src/ThemeBuilder/components/stylers/FontStylerEditor.h @@ -1,5 +1,4 @@ #pragma once -#include "../Editor.h" #include "../properties/FontPropertyEditor.h" #include "StylerEditor.h" #include "cru/base/ClonePtr.h" @@ -12,7 +11,7 @@ class FontStylerEditor : public StylerEditor { ~FontStylerEditor(); public: - ClonePtr<ui::style::FontStyler> GetValue() const; + ClonePtr<ui::style::FontStyler> GetValue(); void SetValue(ui::style::FontStyler* value, bool trigger_change = true); ClonePtr<ui::style::Styler> GetStyler() override { return GetValue(); } diff --git a/src/platform/gui/win/Keyboard.cpp b/src/platform/gui/win/Keyboard.cpp index f4286fbc..29932ff3 100644 --- a/src/platform/gui/win/Keyboard.cpp +++ b/src/platform/gui/win/Keyboard.cpp @@ -64,7 +64,7 @@ KeyCode VirtualKeyToKeyCode(int virtual_key) { } } -KeyModifier RetrieveKeyMofifier() { +KeyModifier RetrieveKeyModifier() { KeyModifier result{0}; if (::GetKeyState(VK_SHIFT) < 0) result |= KeyModifiers::Shift; if (::GetKeyState(VK_CONTROL) < 0) result |= KeyModifiers::Ctrl; diff --git a/src/platform/gui/win/Window.cpp b/src/platform/gui/win/Window.cpp index eb5112f5..2c0bc5a1 100644 --- a/src/platform/gui/win/Window.cpp +++ b/src/platform/gui/win/Window.cpp @@ -585,29 +585,29 @@ void WinNativeWindow::OnMouseLeaveInternal() { void WinNativeWindow::OnMouseDownInternal(platform::gui::MouseButton button, POINT point) { const auto dip_point = PixelToDip(point); - mouse_down_event_.Raise({button, dip_point, RetrieveKeyMofifier()}); + mouse_down_event_.Raise({button, dip_point, RetrieveKeyModifier()}); } void WinNativeWindow::OnMouseUpInternal(platform::gui::MouseButton button, POINT point) { const auto dip_point = PixelToDip(point); - mouse_up_event_.Raise({button, dip_point, RetrieveKeyMofifier()}); + mouse_up_event_.Raise({button, dip_point, RetrieveKeyModifier()}); } void WinNativeWindow::OnMouseWheelInternal(short delta, POINT point) { const auto dip_point = PixelToDip(point); const float d = -((float)delta / 120.f); - mouse_wheel_event_.Raise({d, dip_point, RetrieveKeyMofifier()}); + mouse_wheel_event_.Raise({d, dip_point, RetrieveKeyModifier()}); } void WinNativeWindow::OnKeyDownInternal(int virtual_code) { key_down_event_.Raise( - {VirtualKeyToKeyCode(virtual_code), RetrieveKeyMofifier()}); + {VirtualKeyToKeyCode(virtual_code), RetrieveKeyModifier()}); } void WinNativeWindow::OnKeyUpInternal(int virtual_code) { key_up_event_.Raise( - {VirtualKeyToKeyCode(virtual_code), RetrieveKeyMofifier()}); + {VirtualKeyToKeyCode(virtual_code), RetrieveKeyModifier()}); } void WinNativeWindow::OnActivatedInternal() {} diff --git a/src/ui/components/Input.cpp b/src/ui/components/Input.cpp index 0a14c7b8..770cfc86 100644 --- a/src/ui/components/Input.cpp +++ b/src/ui/components/Input.cpp @@ -19,11 +19,11 @@ Input::~Input() {} controls::Control* Input::GetRootControl() { return &text_box_; } -std::string Input::GetText() const { return text_box_.GetText(); } +std::string Input::GetText() { return text_box_.GetText(); } void Input::SetText(std::string text) { text_box_.SetText(std::move(text)); } -IInputValidator* Input::GetValidator() const { return validator_; } +IInputValidator* Input::GetValidator() { return validator_; } void Input::SetValidator(IInputValidator* validator) { validator_ = validator; @@ -38,11 +38,11 @@ InputValidateResult Input::Validate() { return last_validate_result_; } -InputValidateResult Input::GetLastValidateResult() const { +InputValidateResult Input::GetLastValidateResult() { return last_validate_result_; } -InputValidateResult FloatInputValidator::Validate(std::string_view text) const { +InputValidateResult FloatInputValidator::Validate(std::string_view text) { auto result = cru::string::ParseToNumber<float>( text, cru::string::ParseToNumberFlags::AllowLeadingSpaces | cru::string::ParseToNumberFlags::AllowTrailingSpaces); @@ -77,18 +77,18 @@ FloatInput::FloatInput() { FloatInput::~FloatInput() {} -float FloatInput::GetValue() const { return value_; } +float FloatInput::GetValue() { return value_; } void FloatInput::SetValue(float value) { SetText(std::to_string(value)); } -std::optional<float> FloatInput::GetMin() const { return validator_.min; } +std::optional<float> FloatInput::GetMin() { return validator_.min; } void FloatInput::SetMin(std::optional<float> min) { validator_.min = std::move(min); Validate(); } -std::optional<float> FloatInput::GetMax() const { return validator_.max; } +std::optional<float> FloatInput::GetMax() { return validator_.max; } void FloatInput::SetMax(std::optional<float> max) { validator_.max = std::move(max); diff --git a/src/ui/controls/Button.cpp b/src/ui/controls/Button.cpp index a44a7074..4d897f08 100644 --- a/src/ui/controls/Button.cpp +++ b/src/ui/controls/Button.cpp @@ -1,11 +1,12 @@ #include "cru/ui/controls/Button.h" - #include "cru/ui/ThemeManager.h" #include "cru/ui/helper/ClickDetector.h" #include "cru/ui/render/BorderRenderObject.h" namespace cru::ui::controls { -Button::Button() : click_detector_(this) { +Button::Button() + : SingleChildControl<render::BorderRenderObject>(kControlName), + click_detector_(this) { GetContainerRenderObject()->SetBorderEnabled(true); auto default_button_style = ThemeManager::GetInstance()->GetResourceStyleRuleSet("button.style"); diff --git a/src/ui/controls/CheckBox.cpp b/src/ui/controls/CheckBox.cpp index 778a7b4f..a6cac1a1 100644 --- a/src/ui/controls/CheckBox.cpp +++ b/src/ui/controls/CheckBox.cpp @@ -5,11 +5,10 @@ namespace cru::ui::controls { CheckBox::CheckBox() - : container_render_object_(new render::BorderRenderObject()), - click_detector_(this) { - container_render_object_->SetAttachedControl(this); + : Control(kControlName), checked_(false), click_detector_(this) { + container_render_object_.SetAttachedControl(this); - container_render_object_->SetBorderEnabled(true); + container_render_object_.SetBorderEnabled(true); auto default_checkbox_style = ThemeManager::GetInstance()->GetResourceStyleRuleSet("checkbox.style"); GetStyleRuleSet()->SetParent(std::move(default_checkbox_style)); @@ -26,6 +25,6 @@ void CheckBox::SetChecked(bool checked) { } void CheckBox::ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) { - container_render_object_->ApplyBorderStyle(style); + container_render_object_.ApplyBorderStyle(style); } } // namespace cru::ui::controls diff --git a/src/ui/controls/Container.cpp b/src/ui/controls/Container.cpp index 7b0c10a9..32efa233 100644 --- a/src/ui/controls/Container.cpp +++ b/src/ui/controls/Container.cpp @@ -1,11 +1,7 @@ #include "cru/ui/controls/Container.h" - -#include "cru/platform/graphics/Factory.h" #include "cru/ui/render/BorderRenderObject.h" -#include "cru/ui/render/RenderObject.h" namespace cru::ui::controls { -Container::Container() {} - -Container::~Container() = default; +Container::Container() + : SingleChildControl<render::BorderRenderObject>(kControlName) {} } // namespace cru::ui::controls diff --git a/src/ui/controls/Control.cpp b/src/ui/controls/Control.cpp index 70a3b1f3..41644755 100644 --- a/src/ui/controls/Control.cpp +++ b/src/ui/controls/Control.cpp @@ -14,7 +14,8 @@ using platform::gui::ICursor; using platform::gui::IUiApplication; using platform::gui::SystemCursorType; -Control::Control() { +Control::Control(std::string name) + : name_(std::move(name)), host_(nullptr), parent_(nullptr) { style_rule_set_ = std::make_shared<style::StyleRuleSet>(); style_rule_set_bind_ = std::make_unique<style::StyleRuleSetBind>(this, style_rule_set_); @@ -30,9 +31,10 @@ Control::~Control() { RemoveAllChild(); } -std::string Control::GetDebugId() const { - return std::format("{}({})", GetControlType(), - static_cast<const void*>(this)); +std::string Control::GetName() { return name_; } + +std::string Control::GetDebugId() { + return std::format("{}({})", GetName(), static_cast<const void*>(this)); } ControlHost* Control::GetControlHost() { return host_; } @@ -50,6 +52,15 @@ bool Control::HasAncestor(Control* control) { const std::vector<Control*>& Control::GetChildren() { return children_; } +Index Control::IndexOfChild(Control* control) { + const auto& children = GetChildren(); + auto iter = std::ranges::find(children, control); + if (iter == children.cend()) { + return -1; + } + return iter - children.begin(); +} + void Control::RemoveChild(Control* child) { auto iter = std::ranges::find(children_, child); if (iter != children_.cend()) { diff --git a/src/ui/controls/FlexLayout.cpp b/src/ui/controls/FlexLayout.cpp index 8d71cfdb..ffe953d7 100644 --- a/src/ui/controls/FlexLayout.cpp +++ b/src/ui/controls/FlexLayout.cpp @@ -1,11 +1,10 @@ #include "cru/ui/controls/FlexLayout.h" namespace cru::ui::controls { -FlexLayout::FlexLayout() = default; +FlexLayout::FlexLayout() + : LayoutControl<render::FlexLayoutRenderObject>(kControlName) {} -FlexLayout::~FlexLayout() = default; - -FlexMainAlignment FlexLayout::GetContentMainAlign() const { +FlexMainAlignment FlexLayout::GetContentMainAlign() { return GetContainerRenderObject()->GetContentMainAlign(); } @@ -13,7 +12,7 @@ void FlexLayout::SetContentMainAlign(FlexMainAlignment value) { GetContainerRenderObject()->SetContentMainAlign(value); } -FlexDirection FlexLayout::GetFlexDirection() const { +FlexDirection FlexLayout::GetFlexDirection() { return GetContainerRenderObject()->GetFlexDirection(); } @@ -21,7 +20,7 @@ void FlexLayout::SetFlexDirection(FlexDirection direction) { GetContainerRenderObject()->SetFlexDirection(direction); } -FlexCrossAlignment FlexLayout::GetItemCrossAlign() const { +FlexCrossAlignment FlexLayout::GetItemCrossAlign() { return GetContainerRenderObject()->GetItemCrossAlign(); } diff --git a/src/ui/controls/IconButton.cpp b/src/ui/controls/IconButton.cpp index 059a7784..e20e422f 100644 --- a/src/ui/controls/IconButton.cpp +++ b/src/ui/controls/IconButton.cpp @@ -1,20 +1,16 @@ #include "cru/ui/controls/IconButton.h" - -#include "../Helper.h" #include "cru/platform/graphics/Factory.h" #include "cru/platform/graphics/Geometry.h" +#include "cru/platform/gui/UiApplication.h" #include "cru/ui/ThemeManager.h" namespace cru::ui::controls { -IconButton::IconButton() - : container_render_object_(new render::BorderRenderObject()), - geometry_render_object_(new render::GeometryRenderObject()), - click_detector_(this) { - container_render_object_->SetChild(geometry_render_object_.get()); - container_render_object_->SetAttachedControl(this); - geometry_render_object_->SetAttachedControl(this); - - container_render_object_->SetBorderEnabled(true); +IconButton::IconButton() : Control(kControlName), click_detector_(this) { + container_render_object_.SetChild(&geometry_render_object_); + container_render_object_.SetAttachedControl(this); + geometry_render_object_.SetAttachedControl(this); + + container_render_object_.SetBorderEnabled(true); GetStyleRuleSet()->SetParent( ThemeManager::GetInstance()->GetResourceStyleRuleSet( "icon-button.style")); @@ -29,14 +25,18 @@ IconButton::IconButton(std::string_view icon_svg_path_data_string, IconButton::~IconButton() {} void IconButton::SetIconFillColor(const Color& color) { - SetIconFillBrush(GetGraphicsFactory()->CreateSolidColorBrush(color)); + SetIconFillBrush(platform::gui::IUiApplication::GetInstance() + ->GetGraphicsFactory() + ->CreateSolidColorBrush(color)); } void IconButton::SetIconWithSvgPathDataString( std::string_view icon_svg_path_data_string, const Rect& view_port) { - SetIconGeometry(platform::graphics::CreateGeometryFromSvgPathData( - GetGraphicsFactory(), icon_svg_path_data_string), - view_port); + SetIconGeometry( + platform::graphics::CreateGeometryFromSvgPathData( + platform::gui::IUiApplication::GetInstance()->GetGraphicsFactory(), + icon_svg_path_data_string), + view_port); } void IconButton::SetIconWithSvgPathDataStringResourceKey( diff --git a/src/ui/controls/ScrollView.cpp b/src/ui/controls/ScrollView.cpp index f3b3750f..e156f643 100644 --- a/src/ui/controls/ScrollView.cpp +++ b/src/ui/controls/ScrollView.cpp @@ -1,7 +1,7 @@ #include "cru/ui/controls/ScrollView.h" namespace cru::ui::controls { -ScrollView::ScrollView() {} +ScrollView::ScrollView() + : SingleChildControl<render::ScrollRenderObject>(kControlName) {} -ScrollView::~ScrollView() {} } // namespace cru::ui::controls diff --git a/src/ui/controls/StackLayout.cpp b/src/ui/controls/StackLayout.cpp index 55964bcd..b5ca8f35 100644 --- a/src/ui/controls/StackLayout.cpp +++ b/src/ui/controls/StackLayout.cpp @@ -1,9 +1,6 @@ #include "cru/ui/controls/StackLayout.h" namespace cru::ui::controls { -using render::StackLayoutRenderObject; - -StackLayout::StackLayout() = default; - -StackLayout::~StackLayout() = default; +StackLayout::StackLayout() + : LayoutControl<render::StackLayoutRenderObject>(kControlName) {} } // namespace cru::ui::controls diff --git a/src/ui/controls/TextBlock.cpp b/src/ui/controls/TextBlock.cpp index 790c534b..a36c6b41 100644 --- a/src/ui/controls/TextBlock.cpp +++ b/src/ui/controls/TextBlock.cpp @@ -1,20 +1,15 @@ #include "cru/ui/controls/TextBlock.h" - -#include "../Helper.h" #include "cru/platform/graphics/Factory.h" #include "cru/platform/gui/UiApplication.h" #include "cru/ui/ThemeManager.h" -#include "cru/ui/render/CanvasRenderObject.h" -#include "cru/ui/render/StackLayoutRenderObject.h" #include "cru/ui/render/TextRenderObject.h" -namespace cru::ui::controls { -using render::TextRenderObject; - -TextBlock::TextBlock() { - const auto theme_manager = ThemeManager::GetInstance(); +#include <memory> - text_render_object_ = std::make_unique<TextRenderObject>( +namespace cru::ui::controls { +TextBlock::TextBlock() : Control(kControlName) { + auto theme_manager = ThemeManager::GetInstance(); + text_render_object_ = std::make_unique<render::TextRenderObject>( theme_manager->GetResourceBrush("text.brush"), theme_manager->GetResourceFont("text.font"), theme_manager->GetResourceBrush("text.selection.brush"), @@ -23,30 +18,28 @@ TextBlock::TextBlock() { text_render_object_->SetAttachedControl(this); service_ = std::make_unique<TextHostControlService>(this); - service_->SetEnabled(false); service_->SetEditable(false); } -TextBlock::~TextBlock() = default; - -render::RenderObject* TextBlock::GetRenderObject() const { +render::RenderObject* TextBlock::GetRenderObject() { return text_render_object_.get(); } -std::string TextBlock::GetText() const { return service_->GetText(); } +std::string TextBlock::GetText() { return service_->GetText(); } void TextBlock::SetText(std::string text) { service_->SetText(std::move(text)); } -bool TextBlock::IsSelectable() const { return service_->IsEnabled(); } +bool TextBlock::IsSelectable() { return service_->IsEnabled(); } void TextBlock::SetSelectable(bool value) { service_->SetEnabled(value); } void TextBlock::SetTextColor(const Color& color) { - text_render_object_->SetBrush( - GetUiApplication()->GetGraphicsFactory()->CreateSolidColorBrush(color)); + text_render_object_->SetBrush(platform::gui::IUiApplication::GetInstance() + ->GetGraphicsFactory() + ->CreateSolidColorBrush(color)); } render::TextRenderObject* TextBlock::GetTextRenderObject() { diff --git a/src/ui/controls/TextBox.cpp b/src/ui/controls/TextBox.cpp index 70695a01..1e35de69 100644 --- a/src/ui/controls/TextBox.cpp +++ b/src/ui/controls/TextBox.cpp @@ -2,9 +2,7 @@ #include "cru/ui/ThemeManager.h" #include "cru/ui/render/BorderRenderObject.h" -#include "cru/ui/render/CanvasRenderObject.h" #include "cru/ui/render/ScrollRenderObject.h" -#include "cru/ui/render/StackLayoutRenderObject.h" #include "cru/ui/render/TextRenderObject.h" namespace cru::ui::controls { @@ -13,7 +11,8 @@ using render::ScrollRenderObject; using render::TextRenderObject; TextBox::TextBox() - : border_render_object_(new BorderRenderObject()), + : Control(kControlName), + border_render_object_(new BorderRenderObject()), scroll_render_object_(new ScrollRenderObject()) { auto theme_manager = ThemeManager::GetInstance(); @@ -43,13 +42,11 @@ TextBox::TextBox() theme_manager->GetResourceStyleRuleSet("textbox.style")); } -TextBox::~TextBox() {} - -render::RenderObject* TextBox::GetRenderObject() const { +render::RenderObject* TextBox::GetRenderObject() { return border_render_object_.get(); } -bool TextBox::GetMultiLine() const { return service_->IsMultiLine(); } +bool TextBox::GetMultiLine() { return service_->IsMultiLine(); } void TextBox::SetMultiLine(bool value) { service_->SetMultiLine(value); } diff --git a/src/ui/controls/TreeView.cpp b/src/ui/controls/TreeView.cpp index 89613763..c2dbcae7 100644 --- a/src/ui/controls/TreeView.cpp +++ b/src/ui/controls/TreeView.cpp @@ -65,9 +65,8 @@ void TreeViewItem::TraverseDescendants( } TreeView::TreeView() - : root_item_(this, nullptr, render_object_.GetRootItem()) {} - -TreeView::~TreeView() {} + : Control(kControlType), + root_item_(this, nullptr, render_object_.GetRootItem()) {} void TreeView::OnChildRemoved(Control* control, Index index) { root_item_.TraverseDescendants([control](TreeViewItem* item) { diff --git a/src/ui/controls/Window.cpp b/src/ui/controls/Window.cpp index a5fbf05f..9722a3c6 100644 --- a/src/ui/controls/Window.cpp +++ b/src/ui/controls/Window.cpp @@ -8,7 +8,9 @@ namespace cru::ui::controls { Window::Window() - : control_host_(new ControlHost(this)), attached_control_(nullptr) { + : LayoutControl<render::StackLayoutRenderObject>(kControlName), + control_host_(new ControlHost(this)), + attached_control_(nullptr) { GetContainerRenderObject()->SetDefaultHorizontalAlignment(Alignment::Stretch); GetContainerRenderObject()->SetDefaultVertialAlignment(Alignment::Stretch); } @@ -21,8 +23,6 @@ Window* Window::CreatePopup() { return window; } -std::string Window::GetControlType() const { return std::string(kControlType); } - void Window::SetAttachedControl(Control* control) { attached_control_ = control; } |
