Skip to content

Commit 79ae52e

Browse files
committed
Force resize description to contents on creation, and resize container to contents
1 parent db70321 commit 79ae52e

File tree

6 files changed

+92
-65
lines changed

6 files changed

+92
-65
lines changed

Intersect.Client.Core/Interface/Game/DescriptionWindows/Components/DescriptionComponent.cs

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ protected override void GenerateComponents()
1616
base.GenerateComponents();
1717

1818
mDescription = new RichLabel(mContainer, "Description");
19+
mDescription.SizeChanged += (_, _) => mContainer.SizeToChildren();
20+
1921
}
2022

2123
/// <summary>
@@ -42,6 +44,7 @@ public override void CorrectWidth()
4244
var margins = mDescription.Margin;
4345

4446
mDescription.SetSize(mContainer.InnerWidth - margins.Right, mContainer.InnerHeight);
47+
mDescription.ForceImmediateRebuild();
4548
mDescription.SizeToChildren(false, true);
4649
mDescription.SetSize(mDescription.Width, mDescription.Height + margins.Bottom);
4750
mContainer.SizeToChildren(false, true);

Intersect.Client.Core/MonoGame/Graphics/MonoFont.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ public SpriteFont Instance
4343
{
4444
try
4545
{
46-
return _instance ??= PlatformObjectFactory();
46+
// ReSharper disable once InvertIf
47+
if (_instance == null)
48+
{
49+
_instance = PlatformObjectFactory();
50+
_instance.Texture.Name = $"{FontName} @ {Size}pt";
51+
}
52+
53+
return _instance;
4754
}
4855
catch (Exception exception)
4956
{

Intersect.Client.Core/MonoGame/Graphics/MonoRenderer.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,13 @@ public override GameShader LoadShader(string shaderName)
10081008
return new Shader(this, shaderName, _contentManager);
10091009
}
10101010

1011-
public override System.Numerics.Vector2 MeasureText(string text, IFont? font, int size, float fontScale)
1011+
public override System.Numerics.Vector2 MeasureText(string? text, IFont? font, int size, float fontScale)
10121012
{
1013+
if (string.IsNullOrWhiteSpace(text))
1014+
{
1015+
return default;
1016+
}
1017+
10131018
if (font is not Font<SpriteFont> platformFont)
10141019
{
10151020
return default;

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

+11-8
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,17 @@ protected override void Render(Skin.Base skin)
354354
if (TextureNinePatchMargin is { } textureNinePatchMargin)
355355
{
356356
var sourceBounds = _textureSourceBounds;
357-
_ninepatchRenderer ??= new Bordered(
358-
texture,
359-
sourceBounds.X,
360-
sourceBounds.Y,
361-
sourceBounds.Width,
362-
sourceBounds.Height,
363-
textureNinePatchMargin
364-
);
357+
if (_ninepatchRenderer == null || _ninepatchRenderer.Value.Margin != textureNinePatchMargin)
358+
{
359+
_ninepatchRenderer = new Bordered(
360+
texture,
361+
sourceBounds.X,
362+
sourceBounds.Y,
363+
sourceBounds.Width,
364+
sourceBounds.Height,
365+
textureNinePatchMargin
366+
);
367+
}
365368

366369
if (_ninepatchRenderer is { } ninepatchRenderer)
367370
{

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

+7
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ bool noSplit
494494
Alignment = [block.Alignment],
495495
AutoSizeToContents = true,
496496
Font = font,
497+
FontSize = block.FontSize,
497498
RestrictToParent = false,
498499
Text = x == 0 ? text.TrimStart(' ') : text,
499500
TextAlign = Pos.None,
@@ -583,6 +584,12 @@ protected override void OnSizeChanged(Point oldSize, Point newSize)
583584
}
584585
}
585586

587+
ApplicationContext.CurrentContext.Logger.LogDebug(
588+
"Rebuilding due to size change from {OldSize} to {NewSize} (_dockFillSize={DockFillSize})",
589+
oldSize,
590+
newSize,
591+
_dockFillSize
592+
);
586593
InvalidateRebuild();
587594
}
588595

Intersect.Client.Framework/Gwen/Skin/Texturing/Bordered.cs

+57-55
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,27 @@ public partial struct Bordered : IEquatable<Bordered>, IAtlasDrawable
2222
public static implicit operator FivePatch(Bordered bordered)
2323
{
2424
return new FivePatch(
25-
bordered.mTexture,
25+
bordered._texture,
2626
(int)bordered.mX,
2727
(int)bordered.mY,
28-
(int)bordered.mWidth,
29-
(int)bordered.mHeight,
30-
bordered.mMargin,
28+
(int)bordered._width,
29+
(int)bordered._height,
30+
bordered._margin,
3131
default
3232
);
3333
}
3434

35-
private IGameTexture mTexture;
35+
private IGameTexture _texture;
3636

37-
private readonly SubRect[] mRects;
37+
private readonly SubRect[] _subRects;
3838

39-
private Margin mMargin;
39+
private Margin _margin;
4040

41-
private float mWidth;
41+
private float _width;
4242

43-
private float mHeight;
43+
private float _height;
44+
45+
public Margin Margin => _margin;
4446

4547
public Bordered(
4648
IGameTexture texture,
@@ -53,10 +55,10 @@ Margin inMargin
5355
{
5456
mX = x;
5557
mY = y;
56-
mRects = new SubRect[9];
57-
for (var i = 0; i < mRects.Length; i++)
58+
_subRects = new SubRect[9];
59+
for (var i = 0; i < _subRects.Length; i++)
5860
{
59-
mRects[i].Uv = new float[4];
61+
_subRects[i].Uv = new float[4];
6062
}
6163

6264
Init(texture, x, y, w, h, inMargin);
@@ -65,29 +67,29 @@ Margin inMargin
6567
void DrawRect(Renderer.Base render, int i, int x, int y, int w, int h, Color clr)
6668
{
6769
render.DrawTexturedRect(
68-
mTexture, new Rectangle(x, y, w, h), clr, mRects[i].Uv[0], mRects[i].Uv[1], mRects[i].Uv[2],
69-
mRects[i].Uv[3]
70+
_texture, new Rectangle(x, y, w, h), clr, _subRects[i].Uv[0], _subRects[i].Uv[1], _subRects[i].Uv[2],
71+
_subRects[i].Uv[3]
7072
);
7173
}
7274

7375
void SetRect(int num, float x, float y, float w, float h)
7476
{
75-
if (mTexture == null)
77+
if (_texture == null)
7678
{
7779
return;
7880
}
7981

80-
float texw = mTexture.Width;
81-
float texh = mTexture.Height;
82+
float texw = _texture.Width;
83+
float texh = _texture.Height;
8284

8385
//x -= 1.0f;
8486
//y -= 1.0f;
8587

86-
mRects[num].Uv[0] = x / texw;
87-
mRects[num].Uv[1] = y / texh;
88+
_subRects[num].Uv[0] = x / texw;
89+
_subRects[num].Uv[1] = y / texh;
8890

89-
mRects[num].Uv[2] = (x + w) / texw;
90-
mRects[num].Uv[3] = (y + h) / texh;
91+
_subRects[num].Uv[2] = (x + w) / texw;
92+
_subRects[num].Uv[3] = (y + h) / texh;
9193

9294
// rects[num].uv[0] += 1.0f / m_Texture->width;
9395
// rects[num].uv[1] += 1.0f / m_Texture->width;
@@ -103,31 +105,31 @@ private void Init(
103105
float drawMarginScale = 1.0f
104106
)
105107
{
106-
mTexture = texture;
108+
_texture = texture;
107109

108-
mMargin = inMargin;
110+
_margin = inMargin;
109111

110-
SetRect(0, x, y, mMargin.Left, mMargin.Top);
111-
SetRect(1, x + mMargin.Left, y, w - mMargin.Left - mMargin.Right, mMargin.Top);
112-
SetRect(2, x + w - mMargin.Right, y, mMargin.Right, mMargin.Top);
112+
SetRect(0, x, y, _margin.Left, _margin.Top);
113+
SetRect(1, x + _margin.Left, y, w - _margin.Left - _margin.Right, _margin.Top);
114+
SetRect(2, x + w - _margin.Right, y, _margin.Right, _margin.Top);
113115

114-
SetRect(3, x, y + mMargin.Top, mMargin.Left, h - mMargin.Top - mMargin.Bottom);
116+
SetRect(3, x, y + _margin.Top, _margin.Left, h - _margin.Top - _margin.Bottom);
115117
SetRect(
116118
4,
117-
x + mMargin.Left,
118-
y + mMargin.Top,
119-
w - mMargin.Left - mMargin.Right,
120-
h - mMargin.Top - mMargin.Bottom
119+
x + _margin.Left,
120+
y + _margin.Top,
121+
w - _margin.Left - _margin.Right,
122+
h - _margin.Top - _margin.Bottom
121123
);
122124

123-
SetRect(5, x + w - mMargin.Right, y + mMargin.Top, mMargin.Right, h - mMargin.Top - mMargin.Bottom);
125+
SetRect(5, x + w - _margin.Right, y + _margin.Top, _margin.Right, h - _margin.Top - _margin.Bottom);
124126

125-
SetRect(6, x, y + h - mMargin.Bottom, mMargin.Left, mMargin.Bottom);
126-
SetRect(7, x + mMargin.Left, y + h - mMargin.Bottom, w - mMargin.Left - mMargin.Right, mMargin.Bottom);
127-
SetRect(8, x + w - mMargin.Right, y + h - mMargin.Bottom, mMargin.Right, mMargin.Bottom);
127+
SetRect(6, x, y + h - _margin.Bottom, _margin.Left, _margin.Bottom);
128+
SetRect(7, x + _margin.Left, y + h - _margin.Bottom, w - _margin.Left - _margin.Right, _margin.Bottom);
129+
SetRect(8, x + w - _margin.Right, y + h - _margin.Bottom, _margin.Right, _margin.Bottom);
128130

129-
mWidth = w;
130-
mHeight = h;
131+
_width = w;
132+
_height = h;
131133
}
132134

133135
// can't have this as default param
@@ -138,52 +140,52 @@ private void Init(
138140

139141
public void Draw(Renderer.Base render, Rectangle r, Color col)
140142
{
141-
if (mTexture == null)
143+
if (_texture == null)
142144
{
143145
return;
144146
}
145147

146148
render.DrawColor = col;
147149

148-
if (r.Width < mWidth && r.Height < mHeight)
150+
if (r.Width < _width && r.Height < _height)
149151
{
150152
render.DrawTexturedRect(
151-
mTexture, r, col, mRects[0].Uv[0], mRects[0].Uv[1], mRects[8].Uv[2], mRects[8].Uv[3]
153+
_texture, r, col, _subRects[0].Uv[0], _subRects[0].Uv[1], _subRects[8].Uv[2], _subRects[8].Uv[3]
152154
);
153155

154156
return;
155157
}
156158

157-
DrawRect(render, 0, r.X, r.Y, mMargin.Left, mMargin.Top, col);
158-
DrawRect(render, 1, r.X + mMargin.Left, r.Y, r.Width - mMargin.Left - mMargin.Right, mMargin.Top, col);
159-
DrawRect(render, 2, r.X + r.Width - mMargin.Right, r.Y, mMargin.Right, mMargin.Top, col);
159+
DrawRect(render, 0, r.X, r.Y, _margin.Left, _margin.Top, col);
160+
DrawRect(render, 1, r.X + _margin.Left, r.Y, r.Width - _margin.Left - _margin.Right, _margin.Top, col);
161+
DrawRect(render, 2, r.X + r.Width - _margin.Right, r.Y, _margin.Right, _margin.Top, col);
160162

161-
DrawRect(render, 3, r.X, r.Y + mMargin.Top, mMargin.Left, r.Height - mMargin.Top - mMargin.Bottom, col);
163+
DrawRect(render, 3, r.X, r.Y + _margin.Top, _margin.Left, r.Height - _margin.Top - _margin.Bottom, col);
162164
DrawRect(
163-
render, 4, r.X + mMargin.Left, r.Y + mMargin.Top, r.Width - mMargin.Left - mMargin.Right,
164-
r.Height - mMargin.Top - mMargin.Bottom, col
165+
render, 4, r.X + _margin.Left, r.Y + _margin.Top, r.Width - _margin.Left - _margin.Right,
166+
r.Height - _margin.Top - _margin.Bottom, col
165167
);
166168

167169
DrawRect(
168-
render, 5, r.X + r.Width - mMargin.Right, r.Y + mMargin.Top, mMargin.Right,
169-
r.Height - mMargin.Top - mMargin.Bottom, col
170+
render, 5, r.X + r.Width - _margin.Right, r.Y + _margin.Top, _margin.Right,
171+
r.Height - _margin.Top - _margin.Bottom, col
170172
);
171173

172-
DrawRect(render, 6, r.X, r.Y + r.Height - mMargin.Bottom, mMargin.Left, mMargin.Bottom, col);
174+
DrawRect(render, 6, r.X, r.Y + r.Height - _margin.Bottom, _margin.Left, _margin.Bottom, col);
173175
DrawRect(
174-
render, 7, r.X + mMargin.Left, r.Y + r.Height - mMargin.Bottom, r.Width - mMargin.Left - mMargin.Right,
175-
mMargin.Bottom, col
176+
render, 7, r.X + _margin.Left, r.Y + r.Height - _margin.Bottom, r.Width - _margin.Left - _margin.Right,
177+
_margin.Bottom, col
176178
);
177179

178180
DrawRect(
179-
render, 8, r.X + r.Width - mMargin.Right, r.Y + r.Height - mMargin.Bottom, mMargin.Right,
180-
mMargin.Bottom, col
181+
render, 8, r.X + r.Width - _margin.Right, r.Y + r.Height - _margin.Bottom, _margin.Right,
182+
_margin.Bottom, col
181183
);
182184
}
183185

184186
public bool Equals(Bordered other)
185187
{
186-
return mTexture.Equals(other.mTexture) && mRects.Equals(other.mRects) && mMargin.Equals(other.mMargin) && mWidth.Equals(other.mWidth) && mHeight.Equals(other.mHeight);
188+
return _texture.Equals(other._texture) && _subRects.Equals(other._subRects) && _margin.Equals(other._margin) && _width.Equals(other._width) && _height.Equals(other._height);
187189
}
188190

189191
public override bool Equals(object? obj)
@@ -193,7 +195,7 @@ public override bool Equals(object? obj)
193195

194196
public override int GetHashCode()
195197
{
196-
return HashCode.Combine(mTexture, mRects, mMargin, mWidth, mHeight);
198+
return HashCode.Combine(_texture, _subRects, _margin, _width, _height);
197199
}
198200

199201
public static bool operator ==(Bordered lhs, Bordered rhs) => lhs.Equals(rhs);

0 commit comments

Comments
 (0)