Skip to content

Commit e181f38

Browse files
committed
fix font size in ComboBox/TabControl
1 parent 9864167 commit e181f38

File tree

5 files changed

+80
-5
lines changed

5 files changed

+80
-5
lines changed

Intersect.Client.Framework/Gwen/Control/ComboBox.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public ComboBox(Base parent, string? name = default) : base(parent, name)
4545
Size = new Point(100, 20);
4646
_menu = new Menu(this, name: nameof(_menu))
4747
{
48+
FontProvider = this,
4849
IsHidden = true,
4950
IconMarginDisabled = true,
5051
IsTabable = false,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Intersect.Client.Framework.Graphics;
2+
3+
namespace Intersect.Client.Framework.Gwen.Control;
4+
5+
public interface IFontProvider
6+
{
7+
IFont? Font { get; set; }
8+
9+
int FontSize { get; set; }
10+
}

Intersect.Client.Framework/Gwen/Control/Label.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Intersect.Client.Framework.Gwen.Control;
1515
/// <summary>
1616
/// Static text label.
1717
/// </summary>
18-
public partial class Label : Base, ILabel
18+
public partial class Label : Base, ILabel, IFontProvider
1919
{
2020
protected readonly Text _textElement;
2121

Intersect.Client.Framework/Gwen/Control/Menu.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ public Menu(Base parent, string? name = default) : base(parent, name)
4242

4343
#region Font Handling
4444

45+
public IFontProvider? FontProvider
46+
{
47+
get => _fontProvider;
48+
set
49+
{
50+
if (value == _fontProvider)
51+
{
52+
return;
53+
}
54+
55+
_fontProvider = value;
56+
UpdateItemStyles();
57+
}
58+
}
59+
4560
private IFont? _itemFont;
4661

4762
public IFont? ItemFont
@@ -59,6 +74,7 @@ public string? ItemFontName
5974
}
6075

6176
private int _itemFontSize;
77+
private IFontProvider? _fontProvider;
6278

6379
public int ItemFontSize
6480
{
@@ -478,15 +494,25 @@ public override void LoadJson(JToken token, bool isRoot = default)
478494

479495
private void UpdateItemStyles()
480496
{
497+
var font = _fontProvider?.Font;
498+
var itemFontSize = (_itemFontSize < 1 ? 10 : _itemFontSize);
499+
var fontSize = _fontProvider?.FontSize ?? itemFontSize;
500+
501+
if (_itemFont is { } itemFont)
502+
{
503+
font = itemFont;
504+
fontSize = itemFontSize;
505+
}
506+
481507
var menuItems = Children.OfType<MenuItem>().ToArray();
482508
foreach (var item in menuItems)
483509
{
484-
if (_itemFont != null)
510+
if (font != null)
485511
{
486-
item.Font = _itemFont;
512+
item.Font = font;
487513
}
488514

489-
item.FontSize = _itemFontSize;
515+
item.FontSize = fontSize;
490516
item.SetTextColor(mItemNormalTextColor, ComponentState.Normal);
491517
item.SetTextColor(mItemHoverTextColor, ComponentState.Hovered);
492518
}

Intersect.Client.Framework/Gwen/Control/TabControl.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using Intersect.Client.Framework.Graphics;
1+
using Intersect.Client.Framework.File_Management;
2+
using Intersect.Client.Framework.Graphics;
23
using Intersect.Client.Framework.Gwen.ControlInternal;
4+
using Newtonsoft.Json.Linq;
35

46
namespace Intersect.Client.Framework.Gwen.Control;
57

@@ -121,6 +123,7 @@ public IFont? Font
121123
foreach (var tab in tabs)
122124
{
123125
tab.Font = _font;
126+
tab.FontSize = _fontSize;
124127
}
125128
}
126129
}
@@ -155,6 +158,7 @@ public TabButton AddPage(string label, string? tabName, Base? page = null)
155158
TabButton button = new(_tabStrip)
156159
{
157160
Font = _font,
161+
FontSize = _fontSize,
158162
IsTabable = false,
159163
Page = page,
160164
Text = label,
@@ -211,6 +215,40 @@ public TabButton AddPage(TabButton button)
211215
return button;
212216
}
213217

218+
public override JObject? GetJson(bool isRoot = false, bool onlySerializeIfNotEmpty = false)
219+
{
220+
var serializedProperties = base.GetJson(isRoot, onlySerializeIfNotEmpty);
221+
if (serializedProperties is null)
222+
{
223+
return null;
224+
}
225+
226+
serializedProperties[nameof(Font)] = Font?.Name;
227+
serializedProperties[nameof(FontSize)] = FontSize;
228+
229+
return serializedProperties;
230+
}
231+
232+
public override void LoadJson(JToken token, bool isRoot = default)
233+
{
234+
base.LoadJson(token, isRoot);
235+
236+
if (token is not JObject obj)
237+
{
238+
return;
239+
}
240+
241+
if (obj.TryGetValue(nameof(Font), out var tokenFont) && tokenFont is { Type: JTokenType.String })
242+
{
243+
Font = GameContentManager.Current.GetFont(tokenFont.Value<string>());
244+
}
245+
246+
if (obj.TryGetValue(nameof(FontSize), out var tokenFontSize) && tokenFontSize is { Type: JTokenType.Integer })
247+
{
248+
FontSize = tokenFontSize.Value<int>();
249+
}
250+
}
251+
214252
/// <summary>
215253
/// Handler for tab selection.
216254
/// </summary>

0 commit comments

Comments
 (0)