aboutsummaryrefslogtreecommitdiff
path: root/CruUI/ui/controls/toggle_button.h
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-16 23:48:54 +0800
committercrupest <crupest@outlook.com>2018-09-16 23:48:54 +0800
commit94c066a34900845297c41c134a9a910124a5833d (patch)
treefe717d4d80137c005ae3f2c1675ab3ba7d990b23 /CruUI/ui/controls/toggle_button.h
parent683419f2856d348436ca64cfd4b3abbfc73cda89 (diff)
downloadcru-94c066a34900845297c41c134a9a910124a5833d.tar.gz
cru-94c066a34900845297c41c134a9a910124a5833d.tar.bz2
cru-94c066a34900845297c41c134a9a910124a5833d.zip
Develop toggle button.
Diffstat (limited to 'CruUI/ui/controls/toggle_button.h')
-rw-r--r--CruUI/ui/controls/toggle_button.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/CruUI/ui/controls/toggle_button.h b/CruUI/ui/controls/toggle_button.h
new file mode 100644
index 00000000..d2e49473
--- /dev/null
+++ b/CruUI/ui/controls/toggle_button.h
@@ -0,0 +1,59 @@
+#pragma once
+
+#include "ui/control.h"
+
+namespace cru::ui::controls
+{
+ class ToggleButton : public Control
+ {
+ public:
+ static ToggleButton* Create()
+ {
+ return new ToggleButton();
+ }
+
+ protected:
+ ToggleButton();
+
+ public:
+ ToggleButton(const ToggleButton& other) = delete;
+ ToggleButton(ToggleButton&& other) = delete;
+ ToggleButton& operator=(const ToggleButton& other) = delete;
+ ToggleButton& operator=(ToggleButton&& other) = delete;
+ ~ToggleButton() override = default;
+
+ bool IsPointInside(const Point& point) override;
+
+ bool GetState() const
+ {
+ return state_;
+ }
+
+ void SetState(bool state);
+
+ void Toggle();
+
+ public:
+ events::ToggleEvent toggle_event;
+
+ protected:
+ virtual void OnToggle(events::ToggleEventArgs& args);
+
+ protected:
+ void OnDraw(ID2D1DeviceContext* device_context) override;
+
+ void OnMouseClickCore(events::MouseButtonEventArgs& args) override;
+
+ Size OnMeasure(const Size& available_size) override;
+
+ private:
+ void OnToggleInternal(bool new_state);
+
+ private:
+ bool state_ = false;
+
+ Microsoft::WRL::ComPtr<ID2D1RoundedRectangleGeometry> frame_path_;
+ Microsoft::WRL::ComPtr<ID2D1Brush> on_brush_;
+ Microsoft::WRL::ComPtr<ID2D1Brush> off_brush_;
+ };
+}