-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix scrollbar padding and dragging #271
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ public class ScrollBar : XNAControl | |
_scrollButton.SetParentControl(this); | ||
|
||
_totalHeight = DrawAreaWithParentOffset.Height; | ||
this.ScrollToTop(); | ||
} | ||
|
||
public override void Initialize() | ||
|
@@ -88,7 +89,7 @@ public void ScrollToTop() | |
{ | ||
ScrollOffset = 0; | ||
var pixelsPerLine = (float)(scrollArea.Height - _scrollButton.DrawArea.Height * 2) / (_totalHeight - LinesToRender); | ||
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawArea.X, _scrollButton.DrawArea.Height + pixelsPerLine * ScrollOffset); | ||
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawArea.X, 1 + _scrollButton.DrawArea.Height + pixelsPerLine * ScrollOffset); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
} | ||
|
||
public void ScrollToEnd() | ||
|
@@ -141,10 +142,10 @@ private void arrowClicked(object btn, EventArgs e) | |
} | ||
|
||
var pixelsPerLine = (float)(scrollArea.Height - _scrollButton.DrawArea.Height * 2) / (_totalHeight - LinesToRender); | ||
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, _scrollButton.DrawArea.Height + pixelsPerLine * ScrollOffset); | ||
if (_scrollButton.DrawPosition.Y > scrollArea.Height - _scrollButton.DrawArea.Height) | ||
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, 1 + _scrollButton.DrawArea.Height + pixelsPerLine * ScrollOffset); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain why the |
||
if (_scrollButton.DrawPosition.Y > 1 + scrollArea.Height - _scrollButton.DrawArea.Height) | ||
{ | ||
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, scrollArea.Height - _scrollButton.DrawArea.Height); | ||
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, 1 + scrollArea.Height - _scrollButton.DrawArea.Height); | ||
} | ||
} | ||
|
||
|
@@ -160,12 +161,17 @@ private void OnScrollButtonDragged(object btn, EventArgs e) | |
else if (y > scrollArea.Height - _scrollButton.DrawArea.Height) | ||
y = scrollArea.Height - _scrollButton.DrawArea.Height; | ||
|
||
_scrollButton.DrawPosition = new Vector2(0, y); | ||
var dif = (CurrentMouseState.ScrollWheelValue - PreviousMouseState.ScrollWheelValue) / -160; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If 160 is the height of the scrollbar, different scrollbars have different heights (chat vs shop dialog vs account create dialog), so it can't be hard-coded There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also don't see where this variable is being used |
||
var pixelsPerLine = (float)(scrollArea.Height - _scrollButton.DrawArea.Height * 2) / | ||
(_totalHeight - LinesToRender); | ||
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, 1 + (_scrollButton.DrawArea.Height + pixelsPerLine * ScrollOffset)); | ||
|
||
if (_scrollButton.DrawPosition.Y >= (scrollArea.Height - 1) - _scrollButton.DrawArea.Height) | ||
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, (scrollArea.Height - 1) - _scrollButton.DrawArea.Height); | ||
|
||
if (_totalHeight <= LinesToRender) | ||
return; | ||
|
||
var pixelsPerLine = (double)(scrollArea.Height - _scrollButton.DrawArea.Height * 2) / (_totalHeight - LinesToRender); | ||
ScrollOffset = (int)Math.Round((y - _scrollButton.DrawArea.Height) / pixelsPerLine); | ||
} | ||
|
||
|
@@ -183,10 +189,10 @@ protected override void OnUpdateControl(GameTime gt) | |
|
||
var pixelsPerLine = (float)(scrollArea.Height - _scrollButton.DrawArea.Height * 2) / | ||
(_totalHeight - LinesToRender); | ||
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, _scrollButton.DrawArea.Height + pixelsPerLine * ScrollOffset); | ||
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, 1 + (_scrollButton.DrawArea.Height + pixelsPerLine * ScrollOffset)); | ||
|
||
if (_scrollButton.DrawPosition.Y > scrollArea.Height - _scrollButton.DrawArea.Height) | ||
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, scrollArea.Height - _scrollButton.DrawArea.Height); | ||
if (_scrollButton.DrawPosition.Y >= (scrollArea.Height - 1) - _scrollButton.DrawArea.Height) | ||
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, (scrollArea.Height - 1) - _scrollButton.DrawArea.Height); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
ScrollToTop
call here is a no-op sinceScrollOffset
is already set to0
If you want the
+1
offset then just add that to the_scrollButton
position parameter in its constructor call.