Skip to content

Commit fba13a3

Browse files
committed
fix: allow hidden components to run Layout() if they're the active tooltip component
1 parent 30c0f36 commit fba13a3

File tree

4 files changed

+76
-29
lines changed

4 files changed

+76
-29
lines changed

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

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ public virtual bool IsDisabled
477477
/// </summary>
478478
public virtual bool IsHidden
479479
{
480-
get => (_inheritParentEnablementProperties && Parent != default) ? Parent.IsHidden : mHidden;
480+
get => ((_inheritParentEnablementProperties && Parent is {} parent) ? parent.IsHidden : mHidden);
481481
set
482482
{
483483
if (value == mHidden)
@@ -1298,28 +1298,29 @@ public virtual void ToggleHidden()
12981298
/// Creates a tooltip for the control.
12991299
/// </summary>
13001300
/// <param name="text">Tooltip text.</param>
1301-
public virtual void SetToolTipText(string text)
1301+
public virtual void SetToolTipText(string? text)
13021302
{
1303+
var tooltip = Tooltip;
1304+
13031305
if (mHideToolTip || string.IsNullOrWhiteSpace(text))
13041306
{
1305-
if (this.Tooltip != null && this.Tooltip.Parent != null)
1307+
if (Tooltip is { Parent: not null })
13061308
{
1307-
this.Tooltip?.Parent.RemoveChild(this.Tooltip, true);
1309+
Tooltip?.Parent.RemoveChild(Tooltip, true);
13081310
}
1309-
this.Tooltip = null;
1311+
Tooltip = null;
13101312

13111313
return;
13121314
}
13131315

1314-
var tooltip = Tooltip;
13151316
if (tooltip is not Label labelTooltip)
13161317
{
13171318
if (tooltip is not null)
13181319
{
13191320
return;
13201321
}
13211322

1322-
labelTooltip = new Label(this)
1323+
labelTooltip = new Label(this, name: "Tooltip")
13231324
{
13241325
TextColorOverride = mToolTipFontColor ?? Skin.Colors.TooltipText,
13251326
ToolTipBackground = mToolTipBackgroundImage,
@@ -2456,7 +2457,10 @@ protected virtual void RecurseLayout(Skin.Base skin)
24562457

24572458
if (IsHidden)
24582459
{
2459-
return;
2460+
if (!ToolTip.IsActiveTooltip(this))
2461+
{
2462+
return;
2463+
}
24602464
}
24612465

24622466
if (mNeedsLayout)
@@ -2477,7 +2481,19 @@ protected virtual void RecurseLayout(Skin.Base skin)
24772481
{
24782482
if (child.IsHidden)
24792483
{
2480-
continue;
2484+
if (!ToolTip.IsActiveTooltip(child))
2485+
{
2486+
if (child is Label { Name: "Tooltip" } cl1 && cl1.Text.EndsWith('%'))
2487+
{
2488+
child.ToString();
2489+
}
2490+
continue;
2491+
}
2492+
2493+
if (child is Label { Name: "Tooltip" } cl2 && cl2.Text.EndsWith('%'))
2494+
{
2495+
child.ToString();
2496+
}
24812497
}
24822498

24832499
var dock = child.Dock;
@@ -2487,6 +2503,11 @@ protected virtual void RecurseLayout(Skin.Base skin)
24872503
continue;
24882504
}
24892505

2506+
if (child is Label label && label.Text.EndsWith('%') && !label.Name.StartsWith("EXP"))
2507+
{
2508+
label.ToString();
2509+
}
2510+
24902511
if (dock.HasFlag(Pos.Top))
24912512
{
24922513
var margin = child.Margin;
@@ -2552,6 +2573,11 @@ protected virtual void RecurseLayout(Skin.Base skin)
25522573
//
25532574
foreach (var child in mChildren)
25542575
{
2576+
if (child.IsHidden && !ToolTip.IsActiveTooltip(child))
2577+
{
2578+
continue;
2579+
}
2580+
25552581
var dock = child.Dock;
25562582

25572583
if (!dock.HasFlag(Pos.Fill))
@@ -2566,6 +2592,11 @@ protected virtual void RecurseLayout(Skin.Base skin)
25662592
bounds.Y + margin.Top
25672593
);
25682594

2595+
if (child is Label label && label.Text.EndsWith('%'))
2596+
{
2597+
label.ToString();
2598+
}
2599+
25692600
if (child is IAutoSizeToContents { AutoSizeToContents: true })
25702601
{
25712602
child.SetPosition(newPosition);

Intersect.Client.Framework/Gwen/ControlInternal/Text.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ private void SizeToContents()
178178
return;
179179
}
180180

181-
if (_font == default)
181+
var font = Font;
182+
if (font == default)
182183
{
183184
return;
184185
}
@@ -188,16 +189,11 @@ private void SizeToContents()
188189
if (string.IsNullOrEmpty(_displayedText))
189190
{
190191
const string verticalBar = "|";
191-
newSize = Skin.Renderer.MeasureText(_font, verticalBar, _scale) with { X = 0 };
192+
newSize = Skin.Renderer.MeasureText(font, verticalBar, _scale) with { X = 0 };
192193
}
193194
else
194195
{
195-
newSize = Skin.Renderer.MeasureText(_font, _displayedText, _scale);
196-
}
197-
198-
if (newSize.X == Width && newSize.Y == Height)
199-
{
200-
return;
196+
newSize = Skin.Renderer.MeasureText(font, _displayedText, _scale);
201197
}
202198

203199
if (Size == newSize)

Intersect.Client.Framework/Gwen/Input/InputHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public static bool OnMouseClicked(Base canvas, int mouseButton, bool down)
431431
public static bool OnMouseScroll(Base canvas, int deltaX, int deltaY)
432432
{
433433

434-
if (canvas == null ||
434+
if (canvas == null ||
435435
HoveredControl == null ||
436436
HoveredControl.GetCanvas() != canvas ||
437437
!canvas.IsVisible
@@ -444,7 +444,7 @@ public static bool OnMouseScroll(Base canvas, int deltaX, int deltaY)
444444
{
445445
HoveredControl.InputMouseWheeled(deltaY);
446446
}
447-
447+
448448
if (deltaX != 0)
449449
{
450450
HoveredControl.InputMouseHWheeled(deltaX);

Intersect.Client.Framework/Gwen/ToolTip.cs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ namespace Intersect.Client.Framework.Gwen;
88
/// </summary>
99
public static partial class ToolTip
1010
{
11+
private static Base? _activeTooltipParent;
1112

12-
private static Base sG_toolTip;
13+
public static bool IsActiveTooltip(Base tooltipComponent)
14+
{
15+
if (tooltipComponent.Parent is not { } parent)
16+
{
17+
return false;
18+
}
19+
20+
return parent == _activeTooltipParent;
21+
}
1322

1423
/// <summary>
1524
/// Enables tooltip display for the specified control.
@@ -22,7 +31,7 @@ public static void Enable(Base control)
2231
return;
2332
}
2433

25-
sG_toolTip = control;
34+
_activeTooltipParent = control;
2635
}
2736

2837
/// <summary>
@@ -31,10 +40,12 @@ public static void Enable(Base control)
3140
/// <param name="control">Target control.</param>
3241
public static void Disable(Base control)
3342
{
34-
if (sG_toolTip == control)
43+
if (_activeTooltipParent != control)
3544
{
36-
sG_toolTip = null;
45+
return;
3746
}
47+
48+
_activeTooltipParent = null;
3849
}
3950

4051
/// <summary>
@@ -52,7 +63,13 @@ public static void ControlDeleted(Base control)
5263
/// <param name="skin"></param>
5364
public static void RenderToolTip(Skin.Base skin)
5465
{
55-
if (sG_toolTip == null || sG_toolTip.Tooltip == null)
66+
if (_activeTooltipParent?.Tooltip == default)
67+
{
68+
return;
69+
}
70+
71+
var canvas = _activeTooltipParent.Canvas;
72+
if (canvas == default)
5673
{
5774
return;
5875
}
@@ -61,20 +78,23 @@ public static void RenderToolTip(Skin.Base skin)
6178

6279
var oldRenderOffset = render.RenderOffset;
6380
var mousePos = Input.InputHandler.MousePosition;
64-
var bounds = sG_toolTip.Tooltip.Bounds;
81+
var bounds = _activeTooltipParent.Tooltip.Bounds;
6582

6683
var offset = Util.FloatRect(
67-
mousePos.X - bounds.Width * 0.5f, mousePos.Y - bounds.Height - 10, bounds.Width, bounds.Height
84+
mousePos.X - bounds.Width * 0.5f,
85+
mousePos.Y - bounds.Height,
86+
bounds.Width,
87+
bounds.Height
6888
);
6989

70-
offset = Util.ClampRectToRect(offset, sG_toolTip.GetCanvas().Bounds);
90+
offset = Util.ClampRectToRect(offset, canvas.Bounds);
7191

7292
//Calculate offset on screen bounds
7393
render.AddRenderOffset(offset);
7494
render.EndClip();
7595

76-
skin.DrawToolTip(sG_toolTip.Tooltip);
77-
sG_toolTip.Tooltip.DoRender(skin);
96+
skin.DrawToolTip(_activeTooltipParent.Tooltip);
97+
_activeTooltipParent.Tooltip.DoRender(skin);
7898

7999
render.RenderOffset = oldRenderOffset;
80100
}

0 commit comments

Comments
 (0)