|
@@ -1,6 +1,4 @@
|
|
-using System.Diagnostics;
|
|
|
|
-
|
|
|
|
-namespace Terminal.Gui;
|
|
|
|
|
|
+namespace Terminal.Gui;
|
|
|
|
|
|
public partial class View
|
|
public partial class View
|
|
{
|
|
{
|
|
@@ -8,38 +6,9 @@ public partial class View
|
|
|
|
|
|
internal Size? _contentSize;
|
|
internal Size? _contentSize;
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// Sets the size of the View's content.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <remarks>
|
|
|
|
- /// <para>
|
|
|
|
- /// By default, the content size is set to <see langword="null"/>.
|
|
|
|
- /// </para>
|
|
|
|
- /// </remarks>
|
|
|
|
- /// <param name="contentSize">
|
|
|
|
- /// <para>
|
|
|
|
- /// If <see langword="null"/>, and the View has no visible subviews, <see cref="ContentSize"/> will track the size of <see cref="Viewport"/>.
|
|
|
|
- /// </para>
|
|
|
|
- /// <para>
|
|
|
|
- /// If <see langword="null"/>, and the View has visible subviews, <see cref="ContentSize"/> will track the maximum position plus size of any
|
|
|
|
- /// visible Subviews
|
|
|
|
- /// and <c>Viewport.Location</c> will track the minimum position and size of any visible Subviews.
|
|
|
|
- /// </para>
|
|
|
|
- /// <para>
|
|
|
|
- /// If not <see langword="null"/>, <see cref="ContentSize"/> is set to the passed value and <see cref="Viewport"/> describes the portion of the content currently visible
|
|
|
|
- /// to the user. This enables virtual scrolling.
|
|
|
|
- /// </para>
|
|
|
|
- /// <para>
|
|
|
|
- /// If not <see langword="null"/>, <see cref="ContentSize"/> is set to the passed value and the behavior of <see cref="DimAutoStyle.Content"/> will be to use the ContentSize
|
|
|
|
- /// to determine the size of the view.
|
|
|
|
- /// </para>
|
|
|
|
- /// <para>
|
|
|
|
- /// Negative sizes are not supported.
|
|
|
|
- /// </para>
|
|
|
|
- /// </param>
|
|
|
|
private void SetContentSize (Size? contentSize)
|
|
private void SetContentSize (Size? contentSize)
|
|
{
|
|
{
|
|
- if (ContentSize.Width < 0 || ContentSize.Height < 0)
|
|
|
|
|
|
+ if (contentSize is { } && (contentSize.Value.Width < 0 || contentSize.Value.Height < 0))
|
|
{
|
|
{
|
|
throw new ArgumentException (@"ContentSize cannot be negative.", nameof (contentSize));
|
|
throw new ArgumentException (@"ContentSize cannot be negative.", nameof (contentSize));
|
|
}
|
|
}
|
|
@@ -53,17 +22,80 @@ public partial class View
|
|
OnContentSizeChanged (new (_contentSize));
|
|
OnContentSizeChanged (new (_contentSize));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Gets or sets a value indicating whether the <see cref="ContentSize"/> tracks the <see cref="Viewport"/>'s size or
|
|
|
|
+ /// not.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <remarks>
|
|
|
|
+ /// <list type="bullet">
|
|
|
|
+ /// <listheader>
|
|
|
|
+ /// <term>Value</term> <description>Result</description>
|
|
|
|
+ /// </listheader>
|
|
|
|
+ /// <item>
|
|
|
|
+ /// <term>
|
|
|
|
+ /// <see langword="true"/>
|
|
|
|
+ /// </term>
|
|
|
|
+ /// <description>
|
|
|
|
+ /// <para>
|
|
|
|
+ /// <see cref="ContentSize"/> is tracking the <see cref="Viewport"/>'s size. Content scrolling will be
|
|
|
|
+ /// disabled.
|
|
|
|
+ /// </para>
|
|
|
|
+ /// <para>
|
|
|
|
+ /// The behavior of <see cref="DimAutoStyle.Content"/> will be to use position and size of the Subviews
|
|
|
|
+ /// to
|
|
|
|
+ /// determine the size of the view, ignoring <see cref="ContentSize"/>.
|
|
|
|
+ /// </para>
|
|
|
|
+ /// </description>
|
|
|
|
+ /// </item>
|
|
|
|
+ /// <item>
|
|
|
|
+ /// <term>
|
|
|
|
+ /// <see langword="false"/>
|
|
|
|
+ /// </term>
|
|
|
|
+ /// <description>
|
|
|
|
+ /// <para>
|
|
|
|
+ /// <see cref="ContentSize"/> is independent of <see cref="Viewport"/> and <see cref="Viewport"/>
|
|
|
|
+ /// describes the portion of the content currently visible to the user, bound by
|
|
|
|
+ /// <see cref="ContentSize"/>, enabling content scrolling.
|
|
|
|
+ /// </para>
|
|
|
|
+ /// <para>
|
|
|
|
+ /// The behavior of <see cref="DimAutoStyle.Content"/> will be to use <see cref="ContentSize"/> to
|
|
|
|
+ /// determine the
|
|
|
|
+ /// size of the view, ignoring the position and size of the Subviews.
|
|
|
|
+ /// </para>
|
|
|
|
+ /// </description>
|
|
|
|
+ /// </item>
|
|
|
|
+ /// </list>
|
|
|
|
+ /// </remarks>
|
|
|
|
+ public bool ContentSizeTracksViewport
|
|
|
|
+ {
|
|
|
|
+ get => _contentSize is null;
|
|
|
|
+ set => _contentSize = value ? null : _contentSize;
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets the size of the View's content.
|
|
/// Gets the size of the View's content.
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// <para>
|
|
- /// Use <see cref="SetContentSize"/> to change to change the content size.
|
|
|
|
|
|
+ /// Negative sizes are not supported.
|
|
/// </para>
|
|
/// </para>
|
|
/// <para>
|
|
/// <para>
|
|
- /// If the content size has not been explicitly set with <see cref="SetContentSize"/>, the value tracks
|
|
|
|
|
|
+ /// If not explicitly set, and the View has no visible subviews, <see cref="ContentSize"/> will track the size of
|
|
/// <see cref="Viewport"/>.
|
|
/// <see cref="Viewport"/>.
|
|
/// </para>
|
|
/// </para>
|
|
|
|
+ /// <para>
|
|
|
|
+ /// If not explicitly set, and the View has visible subviews, <see cref="ContentSize"/> will track the maximum
|
|
|
|
+ /// position + dimension of the Subviews, supporting <see cref="Dim.Auto"/> with the
|
|
|
|
+ /// <see cref="DimAutoStyle.Content"/> flag set.
|
|
|
|
+ /// </para>
|
|
|
|
+ /// <para>
|
|
|
|
+ /// If set <see cref="Viewport"/> describes the portion of the content currently visible to the user. This enables
|
|
|
|
+ /// virtual scrolling.
|
|
|
|
+ /// </para>
|
|
|
|
+ /// <para>
|
|
|
|
+ /// If set the behavior of <see cref="DimAutoStyle.Content"/> will be to use the ContentSize to determine the size
|
|
|
|
+ /// of the view.
|
|
|
|
+ /// </para>
|
|
/// </remarks>
|
|
/// </remarks>
|
|
public Size ContentSize
|
|
public Size ContentSize
|
|
{
|
|
{
|
|
@@ -72,7 +104,7 @@ public partial class View
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// Called when <see cref="ContentSize"/> has changed.
|
|
|
|
|
|
+ /// Called when <see cref="ContentSize"/> has changed.
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="e"></param>
|
|
/// <param name="e"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
@@ -83,6 +115,7 @@ public partial class View
|
|
if (e.Cancel != true)
|
|
if (e.Cancel != true)
|
|
{
|
|
{
|
|
OnResizeNeeded ();
|
|
OnResizeNeeded ();
|
|
|
|
+
|
|
//SetNeedsLayout ();
|
|
//SetNeedsLayout ();
|
|
//SetNeedsDisplay ();
|
|
//SetNeedsDisplay ();
|
|
}
|
|
}
|
|
@@ -180,11 +213,12 @@ public partial class View
|
|
/// </para>
|
|
/// </para>
|
|
/// <para>
|
|
/// <para>
|
|
/// Negative values for the location indicate the visible area is offset above (up-and-left) the View's virtual
|
|
/// Negative values for the location indicate the visible area is offset above (up-and-left) the View's virtual
|
|
- /// <see cref="ContentSize"/>. This enables scrolling up and to the left (e.g. in an image viewer that supports zoom
|
|
|
|
|
|
+ /// <see cref="ContentSize"/>. This enables scrolling up and to the left (e.g. in an image viewer that supports
|
|
|
|
+ /// zoom
|
|
/// where the image stays centered).
|
|
/// where the image stays centered).
|
|
/// </para>
|
|
/// </para>
|
|
/// <para>
|
|
/// <para>
|
|
- /// The <see cref="ViewportSettings"/> property controls how scrolling is handled.
|
|
|
|
|
|
+ /// The <see cref="ViewportSettings"/> property controls how scrolling is handled.
|
|
/// </para>
|
|
/// </para>
|
|
/// <para>
|
|
/// <para>
|
|
/// If <see cref="LayoutStyle"/> is <see cref="LayoutStyle.Computed"/> the value of Viewport is indeterminate until
|
|
/// If <see cref="LayoutStyle"/> is <see cref="LayoutStyle.Computed"/> the value of Viewport is indeterminate until
|
|
@@ -211,6 +245,7 @@ public partial class View
|
|
}
|
|
}
|
|
|
|
|
|
Thickness thickness = GetAdornmentsThickness ();
|
|
Thickness thickness = GetAdornmentsThickness ();
|
|
|
|
+
|
|
return new (
|
|
return new (
|
|
_viewportLocation,
|
|
_viewportLocation,
|
|
new (
|
|
new (
|
|
@@ -243,6 +278,7 @@ public partial class View
|
|
}
|
|
}
|
|
|
|
|
|
OnViewportChanged (new (IsInitialized ? Viewport : Rectangle.Empty, oldViewport));
|
|
OnViewportChanged (new (IsInitialized ? Viewport : Rectangle.Empty, oldViewport));
|
|
|
|
+
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -293,7 +329,8 @@ public partial class View
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// Fired when the <see cref="Viewport"/> changes. This event is fired after the <see cref="Viewport"/> has been updated.
|
|
|
|
|
|
+ /// Fired when the <see cref="Viewport"/> changes. This event is fired after the <see cref="Viewport"/> has been
|
|
|
|
+ /// updated.
|
|
/// </summary>
|
|
/// </summary>
|
|
[CanBeNull]
|
|
[CanBeNull]
|
|
public event EventHandler<DrawEventArgs> ViewportChanged;
|
|
public event EventHandler<DrawEventArgs> ViewportChanged;
|
|
@@ -302,10 +339,7 @@ public partial class View
|
|
/// Called when the <see cref="Viewport"/> changes. Invokes the <see cref="ViewportChanged"/> event.
|
|
/// Called when the <see cref="Viewport"/> changes. Invokes the <see cref="ViewportChanged"/> event.
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="e"></param>
|
|
/// <param name="e"></param>
|
|
- protected virtual void OnViewportChanged (DrawEventArgs e)
|
|
|
|
- {
|
|
|
|
- ViewportChanged?.Invoke (this, e);
|
|
|
|
- }
|
|
|
|
|
|
+ protected virtual void OnViewportChanged (DrawEventArgs e) { ViewportChanged?.Invoke (this, e); }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Converts a <see cref="Viewport"/>-relative location and size to a screen-relative location and size.
|
|
/// Converts a <see cref="Viewport"/>-relative location and size to a screen-relative location and size.
|
|
@@ -315,10 +349,7 @@ public partial class View
|
|
/// </remarks>
|
|
/// </remarks>
|
|
/// <param name="viewport">Viewport-relative location and size.</param>
|
|
/// <param name="viewport">Viewport-relative location and size.</param>
|
|
/// <returns>Screen-relative location and size.</returns>
|
|
/// <returns>Screen-relative location and size.</returns>
|
|
- public Rectangle ViewportToScreen (in Rectangle viewport)
|
|
|
|
- {
|
|
|
|
- return viewport with { Location = ViewportToScreen (viewport.Location) };
|
|
|
|
- }
|
|
|
|
|
|
+ public Rectangle ViewportToScreen (in Rectangle viewport) { return viewport with { Location = ViewportToScreen (viewport.Location) }; }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Converts a <see cref="Viewport"/>-relative location to a screen-relative location.
|
|
/// Converts a <see cref="Viewport"/>-relative location to a screen-relative location.
|