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

Button flashing "hover" style after releasing away from it #33553

Closed
MatthewJulian opened this issue Nov 12, 2019 · 3 comments · Fixed by #34781
Closed

Button flashing "hover" style after releasing away from it #33553

MatthewJulian opened this issue Nov 12, 2019 · 3 comments · Fixed by #34781
Milestone

Comments

@MatthewJulian
Copy link

MatthewJulian commented Nov 12, 2019

Godot version: 3.1.1 Stable

OS/device including version: Windows 10

Issue description: When you click off of a button (like when you change your mind), the button "flashes". I couldn't figure it out, but finally discovered that it looks like it's reporting as being "hovered" for a frame (or two). This doesn't really make sense, as it's not being hovered, and it looks weird when it flashes.
Here is a gif

Steps to reproduce: Use a button, click and hold, release outside of button. It'll flash

Minimal reproduction project:
ButtonProblem.zip

@MatthewJulian MatthewJulian changed the title Button showing "hover" style after clicking away from it Button flashing "hover" style after releasing away from it Nov 12, 2019
@MatthewJulian
Copy link
Author

Along with the above problems, the is_hovered() method returns true on the frame you let go (it shouldn't).
I assume this is a pretty easy fix for anyone familiar with the engine and how the GUI works. I couldn't figure it out in the engine, but I have a workaround I'm using with GDscript (it's not pretty though)

Thanks

@Calinou
Copy link
Member

Calinou commented Nov 19, 2019

@MatthewJulian Can you post the code for the workaround here, please? 🙂

@MatthewJulian
Copy link
Author

MatthewJulian commented Nov 19, 2019

Sure, here's what I'm currently doing on my TextureButtons:
image

extends Node2D
const normal := preload("res://normal.png")
const hover := preload("res://hover.png")

func _on_TextureButton_button_up() -> void:
	if !$TextureButton.get_rect().has_point(get_local_mouse_position()):
		$TextureButton.texture_hover = normal

func _on_TextureButton_mouse_entered() -> void:
	if $TextureButton.texture_hover != hover:
		$TextureButton.texture_hover = hover

So it changes the hover texture only when you release OUTSIDE of the button (that way, pressing it normally inside the button doesn't change). Then it just changes back to hover when your mouse enters it.

I was hesitant to post it because it's not really elegant, and also I don't know if changing the textures has a performance impact. (I assume it's just a matter of changing references, but you never know)

Also, and most importantly, this workaround doesn't address the underlying problem, which is that the internal state is_hovered() returns true when it shouldn't.

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.

4 participants