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

Fix wordwrap text layout spaces on load #62

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions Source/Urho3D/UI/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,18 @@ void Text::UpdateText(bool onResize)
else
{
int maxWidth = GetWidth();

if (!IsFixedWidth())
{
// use parent layout to set our max width if possible
UIElement* parent = GetParent();
if (parent && parent->GetLayoutMode() != LM_FREE)
{
auto& parentBorder = parent->GetLayoutBorder();
maxWidth = parent->GetWidth() - (parentBorder.left_ + parentBorder.right_);
}
}

unsigned nextBreak = 0;
unsigned lineStart = 0;
printToText_.Clear();
Expand Down Expand Up @@ -648,10 +660,20 @@ void Text::UpdateText(bool onResize)
// Set minimum and current size according to the text size, but respect fixed width if set
if (!IsFixedWidth())
{
if (wordWrap_)
SetMinWidth(0);
else
{
if (wordWrap_) {
// don't set min width to 0 if we're inside a layout
UIElement* parent = GetParent();
if (parent && parent->GetLayoutMode() != LM_FREE)
{
SetMinWidth(width);
SetWidth(width);
}
else
{
SetMinWidth(0);
}
}
else {
SetMinWidth(width);
SetWidth(width);
}
Expand Down
Loading