-
Notifications
You must be signed in to change notification settings - Fork 206
Support optional text clipping on refactored GuiLabel #2557
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
base: master
Are you sure you want to change the base?
Support optional text clipping on refactored GuiLabel #2557
Conversation
| return this; | ||
| } | ||
|
|
||
| GuiAutoSizeLabel::GuiAutoSizeLabel(GuiContainer* owner, string id, string text, glm::vec2 min_size, glm::vec2 max_size, float min_text_size, float max_text_size) |
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.
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.
The sp::Font::FlagVertical flag is implemented in GuiLabel as a Boolean value defaulting to false at the end of the constructor. If I change the wrap_text GuiAutoSizeLabel parameter to a flag value, should I'll refactor GuiLabel and its invocations to use the flag instead of a Boolean.
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.
Note that the issue isn't storing a boolean in the object. It's the boolean parameter.
Reading: GuiAutoSizeLabel(parent, "ID", "Test", {100, 100}, {300, 300}, true) doesn't make it obvious what the true means (well, it's also not that obvious for the sizes... :P )
…arams Rather than relying on Boolean values consistently across GuiLabel and GuiAutoSizeLabel, and instead of manipulating the font flags inconsistently across them, refactor GuiLabel to manipulate font flags more directly instead of using a Boolean value to determine whether to apply sp::Font::FlagVertical. - Add a bitwise font_flag parameter to GuiLabel and default it to 0x01 (FlagLineWrap only, same as existing label behavior) - Simplify renderer.drawText logic in onDraw to use font_flag instead of conditionally applying some or no sp::Font flags during every draw - Refactor setVertical() to set font_flag to sp::Font::FlagVertical instead of flipping the vertical Bool and applying the flag conditionally at onDraw() - Add setUnwrapped() and setClipped() functions to unset FlagLineWrap and set FlagClip, respectively, in font_flag - Remove unused Boolean parameters for vertical (removed) and bold (never implemented) - Remove redundant GuiAutoSizeLabel::onDraw() to inherit GuiLabel::onDraw instead
src/gui/gui2_label.cpp
Outdated
|
|
||
| GuiLabel::GuiLabel(GuiContainer* owner, string id, string text, float text_size) | ||
| : GuiElement(owner, id), text(text), text_size(text_size), text_color(glm::u8vec4{255,255,255,255}), text_alignment(sp::Alignment::Center), background(false), bold(false), vertical(false) | ||
| : GuiElement(owner, id), text(text), text_size(text_size), text_color(glm::u8vec4{255,255,255,255}), text_alignment(sp::Alignment::Center), background(false), font_flag(0x01) |
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.
I assume the 0x01 is sp::Font::FlagLineWrap?
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.
Yeah, I should've just used that there.
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.
And it ended up being the wrong default anyway, so this is reverted to 0.
Defaulting to LineWrap breaks existing label behavior when a label has a small width, typically 0, as on the main menu's credits and in the autoconnect screen. Revert to no default flag.
Add a
font_flagbitwise parameter toGuiAutoSizeLabel, defaulting to0x01to maintain existing text wrapping behavior.Add
setUnwrapped()andsetClipped()and revisesetVertical()to change font flags accordingly. This replaces or removes existing Boolean parameters.Refactor
GuiLabelto simplify itsonDraw()and remove the now-redundant override inGuiAutoSizeLabel.Supports #2551.