Skip to content

Conversation

@oznogon
Copy link
Contributor

@oznogon oznogon commented Oct 21, 2025

Add a font_flag bitwise parameter to GuiAutoSizeLabel, defaulting to 0x01 to maintain existing text wrapping behavior.

Add setUnwrapped() and setClipped() and revise setVertical() to change font flags accordingly. This replaces or removes existing Boolean parameters.

Refactor GuiLabel to simplify its onDraw() and remove the now-redundant override in GuiAutoSizeLabel.

Supports #2551.

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@oznogon oznogon Oct 22, 2025

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.

Copy link
Owner

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
@oznogon oznogon changed the title Support optional text clipping on AutoSizeLabel Support optional text clipping on refactored GuiLabel Oct 22, 2025
@oznogon oznogon requested a review from daid October 22, 2025 23:09

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)
Copy link
Owner

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@oznogon oznogon marked this pull request as draft October 24, 2025 08:48
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.
@oznogon oznogon marked this pull request as ready for review October 24, 2025 08:58
@oznogon oznogon requested a review from daid October 24, 2025 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants