Skip to content

Commit a2cab6f

Browse files
committed
Make sliders in LabeledSlider fill AscensionGameDev#2549
1 parent 48af167 commit a2cab6f

File tree

7 files changed

+142
-35
lines changed

7 files changed

+142
-35
lines changed

Intersect.Client.Core/Interface/Menu/SelectCharacterWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ protected override void EnsureInitialized()
174174
{
175175
SizeToChildren(recursive: true);
176176

177-
// LoadJsonUi(GameContentManager.UI.Menu, Graphics.Renderer?.GetResolutionString());
177+
LoadJsonUi(GameContentManager.UI.Menu, Graphics.Renderer?.GetResolutionString());
178178
}
179179

180180
//Methods

Intersect.Client.Core/Interface/Shared/InputBox.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ private void NumericInputOnValueChanged(TextBoxNumeric sender, ValueChangedEvent
302302
AutoSizeToContents = false,
303303
Dock = Pos.Bottom,
304304
Font = _defaultFont,
305+
Rounding = 0,
305306
};
306307
numericSliderInput.ValueChanged += NumericSliderInputOnValueChanged;
307308

@@ -518,6 +519,8 @@ protected InputBox(
518519
_numericInputSlider = _inputPanel.FindChildByName<LabeledSlider>(nameof(_numericInputSlider)) ??
519520
throw new InvalidOperationException("Numeric input (slider) wasn't created");
520521
numericInput = _numericInputSlider;
522+
var notchCount = Math.Min(maximumQuantity, 5);
523+
_numericInputSlider.NotchCount = notchCount;
521524
break;
522525
case InputType.TextInput:
523526
_stringInput = _inputPanel.FindChildByName<TextBox>(nameof(_stringInput)) ??

Intersect.Client.Core/Interface/Shared/SettingsWindow.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,11 @@ public SettingsWindow(Base parent) : base(parent: parent, title: Strings.Setting
551551
CreateBottomBar(this);
552552
}
553553

554+
protected override void EnsureInitialized()
555+
{
556+
LoadJsonUi(stage: UI.Shared, resolution: Graphics.Renderer?.GetResolutionString());
557+
}
558+
554559
public override bool IsBlockingInput => _keybindingEditBtn is not null;
555560

556561
private BottomBarItems CreateBottomBar(Base parent)
@@ -1154,9 +1159,4 @@ private void CancelPendingChangesButton_Clicked(Base sender, MouseButtonState ar
11541159
// Hide our current window.
11551160
Hide();
11561161
}
1157-
1158-
protected override void EnsureInitialized()
1159-
{
1160-
LoadJsonUi(stage: UI.Shared, resolution: Graphics.Renderer?.GetResolutionString());
1161-
}
11621162
}

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

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3239,6 +3239,8 @@ protected void DoLayoutIfNeeded(Skin.Base skin)
32393239
Layout(skin);
32403240
}
32413241

3242+
private Point _requiredSizeForDockFillNodes;
3243+
32423244
/// <summary>
32433245
/// Recursively lays out the control's interior according to alignment, margin, padding, dock etc.
32443246
/// </summary>
@@ -3305,11 +3307,22 @@ protected virtual void RecurseLayout(Skin.Base skin)
33053307
var availableWidth = remainingBounds.Width - childMarginH;
33063308
var availableHeight = remainingBounds.Height - childMarginV;
33073309

3308-
var childFitsContents = child is IAutoSizeToContents { AutoSizeToContents: true };
3310+
var childFitsContentWidth = false;
3311+
var childFitsContentHeight = false;
3312+
3313+
if (child is ISmartAutoSizeToContents smartAutoSizeToContents)
3314+
{
3315+
childFitsContentWidth = smartAutoSizeToContents.AutoSizeToContentWidth;
3316+
childFitsContentHeight = smartAutoSizeToContents.AutoSizeToContentHeight;
3317+
} else if (child is IAutoSizeToContents { AutoSizeToContents: true })
3318+
{
3319+
childFitsContentWidth = true;
3320+
childFitsContentHeight = true;
3321+
}
33093322

