diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/cru/ui/controls/text_box.hpp | 13 | ||||
-rw-r--r-- | include/cru/ui/render/canvas_render_object.hpp | 4 | ||||
-rw-r--r-- | include/cru/ui/render/render_object.hpp | 3 | ||||
-rw-r--r-- | include/cru/ui/ui_manager.hpp | 28 |
4 files changed, 23 insertions, 25 deletions
diff --git a/include/cru/ui/controls/text_box.hpp b/include/cru/ui/controls/text_box.hpp index 48168e9d..76a6299e 100644 --- a/include/cru/ui/controls/text_box.hpp +++ b/include/cru/ui/controls/text_box.hpp @@ -1,6 +1,14 @@ #pragma once #include "../no_child_control.hpp" +#include <memory> + +namespace cru::ui::render { +class BorderRenderObject; +class TextRenderObject; +class CanvasRenderObject; +} // namespace cru::ui::render + namespace cru::ui::controls { class TextBox : public NoChildControl { public: @@ -16,5 +24,10 @@ class TextBox : public NoChildControl { ~TextBox() override; std::string_view GetControlType() const final { return control_type; } + + private: + std::unique_ptr<render::BorderRenderObject> border_render_object_; + std::unique_ptr<render::TextRenderObject> text_render_object_; + std::unique_ptr<render::CanvasRenderObject> caret_render_object_; }; } // namespace cru::ui::controls diff --git a/include/cru/ui/render/canvas_render_object.hpp b/include/cru/ui/render/canvas_render_object.hpp index fea68576..5fea8755 100644 --- a/include/cru/ui/render/canvas_render_object.hpp +++ b/include/cru/ui/render/canvas_render_object.hpp @@ -37,6 +37,10 @@ class CanvasRenderObject : public RenderObject { IEvent<CanvasPaintEventArgs>* PaintEvent() { return &paint_event_; } + protected: + Size OnMeasureContent(const Size& available_size) override; + void OnLayoutContent(const Rect& content_rect) override; + private: Event<CanvasPaintEventArgs> paint_event_; }; diff --git a/include/cru/ui/render/render_object.hpp b/include/cru/ui/render/render_object.hpp index b0a65819..0f0cb8df 100644 --- a/include/cru/ui/render/render_object.hpp +++ b/include/cru/ui/render/render_object.hpp @@ -32,6 +32,9 @@ struct IRenderHost : Interface { virtual IEvent<AfterLayoutEventArgs>* AfterLayoutEvent() = 0; }; +// Render object will not destroy its children when destroyed. Control must +// manage lifecycle of its render objects. Since control will destroy its +// children when destroyed, render objects will be destroyed along with it. class RenderObject : public Object { protected: enum class ChildMode { diff --git a/include/cru/ui/ui_manager.hpp b/include/cru/ui/ui_manager.hpp index 199ff28d..f196444c 100644 --- a/include/cru/ui/ui_manager.hpp +++ b/include/cru/ui/ui_manager.hpp @@ -11,26 +11,10 @@ struct IFont; } // namespace cru::platform::graph namespace cru::ui { -// TODO: Make this theme resource. -class PredefineResources : public Object { - public: - PredefineResources(); - PredefineResources(const PredefineResources& other) = delete; - PredefineResources(PredefineResources&& other) = delete; - PredefineResources& operator=(const PredefineResources& other) = delete; - PredefineResources& operator=(PredefineResources&& other) = delete; - ~PredefineResources() override = default; - - // region Button - std::shared_ptr<platform::graph::IBrush> button_normal_border_brush; - - // region TextBlock - std::shared_ptr<platform::graph::IBrush> text_block_selection_brush; - std::shared_ptr<platform::graph::IBrush> text_block_text_brush; - std::shared_ptr<platform::graph::IFont> text_block_font; -}; - struct ThemeResources { + std::shared_ptr<platform::graph::IFont> default_font; + std::shared_ptr<platform::graph::IBrush> text_brush; + std::shared_ptr<platform::graph::IBrush> text_selection_brush; controls::ButtonStyle button_style; }; @@ -48,15 +32,9 @@ class UiManager : public Object { UiManager& operator=(UiManager&& other) = delete; ~UiManager() override = default; - const PredefineResources* GetPredefineResources() const { - return predefine_resources_.get(); - } - ThemeResources* GetThemeResources() { return &theme_resource_; } private: - std::unique_ptr<PredefineResources> predefine_resources_; - ThemeResources theme_resource_; }; } // namespace cru::ui |