Option for BaseButton to keep button down when moving the pointer outside while pressed
This commit is contained in:
@ -379,7 +379,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 {
|
||||
@ -449,6 +449,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())
|
||||
@ -531,6 +541,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);
|
||||
@ -552,6 +564,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");
|
||||
|
||||
@ -569,6 +582,7 @@ BaseButton::BaseButton() {
|
||||
|
||||
toggle_mode = false;
|
||||
shortcut_in_tooltip = true;
|
||||
keep_pressed_outside = false;
|
||||
status.pressed = false;
|
||||
status.press_attempt = false;
|
||||
status.hovering = false;
|
||||
|
||||
Reference in New Issue
Block a user