diff --git a/Blish HUD/Controls/Container.cs b/Blish HUD/Controls/Container.cs
index ea35db8f8..4c7028d17 100644
--- a/Blish HUD/Controls/Container.cs
+++ b/Blish HUD/Controls/Container.cs
@@ -118,6 +118,60 @@ public Point AutoSizePadding {
set => SetProperty(ref _autoSizePadding, value);
}
+ protected Scrollbar _panelScrollbar;
+
+ protected Vector2 _scrollPadding = new Vector2(4, 0);
+ ///
+ /// Padding on the left side of the .
+ ///
+ public Vector2 ScrollPadding {
+ get => _scrollPadding;
+ set => SetProperty(ref _scrollPadding, value, true);
+ }
+
+ ///
+ /// Indicates whether or not there is a drawn inside the .
+ ///
+ public bool ScrollbarVisible {
+ //get => _panelScrollbar != null && _panelScrollbar.Drawn;
+ //get => _panelScrollbar != null;
+ get => _scrollbarVisible;
+ protected set => SetProperty(ref _scrollbarVisible, value, true);
+ }
+ protected bool _scrollbarVisible = false;
+
+ ///
+ /// Space which is taken from the to be drawn inside the .
+ ///
+ public int ScrollbarWidth {
+ get => _panelScrollbar != null ? (_panelScrollbar.ScrollbarWidth + (int) ScrollPadding.X) : 0;
+ }
+
+ protected Point _maxSize = Point.Zero;
+ ///
+ /// Maximum Size the can autoresize to.
+ ///
+ public Point MaxSize {
+ get => _maxSize;
+ protected set => SetProperty(ref _maxSize, value, true);
+ }
+
+ ///
+ /// Maximum Width the can autoresize to.
+ ///
+ public int MaxWidth {
+ get => _maxSize.X;
+ protected set => SetProperty(ref _maxSize.X, value, true);
+ }
+
+ ///
+ /// Maximum Height the can autoresize to.
+ ///
+ public int MaxHeight{
+ get => _maxSize.Y;
+ protected set => SetProperty(ref _maxSize.Y, value, true);
+ }
+
protected override CaptureType CapturesInput() => CaptureType.Mouse | CaptureType.MouseWheel;
public IEnumerable GetDescendants() {
@@ -146,6 +200,7 @@ public IEnumerable GetChildrenOfType() {
public bool AddChild(Control child) {
if (_children.Contains(child)) return true;
+ if (_panelScrollbar != null && child == _panelScrollbar) return true;
var resultingChildren = _children.ToList();
resultingChildren.Add(child);
@@ -234,20 +289,25 @@ public sealed override void DoUpdate(GameTime gameTime) {
UpdateContainer(gameTime);
Control[] children = _children.ToArray();
+ var filteredChildren = children.Where(c => c.GetType() != typeof(Scrollbar) && c.Visible).ToArray();
+
+ _contentBounds = ControlUtil.GetControlBounds(filteredChildren);
- _contentBounds = ControlUtil.GetControlBounds(children);
+ var limitSize = _maxSize != Point.Zero;
// Update our size based on the sizing mode
var parent = this.Parent;
- if (parent != null) {
+ if (parent != null) {
this.Size = new Point(GetUpdatedSizing(this.WidthSizingMode,
- this.Width,
- _contentBounds.X + (this.Width - this.ContentRegion.Width) + _autoSizePadding.X,
- parent.ContentRegion.Width - this.Left),
+ limitSize ? Math.Min(_maxSize.X, this.Width) : this.Width,
+ limitSize ? Math.Min(_maxSize.X, _contentBounds.X + (this.Width - this.ContentRegion.Width) + _autoSizePadding.X) : _contentBounds.X + (this.Width - this.ContentRegion.Width) + _autoSizePadding.X,
+ limitSize ? Math.Min(_maxSize.X, parent.ContentRegion.Width - this.Left) : parent.ContentRegion.Width - this.Left),
GetUpdatedSizing(this.HeightSizingMode,
- this.Height,
- _contentBounds.Y + (this.Height - this.ContentRegion.Height) + _autoSizePadding.Y,
- parent.ContentRegion.Height - this.Top));
+ limitSize ? Math.Min(_maxSize.Y, this.Height) : this.Height,
+ limitSize ? Math.Min(_maxSize.Y, _contentBounds.Y + (this.Height - this.ContentRegion.Height) + _autoSizePadding.Y) : _contentBounds.Y + (this.Height - this.ContentRegion.Height) + _autoSizePadding.Y,
+ limitSize ? Math.Min(_maxSize.Y, parent.ContentRegion.Height - this.Top) : parent.ContentRegion.Height - this.Top));
+
+ ScrollbarVisible = _contentBounds.Y > this.Height;
}
// Update our children
@@ -280,8 +340,9 @@ protected sealed override void Paint(SpriteBatch spriteBatch, Rectangle bounds)
public virtual void PaintBeforeChildren(SpriteBatch spriteBatch, Rectangle bounds) { /* NOOP */ }
protected void PaintChildren(SpriteBatch spriteBatch, Rectangle bounds, Rectangle scissor) {
- var contentScissor = Rectangle.Intersect(scissor, ContentRegion.ToBounds(this.AbsoluteBounds));
-
+ var cR = ContentRegion.ToBounds(this.AbsoluteBounds);
+ var contentScissor = Rectangle.Intersect(scissor, cR);
+
var zSortedChildren = _children.ToArray().OrderBy(i => i.ZIndex);
// Render each visible child
@@ -303,6 +364,8 @@ protected override void DisposeControl() {
descendant.Dispose();
}
+ _panelScrollbar?.Dispose();
+
base.DisposeControl();
}
diff --git a/Blish HUD/Controls/FlowPanel.cs b/Blish HUD/Controls/FlowPanel.cs
index 3e4275d9c..a78ea2de6 100644
--- a/Blish HUD/Controls/FlowPanel.cs
+++ b/Blish HUD/Controls/FlowPanel.cs
@@ -172,7 +172,7 @@ private void ReflowChildLayoutLeftToRight(IEnumerable allChildren) {
foreach (var child in allChildren.Where(c => c.Visible)) {
// Need to flow over to the next row
- if (child.Width >= this.Width - lastRight) {
+ if (child.Width >= this.ContentRegion.Width - lastRight) {
currentBottom = nextBottom + _controlPadding.Y;
lastRight = outerPadX;
}
@@ -192,13 +192,13 @@ private void ReflowChildLayoutRightToLeft(IEnumerable allChildren) {
float nextBottom = outerPadY;
float currentBottom = outerPadY;
- float lastLeft = this.Width - outerPadX;
+ float lastLeft = this.ContentRegion.Width - outerPadX;
foreach (var child in allChildren.Where(c => c.Visible)) {
// Need to flow over to the next row
if (outerPadX > lastLeft - child.Width) {
currentBottom = nextBottom + _controlPadding.Y;
- lastLeft = this.Width - outerPadX;
+ lastLeft = this.ContentRegion.Width - outerPadX;
}
child.Location = new Point((int) (lastLeft - child.Width), (int) currentBottom);
@@ -275,7 +275,7 @@ private void ReflowChildLayoutSingleRightToLeft(IEnumerable allChildren
float outerPadX = _padLeftBeforeControl ? _controlPadding.X : _outerControlPadding.X;
float outerPadY = _padTopBeforeControl ? _controlPadding.Y : _outerControlPadding.Y;
- var lastLeft = this.Width - outerPadX;
+ var lastLeft = this.ContentRegion.Width - outerPadX;
foreach (var child in allChildren) {
child.Location = new Point((int) (lastLeft - child.Width), (int) outerPadY);
@@ -350,4 +350,4 @@ protected override void DisposeControl() {
}
}
-}
+}
\ No newline at end of file
diff --git a/Blish HUD/Controls/Panel.cs b/Blish HUD/Controls/Panel.cs
index cdb3d4eef..739404a0a 100644
--- a/Blish HUD/Controls/Panel.cs
+++ b/Blish HUD/Controls/Panel.cs
@@ -115,7 +115,6 @@ public override SizingMode HeightSizingMode {
[JsonIgnore] public float AccentOpacity { get; set; } = 1f;
private Glide.Tween _collapseAnim;
- private Scrollbar _panelScrollbar;
///
public bool ToggleAccordionState() {
@@ -242,12 +241,14 @@ public override void RecalculateLayout() {
_layoutLeftAccentSrc = new Rectangle(0, 0, _textureLeftSideAccent.Width, _layoutLeftAccentBounds.Height);
}
+ ScrollbarVisible = _contentBounds.Y > (_size.Y - topOffset - bottomOffset);
+
this.ContentRegion = new Rectangle(leftOffset,
topOffset,
- _size.X - leftOffset - rightOffset,
+ _size.X - leftOffset - rightOffset - (ScrollbarVisible ? (ScrollbarWidth / 2) + (ScrollbarVisible ? 0 : RIGHT_PADDING) : 0),
_size.Y - topOffset - bottomOffset);
- _layoutHeaderBounds = new Rectangle(this.ContentRegion.Left, 0, this.ContentRegion.Width, HEADER_HEIGHT);
+ _layoutHeaderBounds = new Rectangle(this.ContentRegion.Left, 0, this.ContentRegion.Width, HEADER_HEIGHT);
_layoutHeaderTextBounds = new Rectangle(_layoutHeaderBounds.Left + 10, 0, _layoutHeaderBounds.Width - 10, HEADER_HEIGHT);
_layoutAccordionArrowOrigin = new Vector2((float)ARROW_SIZE / 2, (float)ARROW_SIZE / 2);
@@ -255,13 +256,19 @@ public override void RecalculateLayout() {
(topOffset - ARROW_SIZE) / 2,
ARROW_SIZE,
ARROW_SIZE).OffsetBy(_layoutAccordionArrowOrigin.ToPoint());
+
+ if (_panelScrollbar != null) {
+ _panelScrollbar.Height = this.ContentRegion.Height - 20;
+ _panelScrollbar.Right = this.Right;
+ _panelScrollbar.Top = this.Top + this.ContentRegion.Top + 10;
+ }
}
private void UpdateScrollbar() {
/* TODO: Fix .CanScroll: currently you have to set it after you set other region changing settings for it
to work correctly */
if (this.CanScroll) {
- if (_panelScrollbar == null)
+ if (_panelScrollbar == null)
_panelScrollbar = new Scrollbar(this);
this.PropertyChanged -= UpdatePanelScrollbarOnOwnPropertyChanged;
@@ -269,7 +276,7 @@ to work correctly */
_panelScrollbar.Parent = this.Parent;
_panelScrollbar.Height = this.ContentRegion.Height - 20;
- _panelScrollbar.Right = this.Right - _panelScrollbar.Width / 2;
+ _panelScrollbar.Right = this.Right;
_panelScrollbar.Top = this.Top + this.ContentRegion.Top + 10;
_panelScrollbar.Visible = this.Visible;
_panelScrollbar.ZIndex = this.ZIndex + 2;
@@ -291,7 +298,7 @@ private void UpdatePanelScrollbarOnOwnPropertyChanged(object? sender, PropertyCh
_panelScrollbar.Height = this.ContentRegion.Height - 20;
break;
case "Right":
- _panelScrollbar.Right = this.Right - _panelScrollbar.Width / 2;
+ _panelScrollbar.Right = this.Right;
break;
case "Top":
_panelScrollbar.Top = this.Top + this.ContentRegion.Top + 10;
@@ -389,8 +396,6 @@ public override void PaintBeforeChildren(SpriteBatch spriteBatch, Rectangle boun
}
protected override void DisposeControl() {
- _panelScrollbar?.Dispose();
-
foreach (var control in this._children) {
control.Resized -= UpdateContentRegionBounds;
control.Moved -= UpdateContentRegionBounds;
@@ -400,4 +405,4 @@ protected override void DisposeControl() {
}
}
-}
+}
\ No newline at end of file
diff --git a/Blish HUD/Controls/Scrollbar.cs b/Blish HUD/Controls/Scrollbar.cs
index 13db516ef..f2037ea8d 100644
--- a/Blish HUD/Controls/Scrollbar.cs
+++ b/Blish HUD/Controls/Scrollbar.cs
@@ -91,6 +91,22 @@ private int ScrollbarHeight {
private double _scrollbarPercent = 1.0;
+ ///
+ /// See if the is beeing drawn.
+ ///
+ public bool Drawn
+ {
+ get => Visible && _scrollbarPercent < 0.99;
+ }
+
+ ///
+ /// Width of the .
+ ///
+ public int ScrollbarWidth
+ {
+ get => _barBounds.Width;
+ }
+
private Container _associatedContainer;
public Container AssociatedContainer {
get => _associatedContainer;
@@ -298,4 +314,4 @@ protected override void Paint(SpriteBatch spriteBatch, Rectangle bounds) {
}
}
-}
+}
\ No newline at end of file
diff --git a/Blish HUD/Properties/launchSettings.json b/Blish HUD/Properties/launchSettings.json
index 7ca9b6158..dae7c9389 100644
--- a/Blish HUD/Properties/launchSettings.json
+++ b/Blish HUD/Properties/launchSettings.json
@@ -8,4 +8,4 @@
"commandLineArgs": "-p powershell -w ConsoleWindowClass"
}
}
-}
+}
\ No newline at end of file