1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-07-02 17:06:36 +02:00

Fixed scroll bars doing unnecessary calculations when hidden

This commit is contained in:
Ell 2024-06-02 13:26:20 +02:00
parent 8fdc3546c6
commit d7cda0d39b
2 changed files with 63 additions and 55 deletions

View file

@ -35,6 +35,7 @@ Improvements
Fixes Fixes
- Fixed hidden scroll bars inhibiting scrolling on their parent panel - Fixed hidden scroll bars inhibiting scrolling on their parent panel
- Fixed scroll bars doing unnecessary calculations when hidden
## 6.3.1 ## 6.3.1

View file

@ -145,65 +145,72 @@ namespace MLEM.Ui.Elements {
public override void Update(GameTime time) { public override void Update(GameTime time) {
base.Update(time); base.Update(time);
// MOUSE INPUT if (!this.IsHidden) {
var moused = this.Controls.MousedElement; // MOUSE INPUT
var wasMouseUp = this.Input.WasUp(MouseButton.Left); var moused = this.Controls.MousedElement;
var isMouseDown = this.Input.IsDown(MouseButton.Left); var wasMouseUp = this.Input.WasUp(MouseButton.Left);
if (moused == this && wasMouseUp && isMouseDown) { var isMouseDown = this.Input.IsDown(MouseButton.Left);
this.isMouseScrolling = true; if (moused == this && wasMouseUp && isMouseDown) {
this.scrollStartOffset = this.TransformInverseAll(this.Input.ViewportMousePosition.ToVector2()) - this.ScrollerPosition; this.isMouseScrolling = true;
} else if (!isMouseDown) { this.scrollStartOffset = this.TransformInverseAll(this.Input.ViewportMousePosition.ToVector2()) - this.ScrollerPosition;
this.isMouseScrolling = false; } else if (!isMouseDown) {
} this.isMouseScrolling = false;
if (this.isMouseScrolling)
this.ScrollToPos(this.TransformInverseAll(this.Input.ViewportMousePosition.ToVector2()));
if (!this.Horizontal) {
if (this.IsMousedForScrolling(moused)) {
var scroll = this.Input.LastScrollWheel - this.Input.ScrollWheel;
if (scroll != 0)
this.CurrentValue += this.StepPerScroll * Math.Sign(scroll);
if (this.MouseDragScrolling && moused != this && wasMouseUp && isMouseDown)
this.isMouseDragging = true;
} }
if (!isMouseDown) if (this.isMouseScrolling)
this.isMouseDragging = false; this.ScrollToPos(this.TransformInverseAll(this.Input.ViewportMousePosition.ToVector2()));
if (this.isMouseDragging) if (!this.Horizontal) {
this.CurrentValue -= (this.Input.MousePosition.Y - this.Input.LastMousePosition.Y) / this.Scale; if (this.IsMousedForScrolling(moused)) {
} var scroll = this.Input.LastScrollWheel - this.Input.ScrollWheel;
if (scroll != 0)
this.CurrentValue += this.StepPerScroll * Math.Sign(scroll);
// TOUCH INPUT if (this.MouseDragScrolling && moused != this && wasMouseUp && isMouseDown)
if (!this.Horizontal) { this.isMouseDragging = true;
// are we dragging on top of the panel?
if (this.Input.GetViewportGesture(GestureType.VerticalDrag, out var drag)) {
// if the element under the drag's start position is on top of the panel, start dragging
var touched = this.Parent.GetElementUnderPos(this.TransformInverseAll(drag.Position));
if (touched != null && touched != this)
this.isTouchDragging = true;
// if we're dragging at all, then move the scroller
if (this.isTouchDragging)
this.CurrentValue -= drag.Delta.Y / this.Scale;
} else {
this.isTouchDragging = false;
}
}
if (this.Input.ViewportTouchState.Count <= 0) {
// if no touch has occured this tick, then reset the variable
this.isTouchScrolling = false;
} else {
foreach (var loc in this.Input.ViewportTouchState) {
var pos = this.TransformInverseAll(loc.Position);
// if we just started touching and are on top of the scroller, then we should start scrolling
if (this.DisplayArea.Contains(pos) && !loc.TryGetPreviousLocation(out _)) {
this.isTouchScrolling = true;
this.scrollStartOffset = pos - this.ScrollerPosition;
break;
} }
// scroll no matter if we're on the scroller right now if (!isMouseDown)
if (this.isTouchScrolling) this.isMouseDragging = false;
this.ScrollToPos(pos); if (this.isMouseDragging)
this.CurrentValue -= (this.Input.MousePosition.Y - this.Input.LastMousePosition.Y) / this.Scale;
} }
// TOUCH INPUT
if (!this.Horizontal) {
// are we dragging on top of the panel?
if (this.Input.GetViewportGesture(GestureType.VerticalDrag, out var drag)) {
// if the element under the drag's start position is on top of the panel, start dragging
var touched = this.Parent.GetElementUnderPos(this.TransformInverseAll(drag.Position));
if (touched != null && touched != this)
this.isTouchDragging = true;
// if we're dragging at all, then move the scroller
if (this.isTouchDragging)
this.CurrentValue -= drag.Delta.Y / this.Scale;
} else {
this.isTouchDragging = false;
}
}
if (this.Input.ViewportTouchState.Count <= 0) {
// if no touch has occured this tick, then reset the variable
this.isTouchScrolling = false;
} else {
foreach (var loc in this.Input.ViewportTouchState) {
var pos = this.TransformInverseAll(loc.Position);
// if we just started touching and are on top of the scroller, then we should start scrolling
if (this.DisplayArea.Contains(pos) && !loc.TryGetPreviousLocation(out _)) {
this.isTouchScrolling = true;
this.scrollStartOffset = pos - this.ScrollerPosition;
break;
}
// scroll no matter if we're on the scroller right now
if (this.isTouchScrolling)
this.ScrollToPos(pos);
}
}
} else {
this.isMouseScrolling = false;
this.isMouseDragging = false;
this.isTouchScrolling = false;
this.isTouchDragging = false;
} }
if (this.SmoothScrolling && this.scrollAdded != 0) { if (this.SmoothScrolling && this.scrollAdded != 0) {