aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/cru/platform/GraphicsBase.h4
-rw-r--r--include/cru/platform/graphics/Geometry.h5
-rw-r--r--include/cru/ui/ThemeManager.h2
-rw-r--r--include/cru/ui/ThemeResourceDictionary.h8
-rw-r--r--include/cru/ui/components/PopupButton.h22
-rw-r--r--include/cru/ui/controls/Button.h1
-rw-r--r--include/cru/ui/controls/IconButton.h93
-rw-r--r--include/cru/ui/mapper/StringMapper.h18
-rw-r--r--include/cru/ui/render/BorderRenderObject.h3
-rw-r--r--include/cru/ui/render/GeometryRenderObject.h50
-rw-r--r--include/cru/ui/render/RenderObject.h9
11 files changed, 201 insertions, 14 deletions
diff --git a/include/cru/platform/GraphicsBase.h b/include/cru/platform/GraphicsBase.h
index 8fb9a3af..62a8bf29 100644
--- a/include/cru/platform/GraphicsBase.h
+++ b/include/cru/platform/GraphicsBase.h
@@ -1,9 +1,9 @@
#pragma once
#include "cru/common/Base.h"
+#include "cru/common/Format.h"
#include "cru/common/Range.h"
#include "cru/common/String.h"
-#include "cru/common/Format.h"
#include <cstdint>
#include <limits>
@@ -25,6 +25,8 @@ struct Point final {
return *this;
}
+ constexpr Point Negate() const { return Point(-x, -y); }
+
float x = 0;
float y = 0;
};
diff --git a/include/cru/platform/graphics/Geometry.h b/include/cru/platform/graphics/Geometry.h
index 1c2bd1f7..19620789 100644
--- a/include/cru/platform/graphics/Geometry.h
+++ b/include/cru/platform/graphics/Geometry.h
@@ -1,6 +1,8 @@
#pragma once
#include "Resource.h"
+#include <memory>
+
namespace cru::platform::graphics {
struct CRU_PLATFORM_GRAPHICS_API IGeometry : virtual IGraphicsResource {
virtual bool FillContains(const Point& point) = 0;
@@ -59,4 +61,7 @@ struct CRU_PLATFORM_GRAPHICS_API IGeometryBuilder : virtual IGraphicsResource {
void ParseAndApplySvgPathData(StringView path_d);
};
+
+std::unique_ptr<IGeometry> CRU_PLATFORM_GRAPHICS_API
+CreateGeometryFromSvgPathData(IGraphicsFactory* factory, StringView path_d);
} // namespace cru::platform::graphics
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;