diff options
author | crupest <crupest@outlook.com> | 2022-03-02 22:07:33 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-03-02 22:07:33 +0800 |
commit | 57353bd3acd97957cb5f970016fec52977cc6e95 (patch) | |
tree | 6e47a50f33466f7bcdce7c7aa9bf15b82fe4a58a /include/cru/ui | |
parent | 7adfe813c23d20abe936aa0624fd68e0112717b3 (diff) | |
download | cru-57353bd3acd97957cb5f970016fec52977cc6e95.tar.gz cru-57353bd3acd97957cb5f970016fec52977cc6e95.tar.bz2 cru-57353bd3acd97957cb5f970016fec52977cc6e95.zip |
...
Diffstat (limited to 'include/cru/ui')
-rw-r--r-- | include/cru/ui/ThemeManager.h | 2 | ||||
-rw-r--r-- | include/cru/ui/ThemeResourceDictionary.h | 8 | ||||
-rw-r--r-- | include/cru/ui/components/PopupButton.h | 22 | ||||
-rw-r--r-- | include/cru/ui/controls/Button.h | 1 | ||||
-rw-r--r-- | include/cru/ui/controls/IconButton.h | 93 | ||||
-rw-r--r-- | include/cru/ui/mapper/StringMapper.h | 18 | ||||
-rw-r--r-- | include/cru/ui/render/BorderRenderObject.h | 3 | ||||
-rw-r--r-- | include/cru/ui/render/GeometryRenderObject.h | 50 | ||||
-rw-r--r-- | include/cru/ui/render/RenderObject.h | 9 |
9 files changed, 193 insertions, 13 deletions
diff --git a/include/cru/ui/ThemeManager.h b/include/cru/ui/ThemeManager.h index 9917f219..faa8a1cf 100644 --- a/include/cru/ui/ThemeManager.h +++ b/include/cru/ui/ThemeManager.h @@ -37,6 +37,8 @@ class CRU_UI_API ThemeManager : public Object { Format(u"Theme resource key {} not exist.", key)); } + String GetResourceString(const String& key); + std::shared_ptr<platform::graphics::IBrush> GetResourceBrush( const String& key); diff --git a/include/cru/ui/ThemeResourceDictionary.h b/include/cru/ui/ThemeResourceDictionary.h index a303b466..7112ab27 100644 --- a/include/cru/ui/ThemeResourceDictionary.h +++ b/include/cru/ui/ThemeResourceDictionary.h @@ -63,14 +63,6 @@ class CRU_UI_API ThemeResourceDictionary : public Object { return resource; } - std::shared_ptr<platform::graphics::IBrush> GetResourceBrush( - const String& key); - - std::shared_ptr<platform::graphics::IFont> GetResourceFont(const String& key); - - std::shared_ptr<style::StyleRuleSet> GetResourceStyleRuleSet( - const String& key); - private: void UpdateResourceMap(xml::XmlElementNode* root_xml); diff --git a/include/cru/ui/components/PopupButton.h b/include/cru/ui/components/PopupButton.h index 37420ff6..c8ef9c50 100644 --- a/include/cru/ui/components/PopupButton.h +++ b/include/cru/ui/components/PopupButton.h @@ -3,6 +3,7 @@ #include "cru/ui/Base.h" #include "cru/ui/components/Menu.h" #include "cru/ui/controls/Button.h" +#include "cru/ui/controls/IconButton.h" #include "cru/ui/controls/Popup.h" #include "cru/ui/controls/TextBlock.h" @@ -35,4 +36,25 @@ class CRU_UI_API PopupMenuTextButton : public Component { Event<Index> menu_item_selected_event_; }; + +class CRU_UI_API PopupMenuIconButton : public Component { + public: + PopupMenuIconButton(); + ~PopupMenuIconButton() override; + + public: + ui::controls::Control* GetRootControl() override { return &button_; } + + ui::controls::IconButton* GetButton() { return &button_; } + + void SetMenuItems(std::vector<String> items); + + IEvent<Index>* MenuItemSelectedEvent() { return &menu_item_selected_event_; } + + private: + ui::controls::IconButton button_; + PopupMenu popup_menu_; + + Event<Index> menu_item_selected_event_; +}; } // namespace cru::ui::components diff --git a/include/cru/ui/controls/Button.h b/include/cru/ui/controls/Button.h index 1828dc57..6df23c62 100644 --- a/include/cru/ui/controls/Button.h +++ b/include/cru/ui/controls/Button.h @@ -1,7 +1,6 @@ #pragma once #include "SingleChildControl.h" -#include "../controls/SingleChildControl.h" #include "../helper/ClickDetector.h" #include "../render/BorderRenderObject.h" #include "IBorderControl.h" diff --git a/include/cru/ui/controls/IconButton.h b/include/cru/ui/controls/IconButton.h new file mode 100644 index 00000000..4f347b33 --- /dev/null +++ b/include/cru/ui/controls/IconButton.h @@ -0,0 +1,93 @@ +#pragma once +#include "NoChildControl.h" + +#include "../helper/ClickDetector.h" +#include "../render/BorderRenderObject.h" +#include "../render/GeometryRenderObject.h" +#include "IBorderControl.h" +#include "IClickableControl.h" +#include "cru/common/Event.h" + +namespace cru::ui::controls { +class CRU_UI_API IconButton : public NoChildControl, + public virtual IClickableControl, + public virtual IBorderControl { + public: + static constexpr StringView kControlType = u"IconButton"; + + public: + IconButton(); + IconButton(StringView icon_svg_path_data_string, const Rect& view_port); + ~IconButton() override; + + String GetControlType() const final { return kControlType.ToString(); } + + render::RenderObject* GetRenderObject() const override { + return container_render_object_.get(); + } + + public: + helper::ClickState GetClickState() override { + return click_detector_.GetState(); + } + + IEvent<helper::ClickState>* ClickStateChangeEvent() override { + return click_detector_.StateChangeEvent(); + } + + IEvent<helper::ClickEventArgs>* ClickEvent() { + return click_detector_.ClickEvent(); + } + + void ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) override { + container_render_object_->ApplyBorderStyle(style); + } + + std::shared_ptr<platform::graphics::IGeometry> GetIconGeometry() const { + 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); + } + + Rect GetIconViewPort() const { + return geometry_render_object_->GetViewPort(); + } + void SetIconViewPort(const Rect& view_port) { + geometry_render_object_->SetViewPort(view_port); + } + + std::shared_ptr<platform::graphics::IBrush> GetIconFillBrush() const { + return geometry_render_object_->GetFillBrush(); + } + void SetIconFillBrush(std::shared_ptr<platform::graphics::IBrush> brush) { + geometry_render_object_->SetFillBrush(std::move(brush)); + } + + std::shared_ptr<platform::graphics::IBrush> GetIconStrokeBrush() const { + return geometry_render_object_->GetStrokeBrush(); + } + void SetIconStrokeBrush(std::shared_ptr<platform::graphics::IBrush> brush) { + geometry_render_object_->SetStrokeBrush(std::move(brush)); + } + + float GetIconStrokeWidth() const { + return geometry_render_object_->GetStrokeWidth(); + } + void SetIconStrokeWidth(float width) { + geometry_render_object_->SetStrokeWidth(width); + } + + void SetIconFillColor(const Color& color); + void SetIconWithSvgPathDataString(StringView icon_svg_path_data_string, + const Rect& view_port); + void SetIconWithSvgPathDataStringResourceKey( + StringView icon_svg_path_data_string_resource_key, const Rect& view_port); + + private: + std::unique_ptr<render::BorderRenderObject> container_render_object_; + std::unique_ptr<render::GeometryRenderObject> geometry_render_object_; + helper::ClickDetector click_detector_; +}; +} // namespace cru::ui::controls diff --git a/include/cru/ui/mapper/StringMapper.h b/include/cru/ui/mapper/StringMapper.h new file mode 100644 index 00000000..8a907591 --- /dev/null +++ b/include/cru/ui/mapper/StringMapper.h @@ -0,0 +1,18 @@ +#pragma once +#include "Mapper.h" + +namespace cru::ui::mapper { +class CRU_UI_API StringMapper : public BasicMapper<String> { + public: + StringMapper(); + ~StringMapper(); + + public: + bool SupportMapFromString() override { return true; } + bool SupportMapFromXml() override { return true; } + + protected: + String DoMapFromString(String str) override; + 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 a71cd6a0..8de0eea3 100644 --- a/include/cru/ui/render/BorderRenderObject.h +++ b/include/cru/ui/render/BorderRenderObject.h @@ -44,7 +44,8 @@ class CRU_UI_API BorderRenderObject : public SingleChildRenderObject { RenderObject* HitTest(const Point& point) override; void Draw(platform::graphics::IPainter* painter) override; - Thickness GetOuterSpaceThickness() const override; + Thickness GetTotalSpaceThickness() const override; + Thickness GetInnerSpaceThickness() const override; Rect GetPaddingRect() const override; Rect GetContentRect() const override; diff --git a/include/cru/ui/render/GeometryRenderObject.h b/include/cru/ui/render/GeometryRenderObject.h new file mode 100644 index 00000000..6c5702ae --- /dev/null +++ b/include/cru/ui/render/GeometryRenderObject.h @@ -0,0 +1,50 @@ +#pragma once +#include "RenderObject.h" +#include "cru/platform/graphics/Brush.h" +#include "cru/platform/graphics/Geometry.h" + +#include <optional> + +namespace cru::ui::render { +class GeometryRenderObject : public RenderObject { + public: + GeometryRenderObject(); + + CRU_DELETE_COPY(GeometryRenderObject) + CRU_DELETE_MOVE(GeometryRenderObject) + + ~GeometryRenderObject() override; + + public: + void Draw(platform::graphics::IPainter* painter) override; + RenderObject* HitTest(const Point& point) override; + + std::shared_ptr<platform::graphics::IGeometry> GetGeometry() const; + void SetGeometry(std::shared_ptr<platform::graphics::IGeometry> geometry, + std::optional<Rect> view_port = std::nullopt); + + Rect GetViewPort() const; + void SetViewPort(const Rect& view_port); + + std::shared_ptr<platform::graphics::IBrush> GetFillBrush() const; + void SetFillBrush(std::shared_ptr<platform::graphics::IBrush> brush); + + std::shared_ptr<platform::graphics::IBrush> GetStrokeBrush() const; + void SetStrokeBrush(std::shared_ptr<platform::graphics::IBrush> brush); + + float GetStrokeWidth() const; + void SetStrokeWidth(float width); + + protected: + Size OnMeasureContent(const MeasureRequirement& requirement, + const MeasureSize& preferred_size) override; + void OnLayoutContent(const Rect& content_rect) override; + + private: + std::shared_ptr<platform::graphics::IGeometry> geometry_ = nullptr; + Rect view_port_{}; + std::shared_ptr<platform::graphics::IBrush> fill_brush_ = nullptr; + std::shared_ptr<platform::graphics::IBrush> stroke_brush_ = nullptr; + float stroke_width_ = 0; +}; +} // namespace cru::ui::render diff --git a/include/cru/ui/render/RenderObject.h b/include/cru/ui/render/RenderObject.h index e8dc3b17..9f2b69d9 100644 --- a/include/cru/ui/render/RenderObject.h +++ b/include/cru/ui/render/RenderObject.h @@ -32,8 +32,9 @@ namespace cru::ui::render { * void Draw(platform::graphics::IPainter* painter) override; * RenderObject* HitTest(const Point& point) override; * protected: - * Size OnMeasureContent(const MeasureRequirement& requirement) override; - * void OnLayoutContent(const Rect& content_rect) override; + * Size OnMeasureContent(const MeasureRequirement& requirement, const + * MeasureSize& preferred_size) override; void OnLayoutContent(const Rect& + * content_rect) override; */ class CRU_UI_API RenderObject : public Object { CRU_DEFINE_CLASS_LOG_TAG(u"RenderObject") @@ -93,7 +94,9 @@ class CRU_UI_API RenderObject : public Object { // This will set offset of this render object and call OnLayoutCore. void Layout(const Point& offset); - virtual Thickness GetOuterSpaceThickness() const; + virtual Thickness GetTotalSpaceThickness() const; + virtual Thickness GetInnerSpaceThickness() const; + virtual Rect GetPaddingRect() const; virtual Rect GetContentRect() const; |