Fixed content scrolling

This commit is contained in:
Tig
2024-10-17 12:10:41 -06:00
parent 8c7982f9c0
commit ed80c66e13
4 changed files with 60 additions and 44 deletions

View File

@@ -43,27 +43,6 @@ public class Margin : Adornment
}
ShadowStyle = base.ShadowStyle;
Add (
_rightShadow = new ()
{
X = Pos.AnchorEnd (1),
Y = 0,
Width = 1,
Height = Dim.Fill (),
ShadowStyle = ShadowStyle,
Orientation = Orientation.Vertical
},
_bottomShadow = new ()
{
X = 0,
Y = Pos.AnchorEnd (1),
Width = Dim.Fill (),
Height = 1,
ShadowStyle = ShadowStyle,
Orientation = Orientation.Horizontal
}
);
}
/// <summary>
@@ -135,9 +114,18 @@ public class Margin : Adornment
/// </summary>
public ShadowStyle SetShadow (ShadowStyle style)
{
if (ShadowStyle == style)
if (_rightShadow is { })
{
// return style;
Remove (_rightShadow);
_rightShadow.Dispose ();
_rightShadow = null;
}
if (_bottomShadow is { })
{
Remove (_bottomShadow);
_bottomShadow.Dispose ();
_bottomShadow = null;
}
if (ShadowStyle != ShadowStyle.None)
@@ -152,14 +140,28 @@ public class Margin : Adornment
Thickness = new (Thickness.Left, Thickness.Top, Thickness.Right + 1, Thickness.Bottom + 1);
}
if (_rightShadow is { })
if (style != ShadowStyle.None)
{
_rightShadow.ShadowStyle = style;
}
_rightShadow = new ()
{
X = Pos.AnchorEnd (1),
Y = 0,
Width = 1,
Height = Dim.Fill (),
ShadowStyle = style,
Orientation = Orientation.Vertical
};
if (_bottomShadow is { })
{
_bottomShadow.ShadowStyle = style;
_bottomShadow = new ()
{
X = 0,
Y = Pos.AnchorEnd (1),
Width = Dim.Fill (),
Height = 1,
ShadowStyle = style,
Orientation = Orientation.Horizontal
};
Add (_rightShadow, _bottomShadow);
}
return style;
@@ -169,7 +171,11 @@ public class Margin : Adornment
public override ShadowStyle ShadowStyle
{
get => base.ShadowStyle;
set => base.ShadowStyle = SetShadow (value);
set
{
base.ShadowStyle = SetShadow (value);
}
}
private const int PRESS_MOVE_HORIZONTAL = 1;

View File

@@ -700,6 +700,11 @@ public partial class View // Drawing APIs
SuperView?.SetSubViewNeedsDisplay ();
if (this is Adornment adornment)
{
adornment.Parent?.SetSubViewNeedsDisplay ();
}
foreach (View subview in Subviews)
{
if (subview.Frame.IntersectsWith (region))

View File

@@ -822,12 +822,12 @@ public partial class View // Layout APIs
TextFormatter.NeedsFormat = true;
SuperView?.SetLayoutNeeded ();
if (this is Adornment adornment)
{
adornment.Parent?.SetLayoutNeeded ();
}
SuperView?.SetLayoutNeeded ();
}
/// <summary>

View File

@@ -47,7 +47,7 @@ public class ContentScrolling : Scenario
// Add a status label to the border that shows Viewport and ContentSize values. Bit of a hack.
// TODO: Move to Padding with controls
Border.Add (new Label { X = 20 });
LayoutComplete += VirtualDemoView_LayoutComplete;
ViewportChanged += VirtualDemoView_LayoutComplete;
MouseEvent += VirtualDemoView_MouseEvent;
}
@@ -81,18 +81,14 @@ public class ContentScrolling : Scenario
}
}
private void VirtualDemoView_LayoutComplete (object sender, LayoutEventArgs e)
private void VirtualDemoView_LayoutComplete (object sender, DrawEventArgs drawEventArgs)
{
Label status = Border.Subviews.OfType<Label> ().FirstOrDefault ();
Label frameLabel = Padding.Subviews.OfType<Label> ().FirstOrDefault ();
if (status is { })
if (frameLabel is { })
{
status.Title = $"Frame: {Frame}\n\nViewport: {Viewport}, ContentSize = {GetContentSize ()}";
status.Width = Border.Frame.Width - status.Frame.X - Border.Thickness.Right;
status.Height = Border.Thickness.Top;
frameLabel.Text = $"Viewport: {Viewport}\nFrame: {Frame}";
}
SetNeedsDisplay ();
}
}
@@ -126,14 +122,22 @@ public class ContentScrolling : Scenario
app.Add (view);
// Add Scroll Setting UI to Padding
view.Padding.Thickness = new (0, 3, 0, 0);
view.Padding.Thickness = new (0, 5, 0, 0);
view.Padding.ColorScheme = Colors.ColorSchemes ["Error"];
view.Padding.CanFocus = true;
Label frameLabel = new ()
{
Text = "Frame\nContent",
Id = "frameLabel",
Y = 0
};
view.Padding.Add (frameLabel);
var cbAllowNegativeX = new CheckBox
{
Title = "Allow _X < 0",
Y = 0,
Y = Pos.Bottom(frameLabel),
CanFocus = true
};
cbAllowNegativeX.CheckedState = view.ViewportSettings.HasFlag(ViewportSettings.AllowNegativeX) ? CheckState.Checked : CheckState.UnChecked;
@@ -157,7 +161,7 @@ public class ContentScrolling : Scenario
{
Title = "Allow _Y < 0",
X = Pos.Right (cbAllowNegativeX) + 1,
Y = 0,
Y = Pos.Bottom (frameLabel),
CanFocus = true
};
cbAllowNegativeY.CheckedState = view.ViewportSettings.HasFlag(ViewportSettings.AllowNegativeY) ? CheckState.Checked : CheckState.UnChecked;
@@ -413,6 +417,7 @@ public class ContentScrolling : Scenario
editor.AutoSelectSuperView = view;
editor.AutoSelectAdornments = false;
view.SetFocus ();
Application.Run (app);
app.Dispose ();
Application.Shutdown ();