-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 Button::image_and_text #832
Conversation
Thanks!
I think this would be worth trying, basically adding a constructor |
Thanks for the feedback and taking a look! I've made a new version, committed to the same branch, that does it to the existing Button implementation, instead of that new one. Does lead to alot less code, and the changes to the existing button were tried to be as small as possible. With this I also added a convenience function like the "button" one called "button_with_image", so you don't have to call the full Button::image_and_text. I saw that there were some validation checks that were run, I ran the same ones locally and fixed a few things, code cleanliness wise. Also, not sure the best way you'd like the commits to be presented, I can do a squash on this branch if you're happy with these changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to demonstrate this, perhaps in egui_glium/examples/native_texture.rs
(which has an actual texture loaded). if ui.button("Quit").clicked() {
could be replaced with the new Button::image_and_text
I re-based with the latest and removed the ui... function. I added the change to the example glium but not sure how to test it, I didn't see a way to run it like you can with the demo, but it should work. |
|
Been using egui with the sdl2 backend for a short while now and it's been a great experience, making UI has been nicely easy with it after learning it.
One of the things I was wanted to do which the integration with sdl2 made possible was to have a hybrid mouse and controller UI, where someone could navigate and press buttons using the controller as well.
Part of that I wanted to be able to have a button with a controller icon in it, to show which one could trigger it. I created a "ImageButtonWithText", which tried to merge the ideas of an ImageButton and a Button, similar to how the Radio Button or Checkbox ones work.
This was mainly copying and pasting the Button implementation and adding the necessary spacing and positions for putting the image and text inside the button. It worked well visually, as can be seen in the screenshot below, which was built using this idea, although not sure if it may be better to add this as an additional feature to the "Button" instead of it being its own Button type.
The code to add this type looks like this, assuming that "texture_confirm" was already created (same idea behind adding an Image to the ui).