GUI Focus mode improvements
Exposed `get_focus_mode()` to the script Added `focus_mode` to the property panels for line-edit and sliders Added `enabled_focus_mode` to the property panels for buttons enabled_focus_mode is used when button is enabled/disabled
This commit is contained in:
parent
8a6933afb1
commit
0ccf153a15
@ -5655,6 +5655,20 @@
|
|||||||
Return the visual state used to draw the button. This is useful mainly when implementing your own draw code by either overriding _draw() or connecting to "draw" signal. The visual state of the button is defined by the DRAW_* enum.
|
Return the visual state used to draw the button. This is useful mainly when implementing your own draw code by either overriding _draw() or connecting to "draw" signal. The visual state of the button is defined by the DRAW_* enum.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="set_enabled_focus_mode">
|
||||||
|
<argument index="0" name="mode" type="int">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Sets the focus access mode to use when switching between enabled/disabled (see [method Control.set_focus_mode] and [method set_disabled]).
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="get_enabled_focus_mode" qualifiers="const">
|
||||||
|
<return type="int">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Returns focus access mode used when switching between enabled/disabled (see [method Control.set_focus_mode] and [method set_disabled]).
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
</methods>
|
</methods>
|
||||||
<signals>
|
<signals>
|
||||||
<signal name="released">
|
<signal name="released">
|
||||||
@ -9088,6 +9102,13 @@
|
|||||||
Set the focus access mode for the control (FOCUS_NONE, FOCUS_CLICK, FOCUS_ALL). Only one Control can be focused at the same time, and it will receive keyboard signals.
|
Set the focus access mode for the control (FOCUS_NONE, FOCUS_CLICK, FOCUS_ALL). Only one Control can be focused at the same time, and it will receive keyboard signals.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="get_focus_mode" qualifiers="const">
|
||||||
|
<return type="int">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Returns the focus access mode for the control (FOCUS_NONE, FOCUS_CLICK, FOCUS_ALL) (see [method set_focus_mode]).
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="has_focus" qualifiers="const">
|
<method name="has_focus" qualifiers="const">
|
||||||
<return type="bool">
|
<return type="bool">
|
||||||
</return>
|
</return>
|
||||||
|
@ -289,7 +289,7 @@ void BaseButton::set_disabled(bool p_disabled) {
|
|||||||
if (p_disabled)
|
if (p_disabled)
|
||||||
set_focus_mode(FOCUS_NONE);
|
set_focus_mode(FOCUS_NONE);
|
||||||
else
|
else
|
||||||
set_focus_mode(FOCUS_ALL);
|
set_focus_mode(enabled_focus_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseButton::is_disabled() const {
|
bool BaseButton::is_disabled() const {
|
||||||
@ -377,7 +377,18 @@ bool BaseButton::get_click_on_press() const {
|
|||||||
return status.click_on_press;
|
return status.click_on_press;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseButton::set_enabled_focus_mode(FocusMode p_mode) {
|
||||||
|
|
||||||
|
enabled_focus_mode = p_mode;
|
||||||
|
if (!status.disabled) {
|
||||||
|
set_focus_mode( p_mode );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Control::FocusMode BaseButton::get_enabled_focus_mode() const {
|
||||||
|
|
||||||
|
return enabled_focus_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void BaseButton::_bind_methods() {
|
void BaseButton::_bind_methods() {
|
||||||
@ -393,6 +404,8 @@ void BaseButton::_bind_methods() {
|
|||||||
ObjectTypeDB::bind_method(_MD("set_click_on_press","enable"),&BaseButton::set_click_on_press);
|
ObjectTypeDB::bind_method(_MD("set_click_on_press","enable"),&BaseButton::set_click_on_press);
|
||||||
ObjectTypeDB::bind_method(_MD("get_click_on_press"),&BaseButton::get_click_on_press);
|
ObjectTypeDB::bind_method(_MD("get_click_on_press"),&BaseButton::get_click_on_press);
|
||||||
ObjectTypeDB::bind_method(_MD("get_draw_mode"),&BaseButton::get_draw_mode);
|
ObjectTypeDB::bind_method(_MD("get_draw_mode"),&BaseButton::get_draw_mode);
|
||||||
|
ObjectTypeDB::bind_method(_MD("set_enabled_focus_mode","mode"),&BaseButton::set_enabled_focus_mode);
|
||||||
|
ObjectTypeDB::bind_method(_MD("get_enabled_focus_mode"),&BaseButton::get_enabled_focus_mode);
|
||||||
|
|
||||||
BIND_VMETHOD(MethodInfo("_pressed"));
|
BIND_VMETHOD(MethodInfo("_pressed"));
|
||||||
BIND_VMETHOD(MethodInfo("_toggled",PropertyInfo(Variant::BOOL,"pressed")));
|
BIND_VMETHOD(MethodInfo("_toggled",PropertyInfo(Variant::BOOL,"pressed")));
|
||||||
@ -404,6 +417,7 @@ void BaseButton::_bind_methods() {
|
|||||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "toggle_mode"), _SCS("set_toggle_mode"), _SCS("is_toggle_mode"));
|
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "toggle_mode"), _SCS("set_toggle_mode"), _SCS("is_toggle_mode"));
|
||||||
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "is_pressed"), _SCS("set_pressed"), _SCS("is_pressed"));
|
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "is_pressed"), _SCS("set_pressed"), _SCS("is_pressed"));
|
||||||
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "click_on_press"), _SCS("set_click_on_press"), _SCS("get_click_on_press"));
|
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "click_on_press"), _SCS("set_click_on_press"), _SCS("get_click_on_press"));
|
||||||
|
ADD_PROPERTY( PropertyInfo( Variant::INT,"enabled_focus_mode", PROPERTY_HINT_ENUM, "None,Click,All" ), _SCS("set_enabled_focus_mode"), _SCS("get_enabled_focus_mode") );
|
||||||
|
|
||||||
|
|
||||||
BIND_CONSTANT( DRAW_NORMAL );
|
BIND_CONSTANT( DRAW_NORMAL );
|
||||||
@ -424,6 +438,7 @@ BaseButton::BaseButton() {
|
|||||||
status.click_on_press=false;
|
status.click_on_press=false;
|
||||||
status.pressing_button=0;
|
status.pressing_button=0;
|
||||||
set_focus_mode( FOCUS_ALL );
|
set_focus_mode( FOCUS_ALL );
|
||||||
|
enabled_focus_mode = FOCUS_ALL;
|
||||||
group=NULL;
|
group=NULL;
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ class BaseButton : public Control {
|
|||||||
OBJ_TYPE( BaseButton, Control );
|
OBJ_TYPE( BaseButton, Control );
|
||||||
|
|
||||||
bool toggle_mode;
|
bool toggle_mode;
|
||||||
|
FocusMode enabled_focus_mode;
|
||||||
|
|
||||||
struct Status {
|
struct Status {
|
||||||
|
|
||||||
@ -97,6 +98,9 @@ public:
|
|||||||
void set_click_on_press(bool p_click_on_press);
|
void set_click_on_press(bool p_click_on_press);
|
||||||
bool get_click_on_press() const;
|
bool get_click_on_press() const;
|
||||||
|
|
||||||
|
void set_enabled_focus_mode(FocusMode p_mode);
|
||||||
|
FocusMode get_enabled_focus_mode() const;
|
||||||
|
|
||||||
|
|
||||||
BaseButton();
|
BaseButton();
|
||||||
~BaseButton();
|
~BaseButton();
|
||||||
|
@ -2265,6 +2265,7 @@ void Control::_bind_methods() {
|
|||||||
ObjectTypeDB::bind_method(_MD("set_area_as_parent_rect","margin"),&Control::set_area_as_parent_rect,DEFVAL(0));
|
ObjectTypeDB::bind_method(_MD("set_area_as_parent_rect","margin"),&Control::set_area_as_parent_rect,DEFVAL(0));
|
||||||
ObjectTypeDB::bind_method(_MD("show_modal","exclusive"),&Control::show_modal,DEFVAL(false));
|
ObjectTypeDB::bind_method(_MD("show_modal","exclusive"),&Control::show_modal,DEFVAL(false));
|
||||||
ObjectTypeDB::bind_method(_MD("set_focus_mode","mode"),&Control::set_focus_mode);
|
ObjectTypeDB::bind_method(_MD("set_focus_mode","mode"),&Control::set_focus_mode);
|
||||||
|
ObjectTypeDB::bind_method(_MD("get_focus_mode"),&Control::get_focus_mode);
|
||||||
ObjectTypeDB::bind_method(_MD("has_focus"),&Control::has_focus);
|
ObjectTypeDB::bind_method(_MD("has_focus"),&Control::has_focus);
|
||||||
ObjectTypeDB::bind_method(_MD("grab_focus"),&Control::grab_focus);
|
ObjectTypeDB::bind_method(_MD("grab_focus"),&Control::grab_focus);
|
||||||
ObjectTypeDB::bind_method(_MD("release_focus"),&Control::release_focus);
|
ObjectTypeDB::bind_method(_MD("release_focus"),&Control::release_focus);
|
||||||
|
@ -1027,7 +1027,7 @@ void LineEdit::_bind_methods() {
|
|||||||
ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "max_length" ), _SCS("set_max_length"),_SCS("get_max_length") );
|
ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "max_length" ), _SCS("set_max_length"),_SCS("get_max_length") );
|
||||||
ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "editable" ), _SCS("set_editable"),_SCS("is_editable") );
|
ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "editable" ), _SCS("set_editable"),_SCS("is_editable") );
|
||||||
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "secret" ), _SCS("set_secret"),_SCS("is_secret") );
|
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "secret" ), _SCS("set_secret"),_SCS("is_secret") );
|
||||||
|
ADD_PROPERTY( PropertyInfo( Variant::INT,"focus_mode", PROPERTY_HINT_ENUM, "None,Click,All" ), _SCS("set_focus_mode"), _SCS("get_focus_mode") );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +119,6 @@ void LinkButton::_bind_methods() {
|
|||||||
|
|
||||||
LinkButton::LinkButton() {
|
LinkButton::LinkButton() {
|
||||||
underline_mode=UNDERLINE_MODE_ALWAYS;
|
underline_mode=UNDERLINE_MODE_ALWAYS;
|
||||||
set_focus_mode(FOCUS_NONE);
|
set_enabled_focus_mode(FOCUS_NONE);
|
||||||
set_default_cursor_shape(CURSOR_POINTING_HAND);
|
set_default_cursor_shape(CURSOR_POINTING_HAND);
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ MenuButton::MenuButton() {
|
|||||||
|
|
||||||
|
|
||||||
set_flat(true);
|
set_flat(true);
|
||||||
set_focus_mode(FOCUS_NONE);
|
set_enabled_focus_mode(FOCUS_NONE);
|
||||||
popup = memnew( PopupMenu );
|
popup = memnew( PopupMenu );
|
||||||
popup->hide();
|
popup->hide();
|
||||||
add_child(popup);
|
add_child(popup);
|
||||||
|
@ -237,6 +237,7 @@ void Slider::_bind_methods() {
|
|||||||
|
|
||||||
ADD_PROPERTY( PropertyInfo( Variant::INT, "tick_count", PROPERTY_HINT_RANGE,"0,4096,1"), _SCS("set_ticks"), _SCS("get_ticks") );
|
ADD_PROPERTY( PropertyInfo( Variant::INT, "tick_count", PROPERTY_HINT_RANGE,"0,4096,1"), _SCS("set_ticks"), _SCS("get_ticks") );
|
||||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "ticks_on_borders" ), _SCS("set_ticks_on_borders"), _SCS("get_ticks_on_borders") );
|
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "ticks_on_borders" ), _SCS("set_ticks_on_borders"), _SCS("get_ticks_on_borders") );
|
||||||
|
ADD_PROPERTY( PropertyInfo( Variant::INT,"focus_mode", PROPERTY_HINT_ENUM, "None,Click,All" ), _SCS("set_focus_mode"), _SCS("get_focus_mode") );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user