-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Added alignment options to icons on buttons. They can now be centered and right-aligned. #37181
Added alignment options to icons on buttons. They can now be centered and right-aligned. #37181
Conversation
A bit of documentation for the new methods would be nice. |
Ah, good call. I forgot I added new functions for this. Should that be a separate pull request, or should it be squashed into this one? Never touched the documentation before. |
Squashed in this commit would be best. You can generate the template for the new functions with |
5e9ab0d
to
ef5228e
Compare
Ok, I think I have it all squared away now. For some reason, the doc generation did not work proprely using just "." as the output directory. Nothing changed. I then tried using a test directory, and it generate a bunch of stub xml files. Finally, I ended up just doing "testdir.." and that ended up working. Strange. This was on a window build. Rebasing also got interesting with some merge conflicts. Always something new whenever I try to do a pull request. |
The |
dff2a93
to
e145281
Compare
Merge conflicts resolved. Just waiting on a review, now. |
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.
Looks ok feature and code-wise (aside from that one nitpick about order).
We could rename align
to text_align
, so these properties are less confusing, but this could be done in another PR (and allow this one to be cherry-picked easier).
Having an option for drawing text on the bottom will be good too while the icon is centered. |
The implementation seems fine, but looking at the screenshot on #11380 (comment), I'm not sure how usable the |
I don't imagine people would really use the centered text AND centered icon. It's just there because that's a possible combination. I primarily wanted to just be able to center icons by themselves. Icons could maybe be used for backgrounds on buttons as well. We could always expand this later if there's a desire for it. |
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.
LGTM.
@jitspoe Could you rebase to solve merge conflicts? |
Working on merging this. It's a pretty significant conflict with all the rtl changes. |
I'm really confused by some of these changes and how to test them. For example,
Why, if the text is RTL, would we be using the right side margin for the icon offset? The icon is still on the left, right? Wouldn't we always want to be using the left margin? Also, when does "rtl" get set? There's a "Text Direction" property on the button that can specify "RTL", but it appears to not change any behavior with the text. I even tried putting in some Arabic text to test. Nothing appears to change within the editor. I'm confused as to what all these checks are doing, and if they're even necessary. Seems to be making the code rather complex. |
CC @bruvzg You might find some explanations in https://godotengine.org/article/complex-text-layouts-progress-report-2 in the part about UI mirroring. If RTL UI mirroring is enabled, then it would be expected that a Left icon would be shown to the Right. E.g. if your usage is "user avatar on the left, then name on the right", in Arabic this should be "user avatar on the right, then name on the left". Godot's Complex Text Layouts would handle this automagically based on the locale's preference. |
No, both text and icon are aligned to the right, as well as everything else. It's done to automatically flip layout for right-to-left languages without redesigning UI. For |
Ok, that's what the code looked like it was doing, but when I tried a nightly build and attempted to enable RTL on a button, it didn't seem to make a difference. How do I test this? |
Layout direction is controlled by |
I rewrote some of the rtl checking logic a little bit because the way it was previously implemented would involve lots of copy/pasting code and be difficult to maintain. I believe everything is working properly. I'm unsure how to test the internal margins, though. What sets things like _internal_margin[SIDE_RIGHT]? |
c117c0c
to
92087c2
Compare
It would be good if you can rebase on top of upstream |
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.
With exception to min. size not updated on icon alignment change, everything seems to be working fine.
They can now be centered and right-aligned. Fixes godotengine#11380.
92087c2
to
e192eb0
Compare
Force pushed an update to rebase on |
Thanks! |
Thanks for taking care of the last couple changes. Should I make a pull request for 3.x as well? Will the RTL stuff be making its way to 3.x? |
Feel free to open a pull request for
No, as it's backwards-incompatible with existing projects. |
@jitspoe Did you ever get around to backporting this to |
It's on my todo list but it's kinda far down. I actually wrote it for 3.x then rewrote it for 4.0, so I have some iteration of it here: https://github.com/jitspoe/godot/tree/3.x.jitspoe I think I may have changed some variable names or something and wanted to make sure it was consistent with what was in 4.0. Got kind of a big milestone coming up, so I probably won't have time to look at it this month. |
I've opened PR #57771 to backport this to |
Icons now have the same alignment options as text on buttons. Icons can be aligned on the left, right, or centered. Left is the same as the current behavior. Right is basically the same, but on the other side. Centered centers the icon and draws the text (if any) on top. Very useful if you want to have menu buttons that can sometimes have text OR an icon and you want them justified in the same way.
Fixes #11380