aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/controls
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-03-02 22:07:33 +0800
committercrupest <crupest@outlook.com>2022-03-02 22:07:33 +0800
commit57353bd3acd97957cb5f970016fec52977cc6e95 (patch)
tree6e47a50f33466f7bcdce7c7aa9bf15b82fe4a58a /include/cru/ui/controls
parent7adfe813c23d20abe936aa0624fd68e0112717b3 (diff)
downloadcru-57353bd3acd97957cb5f970016fec52977cc6e95.tar.gz
cru-57353bd3acd97957cb5f970016fec52977cc6e95.tar.bz2
cru-57353bd3acd97957cb5f970016fec52977cc6e95.zip
...
Diffstat (limited to 'include/cru/ui/controls')
-rw-r--r--include/cru/ui/controls/Button.h1
-rw-r--r--include/cru/ui/controls/IconButton.h93
2 files changed, 93 insertions, 1 deletions
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