33103323
if (childDock.HasFlag(Pos.Left))
33113324
{
3312-
var height = childFitsContents
3325+
var height = childFitsContentHeight
33133326
? child.Height
33143327
: availableHeight;
33153328

@@ -3350,7 +3363,7 @@ protected virtual void RecurseLayout(Skin.Base skin)
33503363

33513364
if (childDock.HasFlag(Pos.Right))
33523365
{
3353-
var height = childFitsContents
3366+
var height = childFitsContentHeight
33543367
? child.Height
33553368
: availableHeight;
33563369

@@ -3391,7 +3404,7 @@ protected virtual void RecurseLayout(Skin.Base skin)
33913404

33923405
if (childDock.HasFlag(Pos.Top) && !childDock.HasFlag(Pos.Left) && !childDock.HasFlag(Pos.Right))
33933406
{
3394-
var width = childFitsContents
3407+
var width = childFitsContentWidth
33953408
? child.Width
33963409
: availableWidth;
33973410

@@ -3417,7 +3430,7 @@ protected virtual void RecurseLayout(Skin.Base skin)
34173430

34183431
if (childDock.HasFlag(Pos.Bottom) && !childDock.HasFlag(Pos.Left) && !childDock.HasFlag(Pos.Right))
34193432
{
3420-
var width = childFitsContents
3433+
var width = childFitsContentWidth
34213434
? child.Width
34223435
: availableWidth;
34233436

@@ -3445,6 +3458,8 @@ protected virtual void RecurseLayout(Skin.Base skin)
34453458

34463459
mInnerBounds = remainingBounds;
34473460

3461+
Point sizeToFitDockFillNodes = default;
3462+
34483463
//
34493464
// Fill uses the left over space, so do that now.
34503465
//
@@ -3461,6 +3476,25 @@ protected virtual void RecurseLayout(Skin.Base skin)
34613476
remainingBounds.Y + childMargin.Top
34623477
);
34633478

3479+
Point newSize = new(
3480+
remainingBounds.Width - childMarginH,
3481+
remainingBounds.Height - childMarginV
3482+
);
3483+
3484+
var childMinimumSize = child.MinimumSize;
3485+
var neededX = Math.Max(0, childMinimumSize.X - newSize.X);
3486+
var neededY = Math.Max(0, childMinimumSize.Y - newSize.Y);
3487+
3488+
bool exhaustSize = false;
3489+
if (neededX > 0 || neededY > 0)
3490+
{
3491+
exhaustSize = true;
3492+
_requiredSizeForDockFillNodes = new Point(Width + neededX, Height + neededY);
3493+
}
3494+
3495+
newSize.X = Math.Max(childMinimumSize.X, newSize.X);
3496+
newSize.Y = Math.Max(childMinimumSize.Y, newSize.Y);
3497+
34643498
if (child is IAutoSizeToContents { AutoSizeToContents: true })
34653499
{
34663500
if (Pos.Right == (dock & (Pos.Right | Pos.Left)))
@@ -3489,14 +3523,17 @@ protected virtual void RecurseLayout(Skin.Base skin)
34893523
}
34903524
else
34913525
{
3492-
Point newSize = new(
3493-
remainingBounds.Width - childMarginH,
3494-
remainingBounds.Height - childMarginV
3495-
);
3496-
34973526
ApplyDockFill(child, newPosition, newSize);
34983527
}
34993528

3529+
if (exhaustSize)
3530+
{
3531+
remainingBounds.X += remainingBounds.Width;
3532+
remainingBounds.Width = 0;
3533+
remainingBounds.Y += remainingBounds.Height;
3534+
remainingBounds.Height = 0;
3535+
}
3536+
35003537
child.RecurseLayout(skin);
35013538
}
35023539

@@ -3508,6 +3545,11 @@ protected virtual void RecurseLayout(Skin.Base skin)
35083545
deferredAction();
35093546
}
35103547

3548+
if (sizeToFitDockFillNodes != default)
3549+
{
3550+
3551+
}
3552+
35113553
// ReSharper disable once InvertIf
35123554
if (_canvas is { } canvas)
35133555
{
@@ -3733,6 +3775,11 @@ public virtual bool DragAndDrop_CanAcceptPackage(Package p)
37333775
/// <returns>True if bounds changed.</returns>
37343776
public virtual bool SizeToChildren(bool resizeX = true, bool resizeY = true, bool recursive = false)
37353777
{
3778+
if (!resizeX && !resizeY)
3779+
{
3780+
return false;
3781+
}
3782+
37363783
if (recursive)
37373784
{
37383785
var children = mChildren.ToArray();
@@ -3756,6 +3803,13 @@ public virtual bool SizeToChildren(bool resizeX = true, bool resizeY = true, boo
37563803
size.X = size.X < 0 ? Width : (size.X + paddingH);
37573804
size.Y = size.Y < 0 ? Height : (size.Y + paddingV);
37583805

3806+
if (_requiredSizeForDockFillNodes != default)
3807+
{
3808+
size.X = Math.Max(_requiredSizeForDockFillNodes.X, size.X);
3809+
size.Y = Math.Max(_requiredSizeForDockFillNodes.Y, size.Y);
3810+
_requiredSizeForDockFillNodes = default;
3811+
}
3812+
37593813
size.X = Math.Max(Math.Min(size.X, _maximumSize.X < 1 ? size.X : _maximumSize.X), _minimumSize.X);
37603814
size.Y = Math.Max(Math.Min(size.Y, _maximumSize.Y < 1 ? size.Y : _maximumSize.Y), _minimumSize.Y);
37613815

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,9 @@ public override void LoadJson(JToken obj, bool isRoot = default)
420420

421421
if (obj["TextColor"] != null)
422422
{
423-
TextColor = Color.FromString((string)obj["TextColor"]);
423+
mNormalTextColor = Color.FromString((string)obj["TextColor"]);
424424
}
425425

426-
mNormalTextColor = TextColor;
427426
if (obj["HoveredTextColor"] != null)
428427
{
429428
mHoverTextColor = Color.FromString((string)obj["HoveredTextColor"]);

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

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77

88
namespace Intersect.Client.Framework.Gwen.Control;
99

10-
public partial class LabeledSlider : Base, IAutoSizeToContents, INumericInput, ITextContainer
10+
public partial class LabeledSlider : Base, ISmartAutoSizeToContents, INumericInput, ITextContainer
1111
{
1212
private readonly Label _label;
1313
private readonly Slider _slider;
1414
private readonly TextBoxNumeric _sliderValue;
1515
private double _scale = 1.0;
1616
private int _rounding = -1;
17-
private bool _autoSizeToContents;
1817
private bool _recomputeValueMinimumSize = true;
18+
private bool _autoSizeToContentWidth;
19+
private bool _autoSizeToContentHeight;
20+
private bool _autoSizeToContentWidthOnChildResize;
21+
private bool _autoSizeToContentHeightOnChildResize;
1922

2023
/// <summary>
2124
/// Initializes a new instance of the <see cref="LabeledSlider" /> class.
@@ -24,6 +27,8 @@ public partial class LabeledSlider : Base, IAutoSizeToContents, INumericInput, I
2427
/// <param name="name"></param>
2528
public LabeledSlider(Base parent, string? name = default) : base(parent: parent, name: name)
2629
{
30+
DockChildSpacing = new Padding(4);
31+
2732
_label = new Label(this, nameof(_label))
2833
{
2934
Alignment = [Alignments.CenterV],
@@ -49,6 +54,7 @@ public LabeledSlider(Base parent, string? name = default) : base(parent: parent,
4954
if (_rounding > -1)
5055
{
5156
newValue = Math.Round(newValue, _rounding);
57+
_slider.SetValue(newValue, skipEvents: true);
5258
}
5359

5460
_sliderValue.SetValue(newValue, skipEvents: true);
@@ -75,7 +81,7 @@ public LabeledSlider(Base parent, string? name = default) : base(parent: parent,
7581
);
7682
};
7783

78-
_autoSizeToContents = true;
84+
AutoSizeToContentHeight = true;
7985
KeyboardInputEnabled = true;
8086
IsTabable = true;
8187
}
@@ -111,8 +117,8 @@ public GameFont? Font
111117

112118
public Point SliderSize
113119
{
114-
get => _slider.Size;
115-
set => _slider.Size = value;
120+
get => _slider.MinimumSize;
121+
set => _slider.MinimumSize = value;
116122
}
117123

118124
public bool IsValueInputEnabled
@@ -273,9 +279,9 @@ protected override void Layout(Skin.Base skin)
273279
_sliderValue.MinimumSize = ComputeMinimumSizeForSliderValue(Maximum);
274280
}
275281

276-
if (_autoSizeToContents)
282+
if (AutoSizeToContents)
277283
{
278-
SizeToChildren();
284+
SizeToChildren(resizeX: AutoSizeToContentWidth, resizeY: AutoSizeToContentHeight);
279285
}
280286

281287
var orientation = _slider.Orientation;
@@ -284,32 +290,32 @@ protected override void Layout(Skin.Base skin)
284290
case Orientation.LeftToRight:
285291
_label.Dock = Pos.Left;
286292
_label.Alignment = [Alignments.CenterV];
287-
_slider.Dock = Pos.Left;
293+
_slider.Dock = Pos.Fill;
288294
_slider.Alignment = [Alignments.CenterV];
289295
_slider.Margin = new Margin(4, 0, 0, 0);
290-
_sliderValue.Dock = Pos.Left;
296+
_sliderValue.Dock = Pos.Right;
291297
_sliderValue.Alignment = [Alignments.CenterV];
292298
_sliderValue.Margin = new Margin(4, 0, 0, 0);
293299
break;
294300
case Orientation.RightToLeft:
295301
_label.Dock = Pos.Right | Pos.CenterV;
296-
_slider.Dock = Pos.Right | Pos.CenterV;
302+
_slider.Dock = Pos.Fill;
297303
_slider.Margin = new Margin(0, 0, 4, 0);
298-
_sliderValue.Dock = Pos.Right;
304+
_sliderValue.Dock = Pos.Left;
299305
_sliderValue.Margin = new Margin(0, 0, 4, 0);
300306
break;
301307
case Orientation.TopToBottom:
302308
_label.Dock = Pos.Top;
303-
_slider.Dock = Pos.Top;
309+
_slider.Dock = Pos.Fill;
304310
_slider.Margin = new Margin(0, 4, 0, 0);
305-
_sliderValue.Dock = Pos.Top;
311+
_sliderValue.Dock = Pos.Bottom;
306312
_sliderValue.Margin = new Margin(0, 4, 0, 0);
307313
break;
308314
case Orientation.BottomToTop:
309315
_label.Dock = Pos.Bottom;
310-
_slider.Dock = Pos.Bottom;
316+
_slider.Dock = Pos.Fill;
311317
_slider.Margin = new Margin(0, 0, 0, 4);
312-
_sliderValue.Dock = Pos.Bottom;
318+
_sliderValue.Dock = Pos.Top;
313319
_sliderValue.Margin = new Margin(0, 0, 0, 4);
314320
break;
315321
default:
@@ -326,17 +332,57 @@ public override void SetToolTipText(string? text)
326332
_sliderValue.SetToolTipText(text);
327333
}
328334

335+
protected override void OnSizeChanged(Point oldSize, Point newSize)
336+
{
337+
base.OnSizeChanged(oldSize, newSize);
338+
}
339+
329340
protected override void OnBoundsChanged(Rectangle oldBounds, Rectangle newBounds)
330341
{
331342
base.OnBoundsChanged(oldBounds, newBounds);
332343
}
333344

345+
protected override void OnChildSizeChanged(Base child, Point oldChildSize, Point newChildSize)
346+
{
347+
base.OnChildSizeChanged(child, oldChildSize, newChildSize);
348+
349+
SizeToChildren(resizeX: AutoSizeToContentWidthOnChildResize, resizeY: AutoSizeToContentHeightOnChildResize);
350+
}
351+
334352
public void SetRange(double min, double max) => (Minimum, Maximum) = (min, max);
335353

336354
public bool AutoSizeToContents
337355
{
338-
get => _autoSizeToContents;
339-
set => SetAndDoIfChanged(ref _autoSizeToContents, value, Invalidate);
356+
get => AutoSizeToContentWidth || AutoSizeToContentHeight;
357+
set
358+
{
359+
AutoSizeToContentWidth = value;
360+
AutoSizeToContentHeight = value;
361+
}
362+
}
363+
364+
public bool AutoSizeToContentWidth
365+
{
366+
get => _autoSizeToContentWidth;
367+
set => SetAndDoIfChanged(ref _autoSizeToContentWidth, value, Invalidate);
368+
}
369+
370+
public bool AutoSizeToContentHeight
371+
{
372+
get => _autoSizeToContentHeight;
373+
set => SetAndDoIfChanged(ref _autoSizeToContentHeight, value, Invalidate);
374+
}
375+
376+
public bool AutoSizeToContentWidthOnChildResize
377+
{
378+
get => _autoSizeToContentWidthOnChildResize;
379+
set => SetAndDoIfChanged(ref _autoSizeToContentWidthOnChildResize, value, Invalidate);
380+
}
381+
382+
public bool AutoSizeToContentHeightOnChildResize
383+
{
384+
get => _autoSizeToContentHeightOnChildResize;
385+
set => SetAndDoIfChanged(ref _autoSizeToContentHeightOnChildResize, value, Invalidate);
340386
}
341387

342388
public override void Focus(bool moveMouse = false)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ public Point DraggerSize
170170
set => _sliderBar.Size = value;
171171
}
172172

173+
public override bool SizeToChildren(bool resizeX = true, bool resizeY = true, bool recursive = false)
174+
{
175+
return false;
176+
}
177+
173178
public override JObject? GetJson(bool isRoot = false, bool onlySerializeIfNotEmpty = false)
174179
{
175180
var serializedProperties = base.GetJson(isRoot, onlySerializeIfNotEmpty);

0 commit comments

Comments
 (0)