diff options
author | crupest <crupest@outlook.com> | 2019-12-13 01:02:47 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-12-13 01:02:47 +0800 |
commit | 9110574bb51e9e2959842a7641f598d34c3cd847 (patch) | |
tree | 96ee1f5b3c40095e4e923fc763de0663ee6a01aa /include/cru/ui | |
parent | f2aa96fba0b72eeeadf5160ea5df2c8143ec8aa0 (diff) | |
download | cru-9110574bb51e9e2959842a7641f598d34c3cd847.tar.gz cru-9110574bb51e9e2959842a7641f598d34c3cd847.tar.bz2 cru-9110574bb51e9e2959842a7641f598d34c3cd847.zip |
...
Diffstat (limited to 'include/cru/ui')
-rw-r--r-- | include/cru/ui/base.hpp | 5 | ||||
-rw-r--r-- | include/cru/ui/control.hpp | 21 | ||||
-rw-r--r-- | include/cru/ui/controls/button.hpp | 17 | ||||
-rw-r--r-- | include/cru/ui/controls/container.hpp | 4 | ||||
-rw-r--r-- | include/cru/ui/controls/flex_layout.hpp | 4 | ||||
-rw-r--r-- | include/cru/ui/controls/text_block.hpp | 12 | ||||
-rw-r--r-- | include/cru/ui/render/border_render_object.hpp | 30 | ||||
-rw-r--r-- | include/cru/ui/render/flex_layout_render_object.hpp | 2 | ||||
-rw-r--r-- | include/cru/ui/render/render_object.hpp | 7 | ||||
-rw-r--r-- | include/cru/ui/render/text_render_object.hpp | 38 | ||||
-rw-r--r-- | include/cru/ui/render/window_render_object.hpp | 2 | ||||
-rw-r--r-- | include/cru/ui/ui_event.hpp (renamed from include/cru/ui/event/ui_event.hpp) | 13 | ||||
-rw-r--r-- | include/cru/ui/ui_manager.hpp | 17 | ||||
-rw-r--r-- | include/cru/ui/window.hpp | 16 |
14 files changed, 89 insertions, 99 deletions
diff --git a/include/cru/ui/base.hpp b/include/cru/ui/base.hpp index a5e656ff..581e6f8f 100644 --- a/include/cru/ui/base.hpp +++ b/include/cru/ui/base.hpp @@ -1,5 +1,6 @@ #pragma once -#include "cru/platform/graphic_base.hpp" +#include "cru/common/base.hpp" +#include "cru/platform/graph_base.hpp" #include "cru/platform/matrix.hpp" #include "cru/platform/native/basic_types.hpp" @@ -17,7 +18,7 @@ using cru::platform::native::MouseButton; namespace colors { using cru::platform::colors::black; -using cru::platform::colors::white; using cru::platform::colors::skyblue; +using cru::platform::colors::white; } // namespace colors } // namespace cru::ui diff --git a/include/cru/ui/control.hpp b/include/cru/ui/control.hpp index cf4f9053..1fe49261 100644 --- a/include/cru/ui/control.hpp +++ b/include/cru/ui/control.hpp @@ -1,15 +1,18 @@ #pragma once #include "base.hpp" -#include "cru/common/base.hpp" -#include "cru/platform/native/basic_types.hpp" -#include "cru/platform/native/cursor.hpp" -#include "event/ui_event.hpp" +#include "cru/common/event.hpp" +#include "ui_event.hpp" +#include <functional> #include <memory> #include <string_view> #include <vector> +namespace cru::platform::native { +struct ICursor; +} + namespace cru::ui { class Window; namespace render { @@ -30,7 +33,7 @@ class Control : public Object { ~Control() override = default; public: - virtual std::wstring_view GetControlType() const = 0; + virtual std::string_view GetControlType() const = 0; //*************** region: tree *************** public: @@ -74,13 +77,13 @@ class Control : public Object { // Cursor is inherited from parent recursively if not set. public: // null for not set - std::shared_ptr<platform::native::Cursor> GetCursor(); + std::shared_ptr<platform::native::ICursor> GetCursor(); // will not return nullptr - std::shared_ptr<platform::native::Cursor> GetInheritedCursor(); + std::shared_ptr<platform::native::ICursor> GetInheritedCursor(); // null to unset - void SetCursor(std::shared_ptr<platform::native::Cursor> cursor); + void SetCursor(std::shared_ptr<platform::native::ICursor> cursor); //*************** region: events *************** public: @@ -163,6 +166,6 @@ class Control : public Object { bool right; } click_map_; - std::shared_ptr<platform::native::Cursor> cursor_ = nullptr; + std::shared_ptr<platform::native::ICursor> cursor_ = nullptr; }; } // namespace cru::ui diff --git a/include/cru/ui/controls/button.hpp b/include/cru/ui/controls/button.hpp index d4a03e1d..60b1243f 100644 --- a/include/cru/ui/controls/button.hpp +++ b/include/cru/ui/controls/button.hpp @@ -3,24 +3,19 @@ #include "../click_detector.hpp" #include "../render/border_render_object.hpp" -#include "cru/platform/graph/brush.hpp" #include "cru/platform/native/basic_types.hpp" #include <memory> -namespace cru::ui::render { -class BorderRenderObject; -} - namespace cru::ui::controls { using render::CornerRadius; struct ButtonStateStyle { - std::shared_ptr<platform::graph::Brush> border_brush; + std::shared_ptr<platform::graph::IBrush> border_brush; Thickness border_thickness; CornerRadius border_radius; - std::shared_ptr<platform::graph::Brush> foreground_brush; - std::shared_ptr<platform::graph::Brush> background_brush; + std::shared_ptr<platform::graph::IBrush> foreground_brush; + std::shared_ptr<platform::graph::IBrush> background_brush; }; struct ButtonStyle { @@ -47,7 +42,7 @@ enum class ButtonState { class Button : public ContentControl { public: - static constexpr auto control_type = L"Button"; + static constexpr std::string_view control_type = "Button"; static Button* Create() { return new Button(); } @@ -61,7 +56,7 @@ class Button : public ContentControl { Button& operator=(Button&& other) = delete; ~Button() override = default; - std::wstring_view GetControlType() const override final { + std::string_view GetControlType() const final { return control_type; } @@ -96,7 +91,7 @@ class Button : public ContentControl { } private: - std::shared_ptr<render::BorderRenderObject> render_object_{}; + std::unique_ptr<render::BorderRenderObject> render_object_{}; ButtonState state_ = ButtonState::Normal; diff --git a/include/cru/ui/controls/container.hpp b/include/cru/ui/controls/container.hpp index 3c877067..efc099f7 100644 --- a/include/cru/ui/controls/container.hpp +++ b/include/cru/ui/controls/container.hpp @@ -7,7 +7,7 @@ class BorderRenderObject; namespace cru::ui::controls { class Container : public ContentControl { - static constexpr auto control_type = L"Container"; + static constexpr std::string_view control_type = "Container"; protected: Container(); @@ -19,7 +19,7 @@ class Container : public ContentControl { ~Container() override; public: - std::wstring_view GetControlType() const override final { + std::string_view GetControlType() const final { return control_type; } diff --git a/include/cru/ui/controls/flex_layout.hpp b/include/cru/ui/controls/flex_layout.hpp index d8d92d08..ff8ec53b 100644 --- a/include/cru/ui/controls/flex_layout.hpp +++ b/include/cru/ui/controls/flex_layout.hpp @@ -15,7 +15,7 @@ using render::FlexMainAlignment; class FlexLayout : public LayoutControl { public: - static constexpr auto control_type = L"FlexLayout"; + static constexpr std::string_view control_type = "FlexLayout"; static FlexLayout* Create() { return new FlexLayout(); } @@ -29,7 +29,7 @@ class FlexLayout : public LayoutControl { FlexLayout& operator=(FlexLayout&& other) = delete; ~FlexLayout() override = default; - std::wstring_view GetControlType() const override final { + std::string_view GetControlType() const final { return control_type; } diff --git a/include/cru/ui/controls/text_block.hpp b/include/cru/ui/controls/text_block.hpp index 45cd12b9..708b62f1 100644 --- a/include/cru/ui/controls/text_block.hpp +++ b/include/cru/ui/controls/text_block.hpp @@ -10,7 +10,7 @@ class TextRenderObject; namespace cru::ui::controls { class TextBlock : public NoChildControl { public: - static constexpr auto control_type = L"TextBlock"; + static constexpr std::string_view control_type = "TextBlock"; static TextBlock* Create() { return new TextBlock(); } @@ -22,18 +22,18 @@ class TextBlock : public NoChildControl { TextBlock(TextBlock&& other) = delete; TextBlock& operator=(const TextBlock& other) = delete; TextBlock& operator=(TextBlock&& other) = delete; - ~TextBlock() override = default; + ~TextBlock() override; - std::wstring_view GetControlType() const override final { + std::string_view GetControlType() const final { return control_type; } render::RenderObject* GetRenderObject() const override; - std::wstring GetText() const; - void SetText(std::wstring text); + std::string GetText() const; + void SetText(std::string text); private: - std::shared_ptr<render::TextRenderObject> render_object_; + std::unique_ptr<render::TextRenderObject> render_object_; }; } // namespace cru::ui::controls diff --git a/include/cru/ui/render/border_render_object.hpp b/include/cru/ui/render/border_render_object.hpp index 5520ab2e..726510a8 100644 --- a/include/cru/ui/render/border_render_object.hpp +++ b/include/cru/ui/render/border_render_object.hpp @@ -1,13 +1,11 @@ #pragma once -#include "cru/platform/graph/brush.hpp" -#include "cru/ui/base.hpp" #include "render_object.hpp" #include <memory> namespace cru::platform::graph { -class Brush; -class IGeometry; +struct IBrush; +struct IGeometry; } // namespace cru::platform::graph namespace cru::ui::render { @@ -55,19 +53,19 @@ class BorderRenderObject : public RenderObject { bool IsBorderEnabled() const { return is_border_enabled_; } void SetBorderEnabled(bool enabled) { is_border_enabled_ = enabled; } - std::shared_ptr<platform::graph::Brush> GetBorderBrush() { + std::shared_ptr<platform::graph::IBrush> GetBorderBrush() { return border_brush_; } - void SetBorderBrush(std::shared_ptr<platform::graph::Brush> brush) { + void SetBorderBrush(std::shared_ptr<platform::graph::IBrush> brush) { if (brush == border_brush_) return; border_brush_ = std::move(brush); InvalidatePaint(); } - platform::Thickness GetBorderThickness() { return border_thickness_; } + Thickness GetBorderThickness() { return border_thickness_; } - void SetBorderThickness(const platform::Thickness thickness) { + void SetBorderThickness(const Thickness thickness) { if (thickness == border_thickness_) return; border_thickness_ = thickness; InvalidateLayout(); @@ -81,27 +79,27 @@ class BorderRenderObject : public RenderObject { RecreateGeometry(); } - std::shared_ptr<platform::graph::Brush> GetForegroundBrush() { + std::shared_ptr<platform::graph::IBrush> GetForegroundBrush() { return foreground_brush_; } - void SetForegroundBrush(std::shared_ptr<platform::graph::Brush> brush) { + void SetForegroundBrush(std::shared_ptr<platform::graph::IBrush> brush) { if (brush == foreground_brush_) return; foreground_brush_ = std::move(brush); InvalidatePaint(); } - std::shared_ptr<platform::graph::Brush> GetBackgroundBrush() { + std::shared_ptr<platform::graph::IBrush> GetBackgroundBrush() { return background_brush_; } - void SetBackgroundBrush(std::shared_ptr<platform::graph::Brush> brush) { + void SetBackgroundBrush(std::shared_ptr<platform::graph::IBrush> brush) { if (brush == background_brush_) return; background_brush_ = std::move(brush); InvalidatePaint(); } - void Draw(platform::graph::Painter* painter) override; + void Draw(platform::graph::IPainter* painter) override; RenderObject* HitTest(const Point& point) override; @@ -123,12 +121,12 @@ class BorderRenderObject : public RenderObject { private: bool is_border_enabled_ = false; - std::shared_ptr<platform::graph::Brush> border_brush_; + std::shared_ptr<platform::graph::IBrush> border_brush_; platform::Thickness border_thickness_; CornerRadius border_radius_; - std::shared_ptr<platform::graph::Brush> foreground_brush_; - std::shared_ptr<platform::graph::Brush> background_brush_; + std::shared_ptr<platform::graph::IBrush> foreground_brush_; + std::shared_ptr<platform::graph::IBrush> background_brush_; // The ring. Used for painting. std::unique_ptr<platform::graph::IGeometry> geometry_; diff --git a/include/cru/ui/render/flex_layout_render_object.hpp b/include/cru/ui/render/flex_layout_render_object.hpp index 7b71b96e..5a8d09ba 100644 --- a/include/cru/ui/render/flex_layout_render_object.hpp +++ b/include/cru/ui/render/flex_layout_render_object.hpp @@ -78,7 +78,7 @@ class FlexLayoutRenderObject : public RenderObject { InvalidateLayout(); } - void Draw(platform::graph::Painter* painter) override; + void Draw(platform::graph::IPainter* painter) override; RenderObject* HitTest(const Point& point) override; diff --git a/include/cru/ui/render/render_object.hpp b/include/cru/ui/render/render_object.hpp index befaa3ec..55b7f2da 100644 --- a/include/cru/ui/render/render_object.hpp +++ b/include/cru/ui/render/render_object.hpp @@ -1,7 +1,6 @@ #pragma once -#include "cru/common/base.hpp" - #include "../base.hpp" + #include "cru/common/event.hpp" #include <vector> @@ -12,7 +11,7 @@ class Control; } namespace cru::platform::graph { -class Painter; +struct IPainter; } namespace cru::ui::render { @@ -75,7 +74,7 @@ class RenderObject : public Object { void Measure(const Size& available_size); void Layout(const Rect& rect); - virtual void Draw(platform::graph::Painter* painter) = 0; + virtual void Draw(platform::graph::IPainter* painter) = 0; virtual RenderObject* HitTest(const Point& point) = 0; diff --git a/include/cru/ui/render/text_render_object.hpp b/include/cru/ui/render/text_render_object.hpp index a10e3b74..6c01ed93 100644 --- a/include/cru/ui/render/text_render_object.hpp +++ b/include/cru/ui/render/text_render_object.hpp @@ -6,33 +6,33 @@ // forward declarations namespace cru::platform::graph { -class Brush; -class Font; -class TextLayout; +struct IBrush; +struct IFont; +struct ITextLayout; } // namespace cru::platform::graph namespace cru::ui::render { class TextRenderObject : public RenderObject { public: - TextRenderObject(std::shared_ptr<platform::graph::Brush> brush, - std::shared_ptr<platform::graph::Font> font, - std::shared_ptr<platform::graph::Brush> selection_brush); + TextRenderObject(std::shared_ptr<platform::graph::IBrush> brush, + std::shared_ptr<platform::graph::IFont> font, + std::shared_ptr<platform::graph::IBrush> selection_brush); TextRenderObject(const TextRenderObject& other) = delete; TextRenderObject(TextRenderObject&& other) = delete; TextRenderObject& operator=(const TextRenderObject& other) = delete; TextRenderObject& operator=(TextRenderObject&& other) = delete; ~TextRenderObject() override = default; - std::wstring GetText() const; - void SetText(std::wstring new_text); + std::string GetText() const; + void SetText(std::string new_text); - std::shared_ptr<platform::graph::Brush> GetBrush() const { return brush_; } - void SetBrush(std::shared_ptr<platform::graph::Brush> new_brush) { + std::shared_ptr<platform::graph::IBrush> GetBrush() const { return brush_; } + void SetBrush(std::shared_ptr<platform::graph::IBrush> new_brush) { new_brush.swap(brush_); } - std::shared_ptr<platform::graph::Font> GetFont() const; - void SetFont(std::shared_ptr<platform::graph::Font> font); + std::shared_ptr<platform::graph::IFont> GetFont() const; + void SetFont(std::shared_ptr<platform::graph::IFont> font); std::optional<TextRange> GetSelectionRange() const { return selection_range_; @@ -41,14 +41,14 @@ class TextRenderObject : public RenderObject { selection_range_ = std::move(new_range); } - std::shared_ptr<platform::graph::Brush> GetSelectionBrush() const { + std::shared_ptr<platform::graph::IBrush> GetSelectionBrush() const { return selection_brush_; } - void SetSelectionBrush(std::shared_ptr<platform::graph::Brush> new_brush) { + void SetSelectionBrush(std::shared_ptr<platform::graph::IBrush> new_brush) { new_brush.swap(selection_brush_); } - void Draw(platform::graph::Painter* painter) override; + void Draw(platform::graph::IPainter* painter) override; RenderObject* HitTest(const Point& point) override; @@ -59,11 +59,11 @@ class TextRenderObject : public RenderObject { void OnAfterLayout() override; private: - std::shared_ptr<platform::graph::Brush> brush_; - std::shared_ptr<platform::graph::Font> font_; - std::shared_ptr<platform::graph::TextLayout> text_layout_; + std::shared_ptr<platform::graph::IBrush> brush_; + std::shared_ptr<platform::graph::IFont> font_; + std::unique_ptr<platform::graph::ITextLayout> text_layout_; std::optional<TextRange> selection_range_ = std::nullopt; - std::shared_ptr<platform::graph::Brush> selection_brush_; + std::shared_ptr<platform::graph::IBrush> selection_brush_; }; } // namespace cru::ui::render diff --git a/include/cru/ui/render/window_render_object.hpp b/include/cru/ui/render/window_render_object.hpp index 2260c293..8f35ad80 100644 --- a/include/cru/ui/render/window_render_object.hpp +++ b/include/cru/ui/render/window_render_object.hpp @@ -21,7 +21,7 @@ class WindowRenderObject : public RenderObject { void Relayout(); - void Draw(platform::graph::Painter* painter) override; + void Draw(platform::graph::IPainter* painter) override; RenderObject* HitTest(const Point& point) override; diff --git a/include/cru/ui/event/ui_event.hpp b/include/cru/ui/ui_event.hpp index b962ff76..7a688d6d 100644 --- a/include/cru/ui/event/ui_event.hpp +++ b/include/cru/ui/ui_event.hpp @@ -1,15 +1,12 @@ #pragma once -#include "cru/common/base.hpp" - -#include "../base.hpp" -#include "cru/common/event.hpp" +#include "base.hpp" #include <memory> #include <optional> #include <type_traits> namespace cru::platform::graph { -class Painter; +struct IPainter; } namespace cru::ui { @@ -127,7 +124,7 @@ class MouseWheelEventArgs : public MouseEventArgs { class PaintEventArgs : public UiEventArgs { public: PaintEventArgs(Object* sender, Object* original_sender, - platform::graph::Painter* painter) + platform::graph::IPainter* painter) : UiEventArgs(sender, original_sender), painter_(painter) {} PaintEventArgs(const PaintEventArgs& other) = default; PaintEventArgs(PaintEventArgs&& other) = default; @@ -135,10 +132,10 @@ class PaintEventArgs : public UiEventArgs { PaintEventArgs& operator=(PaintEventArgs&& other) = default; ~PaintEventArgs() = default; - platform::graph::Painter* GetPainter() const { return painter_; } + platform::graph::IPainter* GetPainter() const { return painter_; } private: - platform::graph::Painter* painter_; + platform::graph::IPainter* painter_; }; class FocusChangeEventArgs : public UiEventArgs { diff --git a/include/cru/ui/ui_manager.hpp b/include/cru/ui/ui_manager.hpp index 5501c62c..199ff28d 100644 --- a/include/cru/ui/ui_manager.hpp +++ b/include/cru/ui/ui_manager.hpp @@ -1,14 +1,13 @@ #pragma once #include "base.hpp" -#include "cru/common/base.hpp" #include "controls/button.hpp" #include <memory> namespace cru::platform::graph { -class Brush; -class Font; +struct IBrush; +struct IFont; } // namespace cru::platform::graph namespace cru::ui { @@ -23,12 +22,12 @@ class PredefineResources : public Object { ~PredefineResources() override = default; // region Button - std::shared_ptr<platform::graph::Brush> button_normal_border_brush; + std::shared_ptr<platform::graph::IBrush> button_normal_border_brush; // region TextBlock - std::shared_ptr<platform::graph::Brush> text_block_selection_brush; - std::shared_ptr<platform::graph::Brush> text_block_text_brush; - std::shared_ptr<platform::graph::Font> text_block_font; + 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 { @@ -53,9 +52,7 @@ class UiManager : public Object { return predefine_resources_.get(); } - ThemeResources* GetThemeResources() { - return &theme_resource_; - } + ThemeResources* GetThemeResources() { return &theme_resource_; } private: std::unique_ptr<PredefineResources> predefine_resources_; diff --git a/include/cru/ui/window.hpp b/include/cru/ui/window.hpp index 4f44fed4..35d6772e 100644 --- a/include/cru/ui/window.hpp +++ b/include/cru/ui/window.hpp @@ -2,14 +2,13 @@ #include "content_control.hpp" #include "cru/common/self_resolvable.hpp" -#include "cru/platform/native/native_event.hpp" -#include "event/ui_event.hpp" +#include "cru/platform/native/event.hpp" #include <memory> #include <vector> namespace cru::platform::native { -class INativeWindow; +struct INativeWindow; } namespace cru::ui { @@ -21,7 +20,7 @@ class Window final : public ContentControl, public SelfResolvable<Window> { friend class Control; public: - static constexpr auto control_type = L"Window"; + static constexpr std::string_view control_type = "Window"; public: static Window* CreateOverlapped(); @@ -39,7 +38,7 @@ class Window final : public ContentControl, public SelfResolvable<Window> { ~Window() override; public: - std::wstring_view GetControlType() const override final; + std::string_view GetControlType() const override final; render::RenderObject* GetRenderObject() const override; @@ -90,9 +89,10 @@ class Window final : public ContentControl, public SelfResolvable<Window> { void OnNativePaint(std::nullptr_t); void OnNativeResize(const Size& size); - void OnNativeFocus(bool focus); + void OnNativeFocus(cru::platform::native::FocusChangeType focus); - void OnNativeMouseEnterLeave(bool enter); + void OnNativeMouseEnterLeave( + cru::platform::native::MouseEnterLeaveType enter); void OnNativeMouseMove(const Point& point); void OnNativeMouseDown( const platform::native::NativeMouseButtonEventArgs& args); @@ -115,7 +115,7 @@ class Window final : public ContentControl, public SelfResolvable<Window> { platform::native::INativeWindow* native_window_; std::vector<EventRevokerGuard> event_revoker_guards_; - std::shared_ptr<render::WindowRenderObject> render_object_; + std::unique_ptr<render::WindowRenderObject> render_object_; Control* mouse_hover_control_; |