diff options
Diffstat (limited to 'src/ui/controls')
-rw-r--r-- | src/ui/controls/button.cpp | 17 | ||||
-rw-r--r-- | src/ui/controls/button.hpp | 10 | ||||
-rw-r--r-- | src/ui/controls/flex_layout.cpp | 6 | ||||
-rw-r--r-- | src/ui/controls/flex_layout.hpp | 6 | ||||
-rw-r--r-- | src/ui/controls/text_block.cpp | 8 | ||||
-rw-r--r-- | src/ui/controls/text_block.hpp | 6 |
6 files changed, 34 insertions, 19 deletions
diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp index 5d4e15cc..a6578251 100644 --- a/src/ui/controls/button.cpp +++ b/src/ui/controls/button.cpp @@ -1,13 +1,24 @@ #include "button.hpp" -#include "ui/ui_manager.hpp" #include "ui/render/border_render_object.hpp" +#include "ui/ui_manager.hpp" namespace cru::ui::controls { Button::Button() { const auto predefined_resource = UiManager::GetInstance()->GetPredefineResources(); - render_object_ = new render::BorderRenderObject(); } + render_object_.reset(new render::BorderRenderObject( + predefined_resource->button_normal_border_brush)); + render_object_->SetEnabled(true); + render_object_->SetBorderWidth(Thickness{3}); + render_object_->SetCornerRadius(render::CornerRadius{Point{10, 5}}); +} + +render::RenderObject* Button::GetRenderObject() const { return render_object_.get(); } -void Button::OnChildChanged(Control* old_child, Control* new_child) {} +void Button::OnChildChanged(Control* old_child, Control* new_child) { + if (old_child != nullptr) render_object_->RemoveChild(0); + if (new_child != nullptr) + render_object_->AddChild(new_child->GetRenderObject(), 0); +} } // namespace cru::ui::controls diff --git a/src/ui/controls/button.hpp b/src/ui/controls/button.hpp index 27e7fc7b..3f313dfc 100644 --- a/src/ui/controls/button.hpp +++ b/src/ui/controls/button.hpp @@ -1,6 +1,8 @@ #pragma once #include "pre.hpp" +#include <memory> + #include "ui/content_control.hpp" namespace cru::ui::render { @@ -12,7 +14,7 @@ class Button : public ContentControl { public: static constexpr auto control_type = L"Button"; - static Button* Create(); + static Button* Create() { return new Button(); } protected: Button(); @@ -22,7 +24,9 @@ class Button : public ContentControl { Button(Button&& other) = delete; Button& operator=(const Button& other) = delete; Button& operator=(Button&& other) = delete; - ~Button(); + ~Button() override = default; + + StringView GetControlType() const override final { return control_type; } render::RenderObject* GetRenderObject() const override; @@ -30,6 +34,6 @@ class Button : public ContentControl { void OnChildChanged(Control* old_child, Control* new_child) override; private: - render::BorderRenderObject* render_object_; + std::shared_ptr<render::BorderRenderObject> render_object_{}; }; } // namespace cru::ui::controls diff --git a/src/ui/controls/flex_layout.cpp b/src/ui/controls/flex_layout.cpp index 289df1f1..bdbe2d73 100644 --- a/src/ui/controls/flex_layout.cpp +++ b/src/ui/controls/flex_layout.cpp @@ -5,12 +5,10 @@ namespace cru::ui::controls { using render::FlexLayoutRenderObject; -FlexLayout::FlexLayout() { render_object_ = new FlexLayoutRenderObject(); } - -FlexLayout::~FlexLayout() { delete render_object_; } +FlexLayout::FlexLayout() { render_object_.reset(new FlexLayoutRenderObject()); } render::RenderObject* FlexLayout::GetRenderObject() const { - return render_object_; + return render_object_.get(); } void FlexLayout::OnAddChild(Control* child, int position) { diff --git a/src/ui/controls/flex_layout.hpp b/src/ui/controls/flex_layout.hpp index 2ab3e259..9ceef1f6 100644 --- a/src/ui/controls/flex_layout.hpp +++ b/src/ui/controls/flex_layout.hpp @@ -1,6 +1,8 @@ #pragma once #include "pre.hpp" +#include <memory> + #include "ui/layout_control.hpp" namespace cru::ui::render { @@ -23,7 +25,7 @@ class FlexLayout : public LayoutControl { FlexLayout(FlexLayout&& other) = delete; FlexLayout& operator=(const FlexLayout& other) = delete; FlexLayout& operator=(FlexLayout&& other) = delete; - ~FlexLayout() override; + ~FlexLayout() override = default; StringView GetControlType() const override final { return control_type; } @@ -34,6 +36,6 @@ class FlexLayout : public LayoutControl { void OnRemoveChild(Control* child, int position) override; private: - render::FlexLayoutRenderObject* render_object_; + std::shared_ptr<render::FlexLayoutRenderObject> render_object_; }; } // namespace cru::ui::controls diff --git a/src/ui/controls/text_block.cpp b/src/ui/controls/text_block.cpp index c891b832..c2f8cd8e 100644 --- a/src/ui/controls/text_block.cpp +++ b/src/ui/controls/text_block.cpp @@ -9,16 +9,14 @@ using render::TextRenderObject; TextBlock::TextBlock() { const auto predefined_resources = UiManager::GetInstance()->GetPredefineResources(); - render_object_ = + render_object_.reset( new TextRenderObject(predefined_resources->text_block_text_brush, predefined_resources->text_block_text_format, - predefined_resources->text_block_selection_brush); + predefined_resources->text_block_selection_brush)); } -TextBlock::~TextBlock() { delete render_object_; } - render::RenderObject* TextBlock::GetRenderObject() const { - return render_object_; + return render_object_.get(); } String TextBlock::GetText() const { return render_object_->GetText(); } diff --git a/src/ui/controls/text_block.hpp b/src/ui/controls/text_block.hpp index 4c443020..0d65dd67 100644 --- a/src/ui/controls/text_block.hpp +++ b/src/ui/controls/text_block.hpp @@ -1,6 +1,8 @@ #pragma once #include "pre.hpp" +#include <memory> + #include "ui/no_child_control.hpp" namespace cru::ui::render { @@ -22,7 +24,7 @@ class TextBlock : public NoChildControl { TextBlock(TextBlock&& other) = delete; TextBlock& operator=(const TextBlock& other) = delete; TextBlock& operator=(TextBlock&& other) = delete; - ~TextBlock() override; + ~TextBlock() override = default; StringView GetControlType() const override final { return control_type; } @@ -32,6 +34,6 @@ class TextBlock : public NoChildControl { void SetText(const String& text); private: - render::TextRenderObject* render_object_; + std::shared_ptr<render::TextRenderObject> render_object_; }; } // namespace cru::ui::controls |