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

is_hovered() is tied to button focus and not the actual cursor position #29326

Open
MAVREE opened this issue May 30, 2019 · 12 comments · Fixed by #47280
Open

is_hovered() is tied to button focus and not the actual cursor position #29326

MAVREE opened this issue May 30, 2019 · 12 comments · Fixed by #47280

Comments

@MAVREE
Copy link

MAVREE commented May 30, 2019

Godot version: 3.1.1 stable

OS/device including version: Windows 10

Issue description: Trying to check if a non-focused button is hovered with is_hovered() (while another one is focused) will return false even if the mouse is actually hovering it. Meanwhile if the focus is on that button and the mouse is off the button bounds it still returns true.
(I'm trying to make mouse and keyboard/gamepad live and work together by swapping "states")

Minimal reproduction project: Attached a simple 3.1.1 project with some buttons and the same functions i used to reproduce the problem, pressing E the function prints the return of is_hovered(). Also a gif showing the problem

2019-05-30_22-01-12

TestBugHover.zip

@KoBeWi
Copy link
Member

KoBeWi commented Jul 30, 2020

Looks fixed to me in Godot 3.2.3 rc2, but maybe I'm testing wrongly. @MAVREE Can you confirm?

@MAVREE
Copy link
Author

MAVREE commented Aug 4, 2020

Downloaded 3.2.3 rc2, it could be I'm doing what i would like to do wrong but print logs now tell me that the mouse is not hovering the button it is actually hovering if i previously navigate with the arrow keys. Also it still thinks the button is hovered with is_hovered() if it gets focused by navigating with the keyboard buttons while the mouse is not there. Sorry if I'm not describing it well, I'm posting another gif with a (probably) better visualization of what is happening, I only edited the print line to make it more descriptive (reuploading the zip of the project updated to 3.2.3 rc2)
Thanks for getting back to the issue!
(edited line 34 to: print("is " + lastFocusMouse.name + " hovered? -> " + ("yes" if lastFocusMouse.is_hovered() else "no")))
TestBugHover_3.2.3_rc2.zip

5TmNCOb6Qj

@KoBeWi
Copy link
Member

KoBeWi commented Aug 4, 2020

I found the code responsible for this problem:

if (p_what == NOTIFICATION_FOCUS_ENTER) {
status.hovering = true;
update();
}

Looks like in Button "hovered" basically means "focused". The easiest way to fix this would be renaming all current instances of "hover" into "focus" and then introduce a proper hovered property. Or just rename is_hovered() to is_focused() 🤔 Do we even need to know if the button is hovered?

@MAVREE
Copy link
Author

MAVREE commented Aug 4, 2020

There's has_focus(), I at least was needing the hovered property to do this specific check, to manage keyboard and mouse simultaneously. There could probably be a better way to manage it but, well, I don't know 😕

@KoBeWi
Copy link
Member

KoBeWi commented Aug 4, 2020

This can already be easily done with script, using mouse_entered() and mouse_exited() signals.

@abhiagnihotri01
Copy link

This bug is creating problem in my game. What changes can i do in godot 3.2.2 code to solve this is_hovered() problem.
Can you guys please help me to resolve this?

@Calinou
Copy link
Member

Calinou commented Apr 3, 2021

This bug is creating problem in my game. What changes can i do in godot 3.2.2 code to solve this is_hovered() problem.
Can you guys please help me to resolve this?

You can connect the Button's mouse_entered and mouse_exited signals to a method in a script to achieve this. See #29326 (comment)

@abhiagnihotri01
Copy link

Same Problem is coming in mouse_entered and mouse_exited signals as mentioned in bug #47433.
Is there any way by changing godot code i can resolve this ?

@Xioor
Copy link

Xioor commented Apr 24, 2021

Seems like mouse_exited does not get called if you are pressing the button, dragging outside the button while still holding.

@abhiagnihotri01
Copy link

I don't think the issue got resolved in mobile devices. I am still getting the same issue in Android.

@akien-mga
Copy link
Member

Did you compile the latest master branch to test?

@abhiagnihotri01
Copy link

i have added these changes in godot-3.3.2 and then compiled.

Issue reproduction -
Press the button and then drag outside button and then leave touch of screen. Now press the button again and leave touch of screen on the button (is_hovered() do not work in this condition). Now once again press the button and leave the touch of button on the button(is_hoovere() work in this condition).
So is_hovered() does not work when pressed second time.

@akien-mga akien-mga reopened this Jun 10, 2021
@KoBeWi KoBeWi removed this from the 4.0 milestone Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants