Skip to content

Commit

Permalink
UserInterface: CSS teim
Browse files Browse the repository at this point in the history
  • Loading branch information
Efruit committed Nov 27, 2021
1 parent f04a634 commit 46a8794
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 30 deletions.
11 changes: 8 additions & 3 deletions Robust.Client/UserInterface/Controls/ItemList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,17 @@ public Font ActualFont
{
get
{
if (TryGetStyleProperty<Font>("font", out var font))
TryGetStyleProperty<FontClass>("font", out var font);
if (TryGetStyleProperty<IFontLibrary>("font-library", out var flib))
{
return font;
return flib.StartFont(font).Current;
}

return UserInterfaceManager.ThemeDefaults.DefaultFont;
return UserInterfaceManager
.ThemeDefaults
.DefaultFontLibrary
.StartFont(font)
.Current;
}
}

Expand Down
5 changes: 3 additions & 2 deletions Robust.Client/UserInterface/Controls/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ private Font ActualFont
return FontOverride;
}

if (TryGetStyleProperty<Font>(StylePropertyFont, out var font))
TryGetStyleProperty<FontClass>(StylePropertyFont, out var font);
if (TryGetStyleProperty<IFontLibrary>("font-library", out var flib))
{
return font;
return flib.StartFont(font).Current;
}

return UserInterfaceManager.ThemeDefaults.LabelFont;
Expand Down
5 changes: 3 additions & 2 deletions Robust.Client/UserInterface/Controls/LineEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,9 +667,10 @@ protected internal override void KeyboardFocusExited()
[Pure]
private Font _getFont()
{
if (TryGetStyleProperty<Font>("font", out var font))
TryGetStyleProperty<FontClass>("font", out var font);
if (TryGetStyleProperty<IFontLibrary>("font-library", out var flib))
{
return font;
return flib.StartFont(font).Current;
}

return UserInterfaceManager.ThemeDefaults.DefaultFont;
Expand Down
46 changes: 32 additions & 14 deletions Robust.Client/UserInterface/Controls/OutputPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void RemoveEntry(Index index)
var entry = _entries[index];
_entries.RemoveAt(index.GetOffset(_entries.Count));

var font = _getFont().StartFont().Current;
var font = _getFont();
_totalContentHeight -= entry.Height + font.GetLineSeparation(UIScale);
if (_entries.Count == 0)
{
Expand All @@ -83,10 +83,10 @@ public void AddMessage(FormattedMessage message)
{
var entry = new RichTextEntry(message);

entry.Update(_getFont(), _getContentBox().Width, UIScale);
entry.Update(_getFontLib(), _getContentBox().Width, UIScale);

_entries.Add(entry);
var font = _getFont().StartFont().Current;
var font = _getFont();
_totalContentHeight += entry.Height;
if (_firstLine)
{
Expand Down Expand Up @@ -115,7 +115,8 @@ protected internal override void Draw(DrawingHandleScreen handle)
base.Draw(handle);

var style = _getStyleBox();
var font = _getFont().StartFont().Current;
var flib = _getFontLib();
var font = _getFont();
style?.Draw(handle, PixelSizeBox);
var contentBox = _getContentBox();

Expand All @@ -134,7 +135,7 @@ protected internal override void Draw(DrawingHandleScreen handle)
break;
}

entry.Draw(handle, _getFont(), contentBox, entryOffset, UIScale);
entry.Draw(handle, flib, contentBox, entryOffset, UIScale, _getFontColor());

entryOffset += entry.Height + font.GetLineSeparation(UIScale);
}
Expand Down Expand Up @@ -170,7 +171,7 @@ protected override Vector2 MeasureOverride(Vector2 availableSize)
private void _invalidateEntries()
{
_totalContentHeight = 0;
var font = _getFont();
var font = _getFontLib();
var sizeX = _getContentBox().Width;
for (var i = 0; i < _entries.Count; i++)
{
Expand All @@ -188,14 +189,32 @@ private void _invalidateEntries()
}

[System.Diagnostics.Contracts.Pure]
private IFontLibrary _getFont()
private IFontLibrary _getFontLib()
{
if (TryGetStyleProperty<IFontLibrary>("font", out var font))
{
return font;
}
if (TryGetStyleProperty<IFontLibrary>("font-library", out var flib))
return flib;

return UserInterfaceManager
.ThemeDefaults
.DefaultFontLibrary;
}

[System.Diagnostics.Contracts.Pure]
private Font _getFont()
{
TryGetStyleProperty<FontClass>("font", out var fclass);
return _getFontLib().StartFont(fclass).Current;
}

[System.Diagnostics.Contracts.Pure]
private Color _getFontColor()
{
if (TryGetStyleProperty<Color>("font-color", out var fc))
return fc;

return UserInterfaceManager.ThemeDefaults.DefaultFontLibrary;
// From Robust.Client/UserInterface/RichTextEntry.cs#L19
// at 33008a2bce0cc4755b18b12edfaf5b6f1f87fdd9
return new Color(200, 200, 200);
}

[System.Diagnostics.Contracts.Pure]
Expand All @@ -213,8 +232,7 @@ private IFontLibrary _getFont()
[System.Diagnostics.Contracts.Pure]
private int _getScrollSpeed()
{
var font = _getFont().StartFont().Current;
return font.GetLineHeight(UIScale) * 2;
return _getFont().GetLineHeight(UIScale) * 2;
}

[System.Diagnostics.Contracts.Pure]
Expand Down
22 changes: 18 additions & 4 deletions Robust.Client/UserInterface/Controls/RichTextLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,32 @@ protected internal override void Draw(DrawingHandleScreen handle)
return;
}

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

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

return UserInterfaceManager.ThemeDefaults.DefaultFontLibrary;
return UserInterfaceManager
.ThemeDefaults
.DefaultFontLibrary;
}

[Pure]
private Color _getFontColor()
{
if (TryGetStyleProperty<Color>("font-color", out var fc))
return fc;

// From Robust.Client/UserInterface/RichTextEntry.cs#L19
// at 33008a2bce0cc4755b18b12edfaf5b6f1f87fdd9
return new Color(200, 200, 200);
}
}
}
5 changes: 3 additions & 2 deletions Robust.Client/UserInterface/Controls/TabContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,10 @@ private Color _getTabFontColorInactive()
[System.Diagnostics.Contracts.Pure]
private Font _getFont()
{
if (TryGetStyleProperty<Font>("font", out var font))
TryGetStyleProperty<FontClass>("font", out var font);
if (TryGetStyleProperty<IFontLibrary>("font-library", out var flib))
{
return font;
return flib.StartFont(font).Current;
}

return UserInterfaceManager.ThemeDefaults.DefaultFont;
Expand Down
5 changes: 3 additions & 2 deletions Robust.Client/UserInterface/Controls/Tree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,10 @@ protected override void Resized()

private Font? _getFont()
{
if (TryGetStyleProperty<Font>("font", out var font))
TryGetStyleProperty<FontClass>("font", out var font);
if (TryGetStyleProperty<IFontLibrary>("font-library", out var flib))
{
return font;
return flib.StartFont(font).Current;
}

return null;
Expand Down
4 changes: 3 additions & 1 deletion Robust.Client/UserInterface/RichTextEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public void Draw(
IFontLibrary font,
UIBox2 drawBox,
float verticalOffset,
float uiScale)
float uiScale,
Color defColor)
{
var flib = font.StartFont();
foreach (var wd in _ld)
Expand All @@ -80,6 +81,7 @@ public void Draw(
rune,
baseLine,
uiScale,
s.Color == default ? defColor :
new Color { // Why Color.FromArgb isn't a thing is beyond me.
A=(float) ((s.Color & 0xFF_00_00_00) >> 24) / 255f,
R=(float) ((s.Color & 0x00_FF_00_00) >> 16) / 255f,
Expand Down

0 comments on commit 46a8794

Please sign in to comment.