Merge pull request #25453 from nekomatata/button-keep-pressed-option
Add option to keep button pressed when moving cursor outside while pressing
This commit is contained in:
commit
a72552367e
|
@ -69,6 +69,9 @@
|
|||
<member name="toggle_mode" type="bool" setter="set_toggle_mode" getter="is_toggle_mode">
|
||||
If [code]true[/code], the button is in toggle mode. Makes the button flip state between pressed and unpressed each time its area is clicked.
|
||||
</member>
|
||||
<member name="keep_pressed_outside" type="bool" setter="set_keep_pressed_outside" getter="is_keep_pressed_outside">
|
||||
If [code]true[/code], the button stays pressed when moving the cursor outside the button while pressing it. Default value: [code]false[/code].
|
||||
</member>
|
||||
</members>
|
||||
<signals>
|
||||
<signal name="button_down">
|
||||
|
|
|
@ -376,7 +376,7 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const {
|
|||
bool pressing;
|
||||
if (status.press_attempt) {
|
||||
|
||||
pressing = status.pressing_inside;
|
||||
pressing = (status.pressing_inside || keep_pressed_outside);
|
||||
if (status.pressed)
|
||||
pressing = !pressing;
|
||||
} else {
|
||||
|
@ -446,6 +446,16 @@ Control::FocusMode BaseButton::get_enabled_focus_mode() const {
|
|||
return enabled_focus_mode;
|
||||
}
|
||||
|
||||
void BaseButton::set_keep_pressed_outside(bool p_on) {
|
||||
|
||||
keep_pressed_outside = p_on;
|
||||
}
|
||||
|
||||
bool BaseButton::is_keep_pressed_outside() const {
|
||||
|
||||
return keep_pressed_outside;
|
||||
}
|
||||
|
||||
void BaseButton::set_shortcut(const Ref<ShortCut> &p_shortcut) {
|
||||
|
||||
if (shortcut.is_null() == p_shortcut.is_null())
|
||||
|
@ -528,6 +538,8 @@ void BaseButton::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_draw_mode"), &BaseButton::get_draw_mode);
|
||||
ClassDB::bind_method(D_METHOD("set_enabled_focus_mode", "mode"), &BaseButton::set_enabled_focus_mode);
|
||||
ClassDB::bind_method(D_METHOD("get_enabled_focus_mode"), &BaseButton::get_enabled_focus_mode);
|
||||
ClassDB::bind_method(D_METHOD("set_keep_pressed_outside", "enabled"), &BaseButton::set_keep_pressed_outside);
|
||||
ClassDB::bind_method(D_METHOD("is_keep_pressed_outside"), &BaseButton::is_keep_pressed_outside);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_shortcut", "shortcut"), &BaseButton::set_shortcut);
|
||||
ClassDB::bind_method(D_METHOD("get_shortcut"), &BaseButton::get_shortcut);
|
||||
|
@ -549,6 +561,7 @@ void BaseButton::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::INT, "action_mode", PROPERTY_HINT_ENUM, "Button Press,Button Release"), "set_action_mode", "get_action_mode");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "button_mask", PROPERTY_HINT_FLAGS, "Mouse Left, Mouse Right, Mouse Middle"), "set_button_mask", "get_button_mask");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "enabled_focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), "set_enabled_focus_mode", "get_enabled_focus_mode");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_pressed_outside"), "set_keep_pressed_outside", "is_keep_pressed_outside");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shortcut", PROPERTY_HINT_RESOURCE_TYPE, "ShortCut"), "set_shortcut", "get_shortcut");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "group", PROPERTY_HINT_RESOURCE_TYPE, "ButtonGroup"), "set_button_group", "get_button_group");
|
||||
|
||||
|
@ -566,6 +579,7 @@ BaseButton::BaseButton() {
|
|||
|
||||
toggle_mode = false;
|
||||
shortcut_in_tooltip = true;
|
||||
keep_pressed_outside = false;
|
||||
status.pressed = false;
|
||||
status.press_attempt = false;
|
||||
status.hovering = false;
|
||||
|
|
|
@ -52,6 +52,7 @@ private:
|
|||
int button_mask;
|
||||
bool toggle_mode;
|
||||
bool shortcut_in_tooltip;
|
||||
bool keep_pressed_outside;
|
||||
FocusMode enabled_focus_mode;
|
||||
Ref<ShortCut> shortcut;
|
||||
|
||||
|
@ -110,6 +111,9 @@ public:
|
|||
void set_action_mode(ActionMode p_mode);
|
||||
ActionMode get_action_mode() const;
|
||||
|
||||
void set_keep_pressed_outside(bool p_on);
|
||||
bool is_keep_pressed_outside() const;
|
||||
|
||||
void set_button_mask(int p_mask);
|
||||
int get_button_mask() const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue