diff options
author | crupest <crupest@outlook.com> | 2018-11-07 21:40:04 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-11-07 21:40:04 +0800 |
commit | efdce672123284847bd7fb6f12ac1ec96f28f3ef (patch) | |
tree | 298e6313e9a48c5867b2355242b78d3cd23fdc61 /src/ui/controls/toggle_button.hpp | |
parent | 634dab6ad2c9e4675beacfb77ac02b2d43cab132 (diff) | |
download | cru-efdce672123284847bd7fb6f12ac1ec96f28f3ef.tar.gz cru-efdce672123284847bd7fb6f12ac1ec96f28f3ef.tar.bz2 cru-efdce672123284847bd7fb6f12ac1ec96f28f3ef.zip |
Make all header *.hpp .
Diffstat (limited to 'src/ui/controls/toggle_button.hpp')
-rw-r--r-- | src/ui/controls/toggle_button.hpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/ui/controls/toggle_button.hpp b/src/ui/controls/toggle_button.hpp new file mode 100644 index 00000000..5de40ca5 --- /dev/null +++ b/src/ui/controls/toggle_button.hpp @@ -0,0 +1,65 @@ +#pragma once + +#include "ui/control.hpp" + +namespace cru::ui::controls +{ + class ToggleButton : public Control + { + public: + static constexpr auto control_type = L"ToggleButton"; + + 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; + + StringView GetControlType() const override final; + + 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 OnDrawContent(ID2D1DeviceContext* device_context) override; + + void OnMouseClickCore(events::MouseButtonEventArgs& args) override; + + Size OnMeasureContent(const Size& available_size) override; + + private: + void RaiseToggleEvent(bool new_state); + + private: + bool state_ = false; + + float current_circle_position_; + + Microsoft::WRL::ComPtr<ID2D1RoundedRectangleGeometry> frame_path_; + Microsoft::WRL::ComPtr<ID2D1Brush> on_brush_; + Microsoft::WRL::ComPtr<ID2D1Brush> off_brush_; + }; +} |