diff options
Diffstat (limited to 'include/cru/ui')
27 files changed, 62 insertions, 78 deletions
diff --git a/include/cru/ui/ThemeManager.h b/include/cru/ui/ThemeManager.h index 10d90060..5e24a159 100644 --- a/include/cru/ui/ThemeManager.h +++ b/include/cru/ui/ThemeManager.h @@ -1,7 +1,6 @@ #pragma once #include "Base.h" #include "cru/base/Event.h" -#include "cru/base/Format.h" #include "cru/ui/ThemeResourceDictionary.h" #include <vector> @@ -27,7 +26,7 @@ class CRU_UI_API ThemeManager : public Object { std::unique_ptr<ThemeResourceDictionary> theme_resource_dictionary); template <typename T> - T GetResource(std::string_view key) { + T GetResource(const std::string_view& key) { for (const auto& resource_dictionary : theme_resource_dictionary_list_) { try { return resource_dictionary->GetResource<T>(key); diff --git a/include/cru/ui/ThemeResourceDictionary.h b/include/cru/ui/ThemeResourceDictionary.h index 90cbe520..e7463b12 100644 --- a/include/cru/ui/ThemeResourceDictionary.h +++ b/include/cru/ui/ThemeResourceDictionary.h @@ -28,11 +28,7 @@ class CRU_UI_API ThemeResourceDictionary : public Object { public: static std::unique_ptr<ThemeResourceDictionary> FromFile( - const String& file_path); - static std::unique_ptr<ThemeResourceDictionary> FromFile( - std::filesystem::path file_path) { - return FromFile(String::FromStdPath(file_path)); - } + std::filesystem::path file_path); explicit ThemeResourceDictionary(xml::XmlElementNode* xml_root, bool clone = true); diff --git a/include/cru/ui/controls/Button.h b/include/cru/ui/controls/Button.h index 717710e8..3c01be32 100644 --- a/include/cru/ui/controls/Button.h +++ b/include/cru/ui/controls/Button.h @@ -12,7 +12,7 @@ class CRU_UI_API Button : public SingleChildControl<render::BorderRenderObject>, public virtual IClickableControl, public virtual IBorderControl { public: - static constexpr StringView kControlType = u"Button"; + static constexpr std::string_view kControlType = "Button"; public: Button(); @@ -22,7 +22,7 @@ class CRU_UI_API Button : public SingleChildControl<render::BorderRenderObject>, Button& operator=(Button&& other) = delete; ~Button() override; - String GetControlType() const final { return kControlType.ToString(); } + std::string GetControlType() const final { return std::string(kControlType); } public: helper::ClickState GetClickState() override { diff --git a/include/cru/ui/controls/CheckBox.h b/include/cru/ui/controls/CheckBox.h index 19908389..8a2c84a0 100644 --- a/include/cru/ui/controls/CheckBox.h +++ b/include/cru/ui/controls/CheckBox.h @@ -12,12 +12,12 @@ class CRU_UI_API CheckBox : public NoChildControl, public virtual ICheckableControl, public virtual IClickableControl { public: - static constexpr StringView kControlType = u"CheckBox"; + static constexpr std::string_view kControlType = "CheckBox"; CheckBox(); ~CheckBox() override; - String GetControlType() const override { return kControlType.ToString(); } + std::string GetControlType() const override { return std::string(kControlType); } render::RenderObject* GetRenderObject() const override { return container_render_object_.get(); diff --git a/include/cru/ui/controls/Container.h b/include/cru/ui/controls/Container.h index c8bf3f32..4fee178d 100644 --- a/include/cru/ui/controls/Container.h +++ b/include/cru/ui/controls/Container.h @@ -8,7 +8,7 @@ namespace cru::ui::controls { class CRU_UI_API Container : public SingleChildControl<render::BorderRenderObject>, public virtual IBorderControl { - static constexpr StringView kControlType = u"Container"; + static constexpr std::string_view kControlType = "Container"; public: Container(); @@ -46,6 +46,6 @@ class CRU_UI_API Container } public: - String GetControlType() const final { return kControlType.ToString(); } + 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 f6603bbc..7301ecd8 100644 --- a/include/cru/ui/controls/Control.h +++ b/include/cru/ui/controls/Control.h @@ -36,7 +36,7 @@ class CRU_UI_API Control : public Object, ~Control() override; public: - virtual String GetControlType() const = 0; + virtual std::string GetControlType() const = 0; //*************** region: tree *************** public: diff --git a/include/cru/ui/controls/FlexLayout.h b/include/cru/ui/controls/FlexLayout.h index 148586c0..8940e38e 100644 --- a/include/cru/ui/controls/FlexLayout.h +++ b/include/cru/ui/controls/FlexLayout.h @@ -13,7 +13,7 @@ using render::FlexMainAlignment; class CRU_UI_API FlexLayout : public LayoutControl<render::FlexLayoutRenderObject> { public: - static constexpr StringView kControlType = u"FlexLayout"; + static constexpr std::string_view kControlType = "FlexLayout"; public: FlexLayout(); @@ -23,7 +23,7 @@ class CRU_UI_API FlexLayout FlexLayout& operator=(FlexLayout&& other) = delete; ~FlexLayout() override; - String GetControlType() const final { return kControlType.ToString(); } + std::string GetControlType() const final { return std::string(kControlType); } FlexMainAlignment GetContentMainAlign() const; void SetContentMainAlign(FlexMainAlignment value); diff --git a/include/cru/ui/controls/IconButton.h b/include/cru/ui/controls/IconButton.h index 9dbb3a3d..9e7572e0 100644 --- a/include/cru/ui/controls/IconButton.h +++ b/include/cru/ui/controls/IconButton.h @@ -17,14 +17,14 @@ class CRU_UI_API IconButton : public NoChildControl, public virtual IBorderControl, public virtual IContentBrushControl { public: - static constexpr StringView kControlType = u"IconButton"; + static constexpr std::string_view kControlType = "IconButton"; public: IconButton(); IconButton(std::string_view icon_svg_path_data_string, const Rect& view_port); ~IconButton() override; - String GetControlType() const final { return kControlType.ToString(); } + std::string GetControlType() const final { return std::string(kControlType); } render::RenderObject* GetRenderObject() const override { return container_render_object_.get(); diff --git a/include/cru/ui/controls/Popup.h b/include/cru/ui/controls/Popup.h index 464e7278..7c57d257 100644 --- a/include/cru/ui/controls/Popup.h +++ b/include/cru/ui/controls/Popup.h @@ -8,7 +8,7 @@ namespace cru::ui::controls { class CRU_UI_API Popup : public RootControl { public: - static constexpr StringView kControlType = u"Popup"; + static constexpr std::string_view kControlType = "Popup"; explicit Popup(Control* attached_control = nullptr); @@ -17,6 +17,6 @@ class CRU_UI_API Popup : public RootControl { ~Popup() override; - String GetControlType() const override { return kControlType.ToString(); } + std::string GetControlType() const override { return std::string(kControlType); } }; } // namespace cru::ui::controls diff --git a/include/cru/ui/controls/ScrollView.h b/include/cru/ui/controls/ScrollView.h index 244977d5..cefda747 100644 --- a/include/cru/ui/controls/ScrollView.h +++ b/include/cru/ui/controls/ScrollView.h @@ -7,7 +7,7 @@ namespace cru::ui::controls { class CRU_UI_API ScrollView : public SingleChildControl<render::ScrollRenderObject> { public: - static constexpr StringView kControlType = u"ScrollView"; + static constexpr std::string_view kControlType = "ScrollView"; ScrollView(); CRU_DELETE_COPY(ScrollView) @@ -15,6 +15,6 @@ class CRU_UI_API ScrollView ~ScrollView() override; public: - String GetControlType() const override { return kControlType.ToString(); } + std::string GetControlType() const override { return std::string(kControlType); } }; } // namespace cru::ui::controls diff --git a/include/cru/ui/controls/StackLayout.h b/include/cru/ui/controls/StackLayout.h index cbf35cbe..db646807 100644 --- a/include/cru/ui/controls/StackLayout.h +++ b/include/cru/ui/controls/StackLayout.h @@ -9,13 +9,13 @@ using render::StackChildLayoutData; class CRU_UI_API StackLayout : public LayoutControl<render::StackLayoutRenderObject> { public: - static constexpr StringView kControlType = u"StackLayout"; + static constexpr std::string_view kControlType = "StackLayout"; StackLayout(); CRU_DELETE_COPY(StackLayout) CRU_DELETE_MOVE(StackLayout) ~StackLayout() override; - String GetControlType() const final { return kControlType.ToString(); } + 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 66330b23..a3b6407f 100644 --- a/include/cru/ui/controls/TextBlock.h +++ b/include/cru/ui/controls/TextBlock.h @@ -14,7 +14,7 @@ class CRU_UI_API TextBlock : public NoChildControl, public virtual IFontControl, public virtual IContentBrushControl { public: - static constexpr StringView kControlType = u"TextBlock"; + static constexpr std::string_view kControlType = "TextBlock"; static std::unique_ptr<TextBlock> Create(std::string text, bool selectable = false) { @@ -32,7 +32,7 @@ class CRU_UI_API TextBlock : public NoChildControl, TextBlock& operator=(TextBlock&& other) = delete; ~TextBlock() override; - String GetControlType() const final { return kControlType.ToString(); } + std::string GetControlType() const final { return std::string(kControlType); } render::RenderObject* GetRenderObject() const override; diff --git a/include/cru/ui/controls/TextBox.h b/include/cru/ui/controls/TextBox.h index 13f5d356..adb9895e 100644 --- a/include/cru/ui/controls/TextBox.h +++ b/include/cru/ui/controls/TextBox.h @@ -18,14 +18,14 @@ class CRU_UI_API TextBox : public NoChildControl, public virtual IContentBrushControl, public virtual IFontControl { public: - static constexpr StringView control_type = u"TextBox"; + static constexpr std::string_view control_type = "TextBox"; TextBox(); CRU_DELETE_COPY(TextBox) CRU_DELETE_MOVE(TextBox) ~TextBox() override; - String GetControlType() const final { return control_type.ToString(); } + std::string GetControlType() const final { return std::string(control_type); } render::RenderObject* GetRenderObject() const override; diff --git a/include/cru/ui/controls/TreeView.h b/include/cru/ui/controls/TreeView.h index 6c3c360b..dc74750a 100644 --- a/include/cru/ui/controls/TreeView.h +++ b/include/cru/ui/controls/TreeView.h @@ -52,14 +52,16 @@ class CRU_UI_API TreeViewItem : public Object { class CRU_UI_API TreeView : public Control { public: - constexpr static StringView kControlType = u"TreeView"; + constexpr static std::string_view kControlType = "TreeView"; TreeView(); CRU_DELETE_COPY(TreeView) CRU_DELETE_MOVE(TreeView) ~TreeView() override; - String GetControlType() const override { return kControlType.ToString(); } + std::string GetControlType() const override { + return std::string(kControlType); + } render::TreeRenderObject* GetRenderObject() { return &render_object_; } void ForEachChild(const std::function<void(Control*)>& predicate) override; diff --git a/include/cru/ui/controls/Window.h b/include/cru/ui/controls/Window.h index 656a96dd..c4ba94d9 100644 --- a/include/cru/ui/controls/Window.h +++ b/include/cru/ui/controls/Window.h @@ -1,5 +1,4 @@ #pragma once -#include "cru/platform/gui/Base.h" #include "cru/ui/controls/RootControl.h" #include "cru/base/Base.h" @@ -7,7 +6,7 @@ namespace cru::ui::controls { class CRU_UI_API Window final : public RootControl { public: - static constexpr StringView control_type = u"Window"; + static constexpr std::string_view control_type = "Window"; public: explicit Window(Control* attached_control = nullptr); @@ -16,6 +15,6 @@ class CRU_UI_API Window final : public RootControl { ~Window() override; public: - String GetControlType() const final { return control_type.ToString(); } + std::string GetControlType() const final { return std::string(control_type); } }; } // namespace cru::ui::controls diff --git a/include/cru/ui/document/DocumentElementType.h b/include/cru/ui/document/DocumentElementType.h index 6d4958d0..3621bbd9 100644 --- a/include/cru/ui/document/DocumentElementType.h +++ b/include/cru/ui/document/DocumentElementType.h @@ -1,26 +1,25 @@ #pragma once #include "../Base.h" -#include "cru/base/String.h" #include <vector> namespace cru::ui::document { class CRU_UI_API DocumentElementType : public Object { public: - explicit DocumentElementType(String name, + explicit DocumentElementType(std::string name, std::vector<DocumentElementType*> parents); ~DocumentElementType() override; public: - String GetName() const { return name_; } + std::string GetName() const { return name_; } const std::vector<DocumentElementType*>& GetParents() const { return parents_; } private: - String name_; + std::string name_; std::vector<DocumentElementType*> parents_; }; diff --git a/include/cru/ui/document/TextDocumentElement.h b/include/cru/ui/document/TextDocumentElement.h index 73a041ef..85ea6f2e 100644 --- a/include/cru/ui/document/TextDocumentElement.h +++ b/include/cru/ui/document/TextDocumentElement.h @@ -24,12 +24,12 @@ struct IDocumentLink : virtual Interface { class CRU_UI_API TextDocumentElement : public DocumentElement { public: - TextDocumentElement(String text, TextStyle style, IDocumentLink* link); + TextDocumentElement(std::string text, TextStyle style, IDocumentLink* link); ~TextDocumentElement() override; - String GetText() const { return text_; } - void SetText(String text); + std::string GetText() const { return text_; } + void SetText(std::string text); TextStyle GetStyle() const { return style_; } void SetStyle(TextStyle style); @@ -38,7 +38,7 @@ class CRU_UI_API TextDocumentElement : public DocumentElement { void SetLink(IDocumentLink link); private: - String text_; + std::string text_; TextStyle style_; IDocumentLink* link_; }; diff --git a/include/cru/ui/mapper/StringMapper.h b/include/cru/ui/mapper/StringMapper.h index 01f58c77..e41ee0f9 100644 --- a/include/cru/ui/mapper/StringMapper.h +++ b/include/cru/ui/mapper/StringMapper.h @@ -1,10 +1,10 @@ #pragma once #include "Mapper.h" -#include <cru/base/String.h> +#include <string> namespace cru::ui::mapper { -class CRU_UI_API StringMapper : public BasicMapper<String> { +class CRU_UI_API StringMapper : public BasicMapper<std::string> { public: StringMapper(); ~StringMapper(); @@ -14,7 +14,7 @@ class CRU_UI_API StringMapper : public BasicMapper<String> { bool SupportMapFromXml() override { return true; } protected: - String DoMapFromString(std::string str) override; - String DoMapFromXml(xml::XmlElementNode* node) override; + std::string DoMapFromString(std::string str) override; + std::string DoMapFromXml(xml::XmlElementNode* node) override; }; } // namespace cru::ui::mapper diff --git a/include/cru/ui/render/BorderRenderObject.h b/include/cru/ui/render/BorderRenderObject.h index 7bfa4290..001494a6 100644 --- a/include/cru/ui/render/BorderRenderObject.h +++ b/include/cru/ui/render/BorderRenderObject.h @@ -50,7 +50,7 @@ class CRU_UI_API BorderRenderObject : public SingleChildRenderObject { Rect GetPaddingRect() const override; Rect GetContentRect() const override; - String GetName() const override; + std::string GetName() const override; protected: Size OnMeasureContent(const MeasureRequirement& requirement, diff --git a/include/cru/ui/render/FlexLayoutRenderObject.h b/include/cru/ui/render/FlexLayoutRenderObject.h index 6c65ace3..bf68720a 100644 --- a/include/cru/ui/render/FlexLayoutRenderObject.h +++ b/include/cru/ui/render/FlexLayoutRenderObject.h @@ -104,7 +104,7 @@ class CRU_UI_API FlexLayoutRenderObject FlexLayoutRenderObject& operator=(FlexLayoutRenderObject&& other) = delete; ~FlexLayoutRenderObject() override = default; - String GetName() const override; + std::string GetName() const override; FlexDirection GetFlexDirection() const { return direction_; } void SetFlexDirection(FlexDirection direction) { diff --git a/include/cru/ui/render/MeasureRequirement.h b/include/cru/ui/render/MeasureRequirement.h index 544e0788..43bd3326 100644 --- a/include/cru/ui/render/MeasureRequirement.h +++ b/include/cru/ui/render/MeasureRequirement.h @@ -1,8 +1,6 @@ #pragma once #include "../Base.h" -#include "cru/base/String.h" - #include <algorithm> #include <format> #include <limits> @@ -113,13 +111,11 @@ class MeasureLength final { } } - std::string ToDebugStringUtf8() const { + std::string ToDebugString() const { return IsSpecified() ? std::to_string(GetLengthOrUndefined()) : "UNSPECIFIED"; } - String ToDebugString() const { return String::FromUtf8(ToDebugStringUtf8()); } - private: // -1 for not specify float length_; @@ -168,13 +164,11 @@ struct MeasureSize { }; } - std::string ToDebugStringUtf8() const { - return std::format("({}, {})", width.ToDebugStringUtf8(), - height.ToDebugStringUtf8()); + std::string ToDebugString() const { + return std::format("({}, {})", width.ToDebugString(), + height.ToDebugString()); } - String ToDebugString() const { return String::FromUtf8(ToDebugStringUtf8()); } - constexpr static MeasureSize NotSpecified() { return MeasureSize{MeasureLength::NotSpecified(), MeasureLength::NotSpecified()}; @@ -241,13 +235,11 @@ struct MeasureRequirement { return result; } - std::string ToDebugStringUtf8() const { - return std::format("{{min: {}, max: {}}}", min.ToDebugStringUtf8(), - max.ToDebugStringUtf8()); + std::string ToDebugString() const { + return std::format("{{min: {}, max: {}}}", min.ToDebugString(), + max.ToDebugString()); } - String ToDebugString() const { return String::FromUtf8(ToDebugStringUtf8()); } - constexpr static MeasureRequirement Merge(const MeasureRequirement& left, const MeasureRequirement& right) { return MeasureRequirement{MeasureSize::Min(left.max, right.max), diff --git a/include/cru/ui/render/RenderObject.h b/include/cru/ui/render/RenderObject.h index eba3b6c4..266045e3 100644 --- a/include/cru/ui/render/RenderObject.h +++ b/include/cru/ui/render/RenderObject.h @@ -2,7 +2,6 @@ #include "../Base.h" #include "MeasureRequirement.h" -#include "cru/base/String.h" #include <cru/platform/graphics/Painter.h> @@ -145,8 +144,8 @@ class CRU_UI_API RenderObject : public Object { void InvalidatePaint(); public: - virtual String GetName() const; - String GetDebugPathInTree() const; + virtual std::string GetName() const; + std::string GetDebugPathInTree() const; protected: // Size measure including margin and padding. Please reduce margin and padding diff --git a/include/cru/ui/render/ScrollRenderObject.h b/include/cru/ui/render/ScrollRenderObject.h index 180e927a..63a49aa3 100644 --- a/include/cru/ui/render/ScrollRenderObject.h +++ b/include/cru/ui/render/ScrollRenderObject.h @@ -60,7 +60,7 @@ class CRU_UI_API ScrollRenderObject : public SingleChildRenderObject { // Param margin is just for convenience and it will just add to the rect. void ScrollToContain(const Rect& rect, const Thickness& margin = Thickness{}); - String GetName() const override { return u"ScrollRenderObject"; } + std::string GetName() const override { return "ScrollRenderObject"; } bool IsMouseWheelScrollEnabled() const { return is_mouse_wheel_enabled_; } void SetMouseWheelScrollEnabled(bool enable); diff --git a/include/cru/ui/render/StackLayoutRenderObject.h b/include/cru/ui/render/StackLayoutRenderObject.h index 515e8f43..0d75d032 100644 --- a/include/cru/ui/render/StackLayoutRenderObject.h +++ b/include/cru/ui/render/StackLayoutRenderObject.h @@ -36,7 +36,7 @@ class CRU_UI_API StackLayoutRenderObject CRU_DELETE_MOVE(StackLayoutRenderObject) ~StackLayoutRenderObject() = default; - String GetName() const override { return u"StackLayoutRenderObject"; } + std::string GetName() const override { return "StackLayoutRenderObject"; } Alignment GetDefaultHorizontalAlignment() const { return default_vertical_alignment_; diff --git a/include/cru/ui/render/TextRenderObject.h b/include/cru/ui/render/TextRenderObject.h index b8d1882d..5b99ae98 100644 --- a/include/cru/ui/render/TextRenderObject.h +++ b/include/cru/ui/render/TextRenderObject.h @@ -93,7 +93,7 @@ class CRU_UI_API TextRenderObject : public RenderObject { RenderObject* HitTest(const Point& point) override; - String GetName() const override { return u"TextRenderObject"; } + std::string GetName() const override { return "TextRenderObject"; } void Draw(platform::graphics::IPainter* painter) override; diff --git a/include/cru/ui/render/TreeRenderObject.h b/include/cru/ui/render/TreeRenderObject.h index ef40f4d0..9cb8581e 100644 --- a/include/cru/ui/render/TreeRenderObject.h +++ b/include/cru/ui/render/TreeRenderObject.h @@ -57,7 +57,7 @@ class CRU_UI_API TreeRenderObject : public RenderObject { CRU_DELETE_MOVE(TreeRenderObject) ~TreeRenderObject() override; - String GetName() const override { return u"TreeRenderObject"; } + std::string GetName() const override { return "TreeRenderObject"; } TreeRenderObjectItem* GetRootItem() { return root_item_; } diff --git a/include/cru/ui/style/StyleRule.h b/include/cru/ui/style/StyleRule.h index 1ae2f0f1..e7f4d390 100644 --- a/include/cru/ui/style/StyleRule.h +++ b/include/cru/ui/style/StyleRule.h @@ -4,9 +4,6 @@ #include "Styler.h" #include "cru/base/ClonablePtr.h" -#include <memory> -#include <vector> - namespace cru::ui::style { /** * \brief An immutable style rule contains a condition and a styler. @@ -16,13 +13,13 @@ class CRU_UI_API StyleRule : public Object { public: static ClonablePtr<StyleRule> Create(ClonablePtr<Condition> condition, ClonablePtr<Styler> styler, - String name = {}) { + std::string name = {}) { return ClonablePtr<StyleRule>(new StyleRule( std::move(condition), std::move(styler), std::move(name))); } StyleRule(ClonablePtr<Condition> condition, ClonablePtr<Styler> styler, - String name = {}); + std::string name = {}); CRU_DEFAULT_COPY(StyleRule) CRU_DEFAULT_MOVE(StyleRule) @@ -30,16 +27,17 @@ class CRU_UI_API StyleRule : public Object { ~StyleRule() override = default; public: - String GetName() const { return name_; } + std::string GetName() const { return name_; } Condition* GetCondition() const { return condition_.get(); } Styler* GetStyler() const { return styler_.get(); } StyleRule WithNewCondition(ClonablePtr<Condition> condition, - String name = {}) const { + std::string name = {}) const { return StyleRule{std::move(condition), styler_, std::move(name)}; } - StyleRule WithNewStyler(ClonablePtr<Styler> styler, String name = {}) const { + StyleRule WithNewStyler(ClonablePtr<Styler> styler, + std::string name = {}) const { return StyleRule{condition_, std::move(styler), std::move(name)}; } @@ -48,6 +46,6 @@ class CRU_UI_API StyleRule : public Object { private: ClonablePtr<Condition> condition_; ClonablePtr<Styler> styler_; - String name_; + std::string name_; }; } // namespace cru::ui::style |