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

TextureButton doesn't show Pressed image when clicked in V3.4 like it did in V3.3 stable #55146

Closed
furroy opened this issue Nov 20, 2021 · 9 comments

Comments

@furroy
Copy link

furroy commented Nov 20, 2021

Godot version

3.4 stable

System information

Win10, 3080

Issue description

When a normal (toggle mode is false) TextureButton is clicked, the Pressed image should show as long as the mouse is still over the button and left mouse is held down.

This last worked in V3.3 stable

Steps to reproduce

Make TextureButton in test scene
Ensure toggle mode is false
Add textures for Normal, Pressed, Hover, Focus
Run scene
Click and hold down button, it always shows Focus and never Pressed

Minimal reproduction project

TextureButton.zip

@furroy furroy changed the title TextureButton doesn show Pressed image when clicked in V3.4 like it did in V3.3 stable TextureButton doesn't show Pressed image when clicked in V3.4 like it did in V3.3 stable Nov 20, 2021
@kleonc

This comment has been minimized.

@furroy
Copy link
Author

furroy commented Nov 20, 2021

You didn't assign the Focused image.

@kleonc
Copy link
Member

kleonc commented Nov 20, 2021

Edit: seems like a duplicate of #3926.


You didn't assign the Focused image.

Right, didn't read careful enough. In fact, I didn't assign a single texture, just run the minimal reproduction project.

So you're right. It's indeed reproducible without a problem. But you're not right about it working differently in 3.3, it works the same way in there. It seems it behaves like that even in 3.0. And indeed, the relevant part of the source code hasn't changed throughout the versions: if focused, focused texture is being drawn last, despite of what texture was drawn previously.

Relevant source code (click to expand)
  • 3.0:
    if (tile)
    draw_texture_rect(texdraw, Rect2(ofs, size), tile);
    else
    draw_texture_rect_region(texdraw, Rect2(ofs, size), tex_regin);
    }
    if (has_focus() && focused.is_valid()) {
    Rect2 drect(Point2(), get_size());
    draw_texture_rect(focused, drect, false);
    };
  • 3.3:
    if (_tile) {
    draw_texture_rect(texdraw, _position_rect, _tile);
    } else {
    draw_texture_rect_region(texdraw, _position_rect, _texture_region);
    }
    } else {
    _position_rect = Rect2();
    }
    if (has_focus() && focused.is_valid()) {
    draw_texture_rect(focused, _position_rect, false);
    };
  • 3.4:
    if (_tile) {
    draw_texture_rect(texdraw, Rect2(ofs, size), _tile);
    } else {
    draw_texture_rect_region(texdraw, Rect2(ofs, size), _texture_region);
    }
    } else {
    _position_rect = Rect2();
    }
    if (has_focus() && focused.is_valid()) {
    draw_texture_rect(focused, Rect2(ofs, size), false);
    };

So to make it clear: when you're pressing the button pressed texture is being drawn but focused texture is being drawn on top of it.
I'm guessing focused texture is assumed to be some type of an overlay (for example just a border, with transparent middle part). In such a case it would work as expected.

Your example with "just a border" focused texture:
button_stone_focus2
Godot_v3 3-stable_win64_NPWHYtuK3Y
59JPA3R1o2

@furroy
Copy link
Author

furroy commented Nov 20, 2021

I dunno, I gave out a demo of my game built with Godot_v3.3-stable_win64.exe and it worked before. Hmm you're right though, somehow it didn't save the Focused image in my test project. Doh. Thank you for the workaround!

@Calinou
Copy link
Member

Calinou commented Nov 20, 2021

The Focused texture is meant to be an overlay over existing images, so that the focused state can be indicated regardless of the current button's state. The same also applies to Button. This is expected behavior, closing.

If you don't want the focus texture to get in the way, use an empty texture for the focused style. However, this will harm keyboard/controller menu navigation since there will no longer be visual feedback for the currently focused menu item.

@kleonc
Copy link
Member

kleonc commented Nov 20, 2021

@Calinou I don't see anything about it in the TextureButton's docs, it should probably be mentioned in there.

@Calinou
Copy link
Member

Calinou commented Nov 20, 2021

@Calinou I don't see anything about it in the TextureButton's docs, it should probably be mentioned in there.

Done: #55165

@neepsnikeep
Copy link

Still nothing in the docs, please give some info on this there. Took me way too long to find this issue in order to find out what's going on.

@Calinou
Copy link
Member

Calinou commented Nov 23, 2024

Still nothing in the docs, please give some info on this there. Took me way too long to find this issue in order to find out what's going on.

This is already documented in the class reference: #55165

I've opened a PR to document this in the manual, but I couldn't find a great location for the added note: godotengine/godot-docs#10313

Also, implementing godotengine/godot-proposals#6577 would address the original problem mentioned here.

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

5 participants