Skip to content

Commit

Permalink
partial impl of fixing gui-cs#2465
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Mar 30, 2023
1 parent 33c9a5f commit b902593
Show file tree
Hide file tree
Showing 2 changed files with 425 additions and 40 deletions.
138 changes: 98 additions & 40 deletions Terminal.Gui/Core/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,70 +446,102 @@ public override bool CanFocus {
public virtual bool WantContinuousButtonPressed { get; set; }

/// <summary>
/// Gets or sets the frame for the view. The frame is relative to the view's container (<see cref="SuperView"/>).
/// Gets or sets the location and size of the view, relative to its <see cref="SuperView"/>.
/// </summary>
/// <value>The frame.</value>
/// <value>The rectangle describing the location and size of the view, in coordinates relative to the <see cref="SuperView"/>.</value>
/// <remarks>
/// <para>
/// Change the Frame when using the <see cref="Terminal.Gui.LayoutStyle.Absolute"/> layout style to move or resize views.
/// Change the Frame when using the <see cref="Terminal.Gui.LayoutStyle.Absolute"/> layout style to move or resize views.
/// </para>
/// <para>
/// Altering the Frame of a view will trigger the redrawing of the
/// view as well as the redrawing of the affected regions of the <see cref="SuperView"/>.
/// If <see cref="LayoutStyle"/> is <see cref="LayoutStyle.Computed"/>, altering the Frame will
/// change the layout style to <see cref="LayoutStyle.Absolute"/> and <see cref="X"/>, <see cref="Y"/>, <see cref="Width"/> and <see cref="Height"/>
/// will be set to the values of the Frame (using <see cref="Pos.PosAbsolute"/> and <see cref="Dim.DimAbsolute"/>).
/// </para>
/// <para>
/// Altering the Frame will eventually (when the view is next drawn) cause the <see cref="LayoutSubview(View, Rect)"/> and <see cref="Redraw(Rect)"/> methods to be called.
/// </para>
/// </remarks>
public virtual Rect Frame {
get => frame;
set {
frame = new Rect (value.X, value.Y, Math.Max (value.Width, 0), Math.Max (value.Height, 0));
X = frame.X;
Y = frame.Y;
Width = frame.Width;
Height = frame.Height;
TextFormatter.Size = GetSizeNeededForTextAndHotKey ();
SetNeedsLayout ();
SetNeedsDisplay ();
}
}

///// <summary>
///// Gets an enumerator that enumerates the subviews in this view.
///// </summary>
///// <returns>The enumerator.</returns>
//public IEnumerator GetEnumerator ()
//{
// foreach (var v in InternalSubviews)
// yield return v;
//}

LayoutStyle layoutStyle;

/// <summary>
/// Controls how the View's <see cref="Frame"/> is computed during the LayoutSubviews method, if the style is set to
/// <see cref="Terminal.Gui.LayoutStyle.Absolute"/>,
/// LayoutSubviews does not change the <see cref="Frame"/>. If the style is <see cref="Terminal.Gui.LayoutStyle.Computed"/>
/// the <see cref="Frame"/> is updated using
/// the <see cref="X"/>, <see cref="Y"/>, <see cref="Width"/>, and <see cref="Height"/> properties.
/// Gets or sets what <see cref="Terminal.Gui.LayoutStyle"/> the view is using.
/// </summary>
/// <remarks>
/// <para>
/// Setting this property to <see cref="Terminal.Gui.LayoutStyle.Absolute"/> will cause <see cref="Frame"/> to determine the size and position of the view. <see cref="X"/> and <see cref="Y"/> will be
/// set to <see cref="Dim.DimAbsolute"/> using <see cref="Frame"/>.
/// </para>
/// <para>
/// Setting this property to <see cref="Terminal.Gui.LayoutStyle.Computed"/> will cause the view to use the <see cref="LayoutSubviews"/> method to
/// size and position of the view. If either of the <see cref="X"/> and <see cref="Y"/> properties are `null` they will be set to <see cref="Pos.PosAbsolute"/> using
/// the current value of <see cref="Frame"/>.
/// If either of the <see cref="Width"/> and <see cref="Height"/> properties are `null` they will be set to <see cref="Dim.DimAbsolute"/> using <see cref="Frame"/>.
/// </para>
/// </remarks>
/// <value>The layout style.</value>
public LayoutStyle LayoutStyle {
get => layoutStyle;
get {
if ((X == null || X is Pos.PosAbsolute) && (Y == null || Y is Pos.PosAbsolute) &&
(Width == null || Width is Dim.DimAbsolute) && (Height == null || Height is Dim.DimAbsolute)) {
return LayoutStyle.Absolute;
}
return LayoutStyle.Computed;
}
set {
layoutStyle = value;
switch (value) {
case LayoutStyle.Absolute:
X = Frame.X;
Y = Frame.Y;
Width = Frame.Width;
Height = Frame.Height;
break;

case LayoutStyle.Computed:
if (X == null) X = Frame.X;
if (Y == null) Y = Frame.Y;
if (Width == null) Width = Frame.Width;
if (Height == null) Height = Frame.Height;
break;
}

SetNeedsLayout ();
}
}

/// <summary>
/// The bounds represent the View-relative rectangle used for this view; the area inside of the view.
/// The bounds represent the View-relative rectangle used for this view; the area inside of the view where subviews and content are presented.
/// </summary>
/// <value>The bounds.</value>
/// <value>The rectangle describing the location and size of the area where the views' subviews and content are drawn.
/// <remarks>
/// <para>
/// Updates to the Bounds update the <see cref="Frame"/>,
/// and has the same side effects as updating the <see cref="Frame"/>.
/// If <see cref="LayoutStyle"/> is <see cref="LayoutStyle.Computed"/> the value of Bounds is indterminate until the
/// view has been laid out (see <see cref="LayoutSubview(View, Rect)"/> has been called.
/// </para>
/// <para>
/// Updates to the Bounds updates <see cref="Frame"/>, and has the same side effects as updating the <see cref="Frame"/>.
/// </para>
/// <para>
/// Altering the Bounds will eventually (when the view is next drawn) cause the <see cref="LayoutSubview(View, Rect)"/> and <see cref="Redraw(Rect)"/> methods to be called.
/// </para>
/// <para>
/// Because <see cref="Bounds"/> coordinates are relative to the upper-left corner of the <see cref="View"/>,
/// the coordinates of the upper-left corner of the rectangle returned by this property are (0,0).
/// Use this property to obtain the size and coordinates of the client area of the
/// control for tasks such as drawing on the surface of the control.
/// Use this property to obtain the size of the area of the view for tasks such as drawing the view's contents.
/// </para>
/// </remarks>
public Rect Bounds {
Expand All @@ -520,11 +552,17 @@ public Rect Bounds {
Pos x, y;

/// <summary>
/// Gets or sets the X position for the view (the column). Only used if the <see cref="LayoutStyle"/> is <see cref="Terminal.Gui.LayoutStyle.Computed"/>.
/// Gets or sets the X position for the view (the column).
/// </summary>
/// <value>The X Position.</value>
/// <remarks>
/// If <see cref="LayoutStyle"/> is <see cref="Terminal.Gui.LayoutStyle.Absolute"/> changing this property has no effect and its value is indeterminate.
/// <para>
/// Changing this property will eventually (when the view is next drawn) cause the <see cref="LayoutSubview(View, Rect)"/> and <see cref="Redraw(Rect)"/> methods to be called.
/// </para>
/// <para>
/// If <see cref="LayoutStyle"/> is <see cref="Terminal.Gui.LayoutStyle.Absolute"/> changing this property will cause the <see cref="Frame"/> to be updated. If
/// the new value is not of type <see cref="Pos.PosAbsolute"/> the <see cref="LayoutStyle"/> will change to <see cref="Terminal.Gui.LayoutStyle.Computed"/>.
/// </para>
/// </remarks>
public Pos X {
get => x;
Expand All @@ -540,11 +578,17 @@ public Pos X {
}

/// <summary>
/// Gets or sets the Y position for the view (the row). Only used if the <see cref="LayoutStyle"/> is <see cref="Terminal.Gui.LayoutStyle.Computed"/>.
/// Gets or sets the Y position for the view (the row).
/// </summary>
/// <value>The y position (line).</value>
/// <value>The Y Position.</value>
/// <remarks>
/// If <see cref="LayoutStyle"/> is <see cref="Terminal.Gui.LayoutStyle.Absolute"/> changing this property has no effect and its value is indeterminate.
/// <para>
/// Changing this property will eventually (when the view is next drawn) cause the <see cref="LayoutSubview(View, Rect)"/> and <see cref="Redraw(Rect)"/> methods to be called.
/// </para>
/// <para>
/// If <see cref="LayoutStyle"/> is <see cref="Terminal.Gui.LayoutStyle.Absolute"/> changing this property will cause the <see cref="Frame"/> to be updated. If
/// the new value is not of type <see cref="Pos.PosAbsolute"/> the <see cref="LayoutStyle"/> will change to <see cref="Terminal.Gui.LayoutStyle.Computed"/>.
/// </para>
/// </remarks>
public Pos Y {
get => y;
Expand All @@ -561,11 +605,17 @@ public Pos Y {
Dim width, height;

/// <summary>
/// Gets or sets the width of the view. Only used the <see cref="LayoutStyle"/> is <see cref="Terminal.Gui.LayoutStyle.Computed"/>.
/// Gets or sets the width of the view.
/// </summary>
/// <value>The width.</value>
/// <value>The width of the view (the number of columns).</value>
/// <remarks>
/// If <see cref="LayoutStyle"/> is <see cref="Terminal.Gui.LayoutStyle.Absolute"/> changing this property has no effect and its value is indeterminate.
/// <para>
/// Changing this property will eventually (when the view is next drawn) cause the <see cref="LayoutSubview(View, Rect)"/> and <see cref="Redraw(Rect)"/> methods to be called.
/// </para>
/// <para>
/// If <see cref="LayoutStyle"/> is <see cref="Terminal.Gui.LayoutStyle.Absolute"/> changing this property will cause the <see cref="Frame"/> to be updated. If
/// the new value is not of type <see cref="Pos.PosAbsolute"/> the <see cref="LayoutStyle"/> will change to <see cref="Terminal.Gui.LayoutStyle.Computed"/>.
/// </para>
/// </remarks>
public Dim Width {
get => width;
Expand All @@ -588,10 +638,18 @@ public Dim Width {
}

/// <summary>
/// Gets or sets the height of the view. Only used the <see cref="LayoutStyle"/> is <see cref="Terminal.Gui.LayoutStyle.Computed"/>.
/// Gets or sets the height of the view.
/// </summary>
/// <value>The height.</value>
/// If <see cref="LayoutStyle"/> is <see cref="Terminal.Gui.LayoutStyle.Absolute"/> changing this property has no effect and its value is indeterminate.
/// <value>The width of the view (the number of rows).</value>
/// <remarks>
/// <para>
/// Changing this property will eventually (when the view is next drawn) cause the <see cref="LayoutSubview(View, Rect)"/> and <see cref="Redraw(Rect)"/> methods to be called.
/// </para>
/// <para>
/// If <see cref="LayoutStyle"/> is <see cref="Terminal.Gui.LayoutStyle.Absolute"/> changing this property will cause the <see cref="Frame"/> to be updated. If
/// the new value is not of type <see cref="Pos.PosAbsolute"/> the <see cref="LayoutStyle"/> will change to <see cref="Terminal.Gui.LayoutStyle.Computed"/>.
/// </para>
/// </remarks>
public Dim Height {
get => height;
set {
Expand Down Expand Up @@ -827,7 +885,7 @@ void SetInitialProperties (ustring text, Rect rect, LayoutStyle layoutStyle = La

Text = text;

OnResizeNeeded ();
//OnResizeNeeded ();
}

/// <summary>
Expand Down
Loading

0 comments on commit b902593

Please sign in to comment.