From 4640a5905499f304155fb48000fcda41b7ecc1c6 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 26 Dec 2019 12:35:47 +0100 Subject: [PATCH] made the scroll bar scroller only render when it actually makes sense --- MLEM.Ui/Elements/ScrollBar.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/MLEM.Ui/Elements/ScrollBar.cs b/MLEM.Ui/Elements/ScrollBar.cs index 262add8..94499a8 100644 --- a/MLEM.Ui/Elements/ScrollBar.cs +++ b/MLEM.Ui/Elements/ScrollBar.cs @@ -125,12 +125,14 @@ namespace MLEM.Ui.Elements { public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) { batch.Draw(this.Background, this.DisplayArea, Color.White * alpha, this.Scale); - var scrollerPos = new Vector2(this.DisplayArea.X + this.ScrollerOffset.X, this.DisplayArea.Y + this.ScrollerOffset.Y); - var scrollerOffset = new Vector2( - !this.Horizontal ? 0 : this.currValue / this.maxValue * (this.DisplayArea.Width - this.ScrollerSize.X * this.Scale), - this.Horizontal ? 0 : this.currValue / this.maxValue * (this.DisplayArea.Height - this.ScrollerSize.Y * this.Scale)); - var scrollerRect = new RectangleF(scrollerPos + scrollerOffset, this.ScrollerSize * this.Scale); - batch.Draw(this.ScrollerTexture, scrollerRect, Color.White * alpha, this.Scale); + if (this.MaxValue > 0) { + var scrollerPos = new Vector2(this.DisplayArea.X + this.ScrollerOffset.X, this.DisplayArea.Y + this.ScrollerOffset.Y); + var scrollerOffset = new Vector2( + !this.Horizontal ? 0 : this.currValue / this.maxValue * (this.DisplayArea.Width - this.ScrollerSize.X * this.Scale), + this.Horizontal ? 0 : this.currValue / this.maxValue * (this.DisplayArea.Height - this.ScrollerSize.Y * this.Scale)); + var scrollerRect = new RectangleF(scrollerPos + scrollerOffset, this.ScrollerSize * this.Scale); + batch.Draw(this.ScrollerTexture, scrollerRect, Color.White * alpha, this.Scale); + } base.Draw(time, batch, alpha, blendState, samplerState, matrix); }