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

Add a font_focus_hovered_color theme item to BaseButton #11788

Open
ettiSurreal opened this issue Feb 17, 2025 · 2 comments
Open

Add a font_focus_hovered_color theme item to BaseButton #11788

ettiSurreal opened this issue Feb 17, 2025 · 2 comments

Comments

@ettiSurreal
Copy link

Describe the project you are working on

UI in a game, trying to get simultaneous mouse and controller support.

Describe the problem or limitation you are having in your project

Godot_v4.4-beta3_win64_ZNFMCRYvnr.mp4

I made it so hovering over buttons immediately grabs their focus, as this seems like the most intuitive way to handle mouse + controller menu support (this also makes UI audio much easier to work with).
I have the following setup. The buttons are empty with white font when not focused, and white with black font when focused.
However the issue with the combination of these setups is that mouse hover effects take priority over focus effects, so I had to make it so the hover font color is black. But that creates another issue where if you focus a button using the controller/keyboard while the mouse is still hovering another button, the font stays black until you move your mouse off the button. This is where I got completely stuck.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

This has potentially many solutions, from adding an ability to disable hover effects (since they just get in the way in my case) or change their priority. But in this case the simplest solution would just be to add font_hover_focus_color to relevant controls.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Add font_hover_focus_color. It dictates the font color when a button is BOTH focused and hovered over.

If this enhancement will not be used often, can it be worked around with a few lines of script?

I cannot find a way to work around this.

Is there a reason why this should be core and not an add-on in the asset library?

Requires updating built-in classes to support.

@kleonc
Copy link
Member

kleonc commented Feb 17, 2025

If this enhancement will not be used often, can it be worked around with a few lines of script?

I cannot find a way to work around this.

As a workaround you could temporarily override Button's font_hover_color, something like:

for button: Button in buttons:
	var font_focus_color: Color = button.get_theme_color(&"font_focus_color")
	var font_hover_color: Color = button.get_theme_color(&"font_hover_color")
	button.focus_entered.connect(func():
		button.add_theme_color_override(&"font_hover_color", font_focus_color)
	)
	button.focus_exited.connect(func():
		button.add_theme_color_override(&"font_hover_color", font_hover_color)
	)

@Calinou
Copy link
Member

Calinou commented Feb 17, 2025

I made it so hovering over buttons immediately grabs their focus, as this seems like the most intuitive way to handle mouse + controller menu support (this also makes UI audio much easier to work with).

This is not how UI focus is meant to work. Focus does not follow the mouse in modern operating systems; instead, it's dictated by clicking.

Something like #10221 is better suited to addressing this problem, although I think it should only be a visual change and not affect the actual focus behavior, like :focus-visible in CSS.

@Calinou Calinou changed the title Add font_focus_hovered_color Add a font_focus_hovered_color theme item to BaseButton Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants