diff options
author | crupest <crupest@outlook.com> | 2020-01-01 22:52:01 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-01-01 22:52:01 +0800 |
commit | 36708e88596364e81dc9ba2fd3cbddbcaedeedc0 (patch) | |
tree | 0c7990b9e64c6ea1e9df7c01f3521c4fbf7ea2a0 /include/cru/ui/controls | |
parent | ae6f797561cdfa438ebef1fbbf94d784d315e655 (diff) | |
download | cru-36708e88596364e81dc9ba2fd3cbddbcaedeedc0.tar.gz cru-36708e88596364e81dc9ba2fd3cbddbcaedeedc0.tar.bz2 cru-36708e88596364e81dc9ba2fd3cbddbcaedeedc0.zip |
...
Diffstat (limited to 'include/cru/ui/controls')
-rw-r--r-- | include/cru/ui/controls/button.hpp | 48 |
1 files changed, 5 insertions, 43 deletions
diff --git a/include/cru/ui/controls/button.hpp b/include/cru/ui/controls/button.hpp index 60b1243f..b24a9934 100644 --- a/include/cru/ui/controls/button.hpp +++ b/include/cru/ui/controls/button.hpp @@ -19,27 +19,16 @@ struct ButtonStateStyle { }; struct ButtonStyle { - // corresponds to ButtonState::Normal + // corresponds to ClickState::None ButtonStateStyle normal; - // corresponds to ButtonState::Hover + // corresponds to ClickState::Hover ButtonStateStyle hover; - // corresponds to ButtonState::Press + // corresponds to ClickState::Press ButtonStateStyle press; - // corresponds to ButtonState::PressCancel + // corresponds to ClickState::PressInactive ButtonStateStyle press_cancel; }; -enum class ButtonState { - // mouse is not in it - Normal, - // mouse is in it and not pressed - Hover, - // mouse is pressed in it - Press, - // mouse is pressed outside button - PressCancel, -}; - class Button : public ContentControl { public: static constexpr std::string_view control_type = "Button"; @@ -56,9 +45,7 @@ class Button : public ContentControl { Button& operator=(Button&& other) = delete; ~Button() override = default; - std::string_view GetControlType() const final { - return control_type; - } + std::string_view GetControlType() const final { return control_type; } render::RenderObject* GetRenderObject() const override; @@ -66,37 +53,12 @@ class Button : public ContentControl { const ButtonStyle& GetStyle() const { return style_; } void SetStyle(ButtonStyle style); - ButtonState GetState() const { return state_; } - - // Get the trigger mouse button(s). Return value might be a union of Left, - // Middle and Right. - MouseButton GetTriggerButton() const { return trigger_button_; } - // Set the trigger mouse button(s). You can set multiple buttons by passing a - // union of Left, Middle and Right. If you disable a button when user is - // pressing the same one, click will be stopped. - // Default is only Left. - void SetTriggerButton(MouseButton newTrigger); - protected: void OnChildChanged(Control* old_child, Control* new_child) override; - virtual void OnStateChange(ButtonState oldState, ButtonState newState); - - private: - void SetState(ButtonState newState) { - if (state_ == newState) return; - const auto oldState = state_; - state_ = newState; - OnStateChange(oldState, newState); - } - private: std::unique_ptr<render::BorderRenderObject> render_object_{}; - ButtonState state_ = ButtonState::Normal; - - MouseButton trigger_button_ = MouseButton::Left; - ButtonStyle style_; ClickDetector click_detector_; |