Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUI] Implement Properties that can Recursively Disable Child Controls' Focus Mode & Mouse Filter #97495

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Delsin-Yu
Copy link
Contributor

@Delsin-Yu Delsin-Yu commented Sep 26, 2024

Closes godotengine/godot-proposals#8200

This mechanism makes it easier for developers to manipulate a group of controls under one single control, such as disabling elements under a panel while retaining their visibility.

QQ2024927-173954.mp4

Previous Design

Add two properties and methods to `Control`: |PropertyName|Description| |--|--| |`focus_none_recursive`|When set to true, all recursive child nodes will have their `focus_mode` overridden to `None`.| |`mouse_ignore_recursive`|When set to true, all recursive child nodes will have their `mouse_filter` overridden to `Ignore`.|

These two properties do not change the original values in the child nodes.

MethodName Description
get_focus_mode_with_recursive get_focus_mode but takes parent's focus_none_recursive property into account.
get_mouse_filter_with_recursive get_mouse_filter but takes parent's mouse_ignore_recursive property into account.

The addition of this mechanism makes it easier for developers to manipulate a group of controls under one single control, such as disabling elements under a panel while retaining their visibility.

QQ2024926-224220.mp4

New Design

This new design enables child control to ignore the parent's recursive setting.
Added the following members to Control:

These two properties do not change the original values in the child nodes.

PropertyName EnumType Description
focus_recursive_behavior RecursiveBehavior Controls whether the recursive child nodes should have their focus_mode overridden to FOCUS_NONE when evaluating input.
mouse_recursive_behavior RecursiveBehavior Controls whether the recursive child nodes should have their mouse_filter overridden to MOUSE_FILTER_IGNORE when evaluating input.
MethodName Description
get_focus_mode_with_recursive get_focus_mode but takes parent's focus_recursive_behavior property into account.
get_mouse_filter_with_recursive get_mouse_filter but takes parent's mouse_recursive_behavior property into account.
EnumType Description
RECURSIVE_BEHAVIOR_INHERIT Inherits the associated behavior from the control's parent. This is the default for any newly created control.
RECURSIVE_BEHAVIOR_DISABLED The current control and all its recursive child controls have their associated behavior disabled, regardless of the parent control's configuration.
RECURSIVE_BEHAVIOR_ENABLED The current control and all its recursive child controls have their associated behavior enabled, regardless of the parent control's configuration.

Script Attached to the Buttons

@tool
extends Button

func _ready():
	add_theme_font_size_override("font_size", 35)

func _process(_delta:float):
	text = get_focus_mode_str(get_focus_mode_with_recursive()) + "\n" + get_mouse_filter_str(get_mouse_filter_with_recursive());

func get_focus_mode_str(mode: FocusMode):
	if mode == FocusMode.FOCUS_NONE:
		return "FocusMode.NONE";
	if mode == FocusMode.FOCUS_CLICK:
		return "FocusMode.CLICK";
	if mode == FocusMode.FOCUS_ALL:
		return "FocusMode.ALL";
	return "???";

func get_mouse_filter_str(filter: MouseFilter):
	if filter == MouseFilter.MOUSE_FILTER_STOP:
		return "MouseFilter.STOP";
	if filter == MouseFilter.MOUSE_FILTER_PASS:
		return "MouseFilter.PASS";
	if filter == MouseFilter.MOUSE_FILTER_IGNORE:
		return "MouseFilter.IGNORE";
	return "???";

@Delsin-Yu Delsin-Yu requested review from a team as code owners September 26, 2024 15:16
@Delsin-Yu Delsin-Yu force-pushed the control_recursive_disable_children branch from 08493b9 to 666636f Compare September 26, 2024 15:18
@AThousandShips AThousandShips added this to the 4.x milestone Sep 26, 2024
@AThousandShips AThousandShips changed the title [GUI] Implement Properties that can Recursively Disables Child Controls Focus Mode & Mouse Filter [GUI] Implement Properties that can Recursively Disable Child Controls' Focus Mode & Mouse Filter Sep 26, 2024
@Delsin-Yu Delsin-Yu force-pushed the control_recursive_disable_children branch 2 times, most recently from 7e5f6d2 to 853fbdf Compare September 26, 2024 16:00
@Delsin-Yu Delsin-Yu requested a review from a team as a code owner September 26, 2024 16:00
@Delsin-Yu Delsin-Yu force-pushed the control_recursive_disable_children branch from 853fbdf to f89de11 Compare September 26, 2024 16:05
@Delsin-Yu
Copy link
Contributor Author

I admit these properties can have a better naming

@Delsin-Yu Delsin-Yu force-pushed the control_recursive_disable_children branch from f89de11 to 4c13c1b Compare September 27, 2024 07:50
@Delsin-Yu Delsin-Yu requested a review from a team as a code owner September 27, 2024 07:50
@Delsin-Yu Delsin-Yu force-pushed the control_recursive_disable_children branch 2 times, most recently from 930ca6f to 4993de0 Compare September 27, 2024 09:43
@Delsin-Yu Delsin-Yu force-pushed the control_recursive_disable_children branch from 4993de0 to 4642d22 Compare September 27, 2024 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to disable focus on a control (and its children) with out modify the Control.SetFocusMode property
2 participants