Fix some KeepContentInAllViewport bugs.

This commit is contained in:
BDisp
2024-09-04 23:06:17 +01:00
parent 07d7162c8f
commit 14e2e3cbb6
4 changed files with 47 additions and 16 deletions

View File

@@ -54,22 +54,27 @@ public class Scroll : View
_keepContentInAllViewport = value;
var pos = 0;
if (value && Orientation == Orientation.Horizontal && _position + SuperViewAsScrollBar!.Viewport.Width > Size)
if (value
&& Orientation == Orientation.Horizontal
&& _position + (SuperViewAsScrollBar is { } ? SuperViewAsScrollBar.Viewport.Width : Viewport.Width) > Size)
{
pos = Size - SuperViewAsScrollBar.Viewport.Width;
pos = Size - (SuperViewAsScrollBar is { } ? SuperViewAsScrollBar.Viewport.Width : Viewport.Width);
}
if (value && Orientation == Orientation.Vertical && _position + SuperViewAsScrollBar!.Viewport.Height > Size)
if (value
&& Orientation == Orientation.Vertical
&& _position + (SuperViewAsScrollBar is { } ? SuperViewAsScrollBar.Viewport.Height : Viewport.Height) > Size)
{
pos = _size - SuperViewAsScrollBar.Viewport.Height;
pos = _size - (SuperViewAsScrollBar is { } ? SuperViewAsScrollBar.Viewport.Height : Viewport.Height);
}
if (pos != 0)
{
Position = pos;
SetNeedsDisplay ();
AdjustScroll ();
}
SetNeedsDisplay ();
AdjustScroll ();
}
}
}
@@ -175,12 +180,12 @@ public class Scroll : View
}
else if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed) && location > sliderPos.end)
{
Position = Math.Min (Position + barSize, Size - barSize);
Position = Math.Min (Position + barSize, Size - barSize + (KeepContentInAllViewport ? 0 : barSize));
}
else if ((mouseEvent.Flags == MouseFlags.WheeledDown && Orientation == Orientation.Vertical)
|| (mouseEvent.Flags == MouseFlags.WheeledRight && Orientation == Orientation.Horizontal))
{
Position = Math.Min (Position + 1, Size - barSize);
Position = Math.Min (Position + 1, Size - barSize + (KeepContentInAllViewport ? 0 : barSize));
}
else if ((mouseEvent.Flags == MouseFlags.WheeledUp && Orientation == Orientation.Vertical)
|| (mouseEvent.Flags == MouseFlags.WheeledLeft && Orientation == Orientation.Horizontal))

View File

@@ -89,8 +89,13 @@ internal class ScrollSlider : View
{
if (SuperViewAsScroll.Orientation == Orientation.Vertical)
{
Y = Frame.Y + offset < 0 ? 0 :
Frame.Y + offset + Frame.Height > barSize ? Math.Max (barSize - Frame.Height, 0) : Frame.Y + offset;
Y = Frame.Y + offset < 0
? 0
:
Frame.Y + offset + Frame.Height > barSize + (SuperViewAsScroll.KeepContentInAllViewport ? 0 : barSize)
?
Math.Max (barSize - Frame.Height, 0)
: Frame.Y + offset;
SuperViewAsScroll.Position = GetPositionFromSliderLocation (Frame.Y);
}
@@ -157,7 +162,7 @@ internal class ScrollSlider : View
if ((SuperViewAsScroll.Orientation == Orientation.Vertical && location + Frame.Height >= scrollSize)
|| (SuperViewAsScroll.Orientation == Orientation.Horizontal && location + Frame.Width >= scrollSize))
{
return SuperViewAsScroll.Size - scrollSize;
return SuperViewAsScroll.Size - scrollSize + (SuperViewAsScroll.KeepContentInAllViewport ? 0 : scrollSize);
}
return (int)Math.Min (Math.Round ((double)(location * SuperViewAsScroll.Size + location) / scrollSize), SuperViewAsScroll.Size - scrollSize);

View File

@@ -182,14 +182,27 @@ public class ScrollBarDemo : Scenario
}
};
var ckbAutoHideScrollBar = new CheckBox { Y = Pos.Bottom (scrollPosition), Text = "AutoHideScrollBar" };
ckbAutoHideScrollBar.CheckedStateChanging += (s, e) => scrollBar.AutoHide = e.NewValue == CheckState.Checked;
view.Add (ckbAutoHideScrollBar);
var ckbAutoHide = new CheckBox
{ Y = Pos.Bottom (scrollPosition), Text = "AutoHideScrollBar", CheckedState = scrollBar.AutoHide ? CheckState.Checked : CheckState.UnChecked };
ckbAutoHide.CheckedStateChanging += (s, e) => scrollBar.AutoHide = e.NewValue == CheckState.Checked;
view.Add (ckbAutoHide);
var ckbShowScrollIndicator = new CheckBox { X = Pos.Right (ckbAutoHideScrollBar) + 1, Y = Pos.Bottom (scrollPosition), Text = "ShowScrollIndicator" };
var ckbShowScrollIndicator = new CheckBox
{
X = Pos.Right (ckbAutoHide) + 1, Y = Pos.Bottom (scrollPosition), Text = "ShowScrollIndicator",
CheckedState = scrollBar.ShowScrollIndicator ? CheckState.Checked : CheckState.UnChecked
};
ckbShowScrollIndicator.CheckedStateChanging += (s, e) => scrollBar.ShowScrollIndicator = e.NewValue == CheckState.Checked;
view.Add (ckbShowScrollIndicator);
var ckbKeepContentInAllViewport = new CheckBox
{
X = Pos.Right (ckbShowScrollIndicator) + 1, Y = Pos.Bottom (scrollPosition), Text = "KeepContentInAllViewport",
CheckedState = scrollBar.KeepContentInAllViewport ? CheckState.Checked : CheckState.UnChecked
};
ckbKeepContentInAllViewport.CheckedStateChanging += (s, e) => scrollBar.KeepContentInAllViewport = e.NewValue == CheckState.Checked;
view.Add (ckbKeepContentInAllViewport);
var lblSizeChanged = new Label
{
Y = Pos.Bottom (ckbShowScrollIndicator) + 1

View File

@@ -182,9 +182,17 @@ public class ScrollDemo : Scenario
}
};
var ckbKeepContentInAllViewport = new CheckBox
{
Y = Pos.Bottom (scrollPosition), Text = "KeepContentInAllViewport",
CheckedState = scroll.KeepContentInAllViewport ? CheckState.Checked : CheckState.UnChecked
};
ckbKeepContentInAllViewport.CheckedStateChanging += (s, e) => scroll.KeepContentInAllViewport = e.NewValue == CheckState.Checked;
view.Add (ckbKeepContentInAllViewport);
var lblSizeChanged = new Label
{
Y = Pos.Bottom (lblPosition) + 1
Y = Pos.Bottom (ckbKeepContentInAllViewport) + 1
};
view.Add (lblSizeChanged);