Skip to content

Commit

Permalink
Revert "UserInterface/RichTextEntry: Rich Text Fixes (Round 2) (space…
Browse files Browse the repository at this point in the history
…-wizards#2340)"

This reverts commit 5fac3f4.
  • Loading branch information
PaulRitter committed Dec 20, 2021
1 parent f82f9e9 commit fd2712b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 32 deletions.
21 changes: 4 additions & 17 deletions Robust.Client/UserInterface/Controls/RichTextLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override Vector2 MeasureOverride(Vector2 availableSize)
return Vector2.Zero;
}

_entry.Update(_getFontLibrary(), availableSize.X * UIScale, UIScale, defFont: _getFont());
_entry.Update(_getFont(), availableSize.X * UIScale, UIScale);

return (_entry.Width / UIScale, _entry.Height / UIScale);
}
Expand All @@ -45,12 +45,13 @@ protected internal override void Draw(DrawingHandleScreen handle)
return;
}

_entry.Draw(handle, _getFontLibrary(), SizeBox, 0, UIScale, _getFontColor(), defFont: _getFont());
_entry.Draw(handle, _getFont(), SizeBox, 0, UIScale, _getFontColor());
}

[Pure]
private IFontLibrary _getFontLibrary()
private IFontLibrary _getFont()
{
TryGetStyleProperty<FontClass>("font", out var font);
if (TryGetStyleProperty<IFontLibrary>("font-library", out var flib))
{
return flib;
Expand All @@ -61,20 +62,6 @@ private IFontLibrary _getFontLibrary()
.DefaultFontLibrary;
}

[Pure]
private FontClass _getFont()
{
if (TryGetStyleProperty<FontClass>("font", out var fclass))
{
return fclass;
}

return UserInterfaceManager
.ThemeDefaults
.DefaultFontLibrary
.Default;
}

[Pure]
private Color _getFontColor()
{
Expand Down
21 changes: 6 additions & 15 deletions Robust.Client/UserInterface/RichTextEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,20 @@ public RichTextEntry(FormattedMessage message)

// Last maxSizeX, used to detect resizing.
private int _lmsx = 0;

// Last UI scale
private float _lUiScale = 0f;

// Layout data, which needs to be refreshed when resized.
private ImmutableArray<TextLayout.Offset>? _ld = default;
private ImmutableArray<TextLayout.Offset> _ld = default;

/// <summary>
/// Recalculate line dimensions and where it has line breaks for word wrapping.
/// </summary>
/// <param name="font">The font being used for display.</param>
/// <param name="maxSizeX">The maximum horizontal size of the container of this entry.</param>
/// <param name="uiScale"></param>
public void Update(IFontLibrary font, float maxSizeX, float uiScale, FontClass? defFont = default)
public void Update(IFontLibrary font, float maxSizeX, float uiScale)
{
if ((int) maxSizeX != _lmsx || uiScale != _lUiScale || _ld is null)
if ((int) maxSizeX != _lmsx)
{
_ld = TextLayout.Layout(Message, (int) maxSizeX, font, scale: uiScale, fclass: defFont);
_ld = TextLayout.Layout(Message, (int) maxSizeX, font, scale: uiScale);
Height = 0;
Width = 0;
foreach (var w in _ld)
Expand All @@ -58,7 +54,6 @@ public void Update(IFontLibrary font, float maxSizeX, float uiScale, FontClass?
if (w.y + w.h > Height) Height = w.y;
}
_lmsx = (int) maxSizeX;
_lUiScale = uiScale;
}
}

Expand All @@ -68,13 +63,9 @@ public void Draw(
UIBox2 drawBox,
float verticalOffset,
float uiScale,
Color defColor,
FontClass? defFont = default)
Color defColor)
{
if (_ld is null)
return;

var flib = font.StartFont(defFont);
var flib = font.StartFont();
foreach (var wd in _ld)
{
var s = Message.Sections[wd.section];
Expand Down

0 comments on commit fd2712b

Please sign in to comment.