using System.Diagnostics; using System.Runtime.InteropServices.JavaScript; using static System.Net.Mime.MediaTypeNames; using static Terminal.Gui.Dialog; using static Terminal.Gui.Dim; namespace Terminal.Gui; /// /// Describes the position of a which can be an absolute value, a percentage, centered, or /// relative to the ending dimension. Integer values are implicitly convertible to an absolute . These /// objects are created using the static methods Percent, AnchorEnd, and Center. The objects can be /// combined with the addition and subtraction operators. /// /// /// Use the objects on the X or Y properties of a view to control the position. /// /// These can be used to set the absolute position, when merely assigning an integer value (via the implicit /// integer to conversion), and they can be combined to produce more useful layouts, like: /// Pos.Center - 3, which would shift the position of the 3 characters to the left after /// centering for example. /// /// /// Reference coordinates of another view by using the methods Left(View), Right(View), Bottom(View), Top(View). /// The X(View) and Y(View) are aliases to Left(View) and Top(View) respectively. /// /// /// /// /// Pos Object Description /// /// /// /// /// /// /// Creates a object that computes the position by executing the provided /// function. The function will be called every time the position is needed. /// /// /// /// /// /// /// /// Creates a object that is a percentage of the width or height of the /// SuperView. /// /// /// /// /// /// /// /// Creates a object that is anchored to the end (right side or bottom) of /// the dimension, useful to flush the layout from the right or bottom. /// /// /// /// /// /// /// Creates a object that can be used to center the . /// /// /// /// /// /// /// Creates a object that is an absolute position based on the specified /// integer value. /// /// /// /// /// /// /// /// Creates a object that tracks the Left (X) position of the specified /// . /// /// /// /// /// /// /// /// Creates a object that tracks the Left (X) position of the specified /// . /// /// /// /// /// /// /// /// Creates a object that tracks the Top (Y) position of the specified /// . /// /// /// /// /// /// /// /// Creates a object that tracks the Top (Y) position of the specified /// . /// /// /// /// /// /// /// /// Creates a object that tracks the Right (X+Width) coordinate of the /// specified . /// /// /// /// /// /// /// /// Creates a object that tracks the Bottom (Y+Height) coordinate of the /// specified /// /// /// /// /// public class Pos { /// /// Creates a object that is anchored to the end (right side or /// bottom) of the SuperView, minus the respective dimension of the View. This is equivalent to using /// , /// with an offset equivalent to the View's respective dimension. /// /// The object anchored to the end (the bottom or the right side) minus the View's dimension. /// /// This sample shows how align a to the bottom-right the SuperView. /// /// anchorButton.X = Pos.AnchorEnd (); /// anchorButton.Y = Pos.AnchorEnd (); /// /// public static Pos AnchorEnd () { return new PosAnchorEnd (); } /// /// Creates a object that is anchored to the end (right side or bottom) of the SuperView, /// useful to flush the layout from the right or bottom. See also , which uses the view /// dimension to ensure the view is fully visible. /// /// The object anchored to the end (the bottom or the right side). /// The view will be shifted left or up by the amount specified. /// /// This sample shows how align a 10 column wide to the bottom-right the SuperView. /// /// anchorButton.X = Pos.AnchorEnd (10); /// anchorButton.Y = 1 /// /// public static Pos AnchorEnd (int offset) { if (offset < 0) { throw new ArgumentException (@"Must be positive", nameof (offset)); } return new PosAnchorEnd (offset); } /// Creates a object that is an absolute position based on the specified integer value. /// The Absolute . /// The value to convert to the . public static Pos At (int n) { return new PosAbsolute (n); } /// Creates a object that can be used to center the . /// The center Pos. /// /// This creates a centered horizontally, is 50% of the way down, is 30% the height, and /// is 80% the width of the it added to. /// /// var textView = new TextView () { /// X = Pos.Center (), /// Y = Pos.Percent (50), /// Width = Dim.Percent (80), /// Height = Dim.Percent (30), /// }; /// /// public static Pos Center () { return new PosCenter (); } /// Determines whether the specified object is equal to the current object. /// The object to compare with the current object. /// /// if the specified object is equal to the current object; otherwise, /// . /// public override bool Equals (object other) { return other is Pos abs && abs == this; } /// /// Creates a object that computes the position by executing the provided function. The function /// will be called every time the position is needed. /// /// The function to be executed. /// The returned from the function. public static Pos Function (Func function) { return new PosFunc (function); } /// Serves as the default hash function. /// A hash code for the current object. public override int GetHashCode () { return Anchor (0).GetHashCode (); } /// Adds a to a , yielding a new . /// The first to add. /// The second to add. /// The that is the sum of the values of left and right. public static Pos operator + (Pos left, Pos right) { if (left is PosAbsolute && right is PosAbsolute) { return new PosAbsolute (left.Anchor (0) + right.Anchor (0)); } var newPos = new PosCombine (true, left, right); if (left is PosView view) { view.Target.SetNeedsLayout (); } return newPos; } /// Creates an Absolute from the specified integer value. /// The Absolute . /// The value to convert to the . public static implicit operator Pos (int n) { return new PosAbsolute (n); } /// /// Subtracts a from a , yielding a new /// . /// /// The to subtract from (the minuend). /// The to subtract (the subtrahend). /// The that is the left minus right. public static Pos operator - (Pos left, Pos right) { if (left is PosAbsolute && right is PosAbsolute) { return new PosAbsolute (left.Anchor (0) - right.Anchor (0)); } var newPos = new PosCombine (false, left, right); if (left is PosView view) { view.Target.SetNeedsLayout (); } return newPos; } /// Creates a percentage object /// The percent object. /// A value between 0 and 100 representing the percentage. /// /// This creates a centered horizontally, is 50% of the way down, is 30% the height, and /// is 80% the width of the it added to. /// /// var textView = new TextField { /// X = Pos.Center (), /// Y = Pos.Percent (50), /// Width = Dim.Percent (80), /// Height = Dim.Percent (30), /// }; /// /// public static Pos Percent (float percent) { if (percent is < 0 or > 100) { throw new ArgumentException ("Percent value must be between 0 and 100."); } return new PosFactor (percent / 100); } /// Creates a object that tracks the Top (Y) position of the specified . /// The that depends on the other view. /// The that will be tracked. public static Pos Top (View view) { return new PosView (view, Side.Top); } /// Creates a object that tracks the Top (Y) position of the specified . /// The that depends on the other view. /// The that will be tracked. public static Pos Y (View view) { return new PosView (view, Side.Top); } /// Creates a object that tracks the Left (X) position of the specified . /// The that depends on the other view. /// The that will be tracked. public static Pos Left (View view) { return new PosView (view, Side.Left); } /// Creates a object that tracks the Left (X) position of the specified . /// The that depends on the other view. /// The that will be tracked. public static Pos X (View view) { return new PosView (view, Side.Left); } /// /// Creates a object that tracks the Bottom (Y+Height) coordinate of the specified /// /// /// The that depends on the other view. /// The that will be tracked. public static Pos Bottom (View view) { return new PosView (view, Side.Bottom); } /// /// Creates a object that tracks the Right (X+Width) coordinate of the specified /// . /// /// The that depends on the other view. /// The that will be tracked. public static Pos Right (View view) { return new PosView (view, Side.Right); } /// /// Gets a position that is anchored to a certain point in the layout. This method is typically used /// internally by the layout system to determine where a View should be positioned. /// /// The width of the area where the View is being positioned (Superview.ContentSize). /// /// An integer representing the calculated position. The way this position is calculated depends on the specific /// subclass of Pos that is used. For example, PosAbsolute returns a fixed position, PosAnchorEnd returns a /// position that is anchored to the end of the layout, and so on. /// internal virtual int Anchor (int width) { return 0; } /// /// Calculates and returns the position of a object. It takes into account the dimension of the /// superview and the dimension of the view itself. /// /// /// The dimension of the superview. This could be the width for x-coordinate calculation or the /// height for y-coordinate calculation. /// /// The dimension of the View. It could be the current width or height. /// The View that holds this Pos object. /// Width or Height /// /// The calculated position of the View. The way this position is calculated depends on the specific subclass of Pos /// that /// is used. /// internal virtual int Calculate (int superviewDimension, Dim dim, View us, Dimension dimension) { return Anchor (superviewDimension); } /// /// Diagnostics API to determine if this Pos object references other views. /// /// internal virtual bool ReferencesOtherViews () { return false; } internal class PosAbsolute (int n) : Pos { private readonly int _n = n; public override bool Equals (object other) { return other is PosAbsolute abs && abs._n == _n; } public override int GetHashCode () { return _n.GetHashCode (); } public override string ToString () { return $"Absolute({_n})"; } internal override int Anchor (int width) { return _n; } } internal class PosAnchorEnd : Pos { private readonly int _offset; public PosAnchorEnd () { UseDimForOffset = true; } public PosAnchorEnd (int offset) { _offset = offset; } public override bool Equals (object other) { return other is PosAnchorEnd anchorEnd && anchorEnd._offset == _offset; } public override int GetHashCode () { return _offset.GetHashCode (); } /// /// If true, the offset is the width of the view, if false, the offset is the offset value. /// internal bool UseDimForOffset { get; set; } public override string ToString () { return UseDimForOffset ? "AnchorEnd()" : $"AnchorEnd({_offset})"; } internal override int Anchor (int width) { if (UseDimForOffset) { return width; } return width - _offset; } internal override int Calculate (int superviewDimension, Dim dim, View us, Dimension dimension) { int newLocation = Anchor (superviewDimension); if (UseDimForOffset) { newLocation -= dim.Anchor (superviewDimension); } return newLocation; } } internal class PosCenter : Pos { public override string ToString () { return "Center"; } internal override int Anchor (int width) { return width / 2; } internal override int Calculate (int superviewDimension, Dim dim, View us, Dimension dimension) { int newDimension = Math.Max (dim.Calculate (0, superviewDimension, us, dimension), 0); return Anchor (superviewDimension - newDimension); } } internal class PosCombine (bool add, Pos left, Pos right) : Pos { internal bool _add = add; internal Pos _left = left, _right = right; public override string ToString () { return $"Combine({_left}{(_add ? '+' : '-')}{_right})"; } internal override int Anchor (int width) { int la = _left.Anchor (width); int ra = _right.Anchor (width); if (_add) { return la + ra; } return la - ra; } internal override int Calculate (int superviewDimension, Dim dim, View us, Dimension dimension) { int newDimension = dim.Calculate (0, superviewDimension, us, dimension); int left = _left.Calculate (superviewDimension, dim, us, dimension); int right = _right.Calculate (superviewDimension, dim, us, dimension); if (_add) { return left + right; } return left - right; } /// /// Diagnostics API to determine if this Pos object references other views. /// /// internal override bool ReferencesOtherViews () { if (_left.ReferencesOtherViews ()) { return true; } if (_right.ReferencesOtherViews ()) { return true; } return false; } } internal class PosFactor (float factor) : Pos { private readonly float _factor = factor; public override bool Equals (object other) { return other is PosFactor f && f._factor == _factor; } public override int GetHashCode () { return _factor.GetHashCode (); } public override string ToString () { return $"Factor({_factor})"; } internal override int Anchor (int width) { return (int)(width * _factor); } } // Helper class to provide dynamic value by the execution of a function that returns an integer. internal class PosFunc (Func n) : Pos { private readonly Func _function = n; public override bool Equals (object other) { return other is PosFunc f && f._function () == _function (); } public override int GetHashCode () { return _function.GetHashCode (); } public override string ToString () { return $"PosFunc({_function ()})"; } internal override int Anchor (int width) { return _function (); } } /// /// Describes which side of the view to use for the position. /// public enum Side { /// /// The left (X) side of the view. /// Left = 0, /// /// The top (Y) side of the view. /// Top = 1, /// /// The right (X + Width) side of the view. /// Right = 2, /// /// The bottom (Y + Height) side of the view. /// Bottom = 3 } internal class PosView (View view, Side side) : Pos { public readonly View Target = view; public override bool Equals (object other) { return other is PosView abs && abs.Target == Target; } public override int GetHashCode () { return Target.GetHashCode (); } public override string ToString () { string sideString = side switch { Side.Left => "left", Side.Top => "top", Side.Right => "right", Side.Bottom => "bottom", _ => "unknown" }; if (Target == null) { throw new NullReferenceException (nameof (Target)); } return $"View(side={sideString},target={Target})"; } internal override int Anchor (int width) { return side switch { Side.Left => Target.Frame.X, Side.Top => Target.Frame.Y, Side.Right => Target.Frame.Right, Side.Bottom => Target.Frame.Bottom, _ => 0 }; } /// /// Diagnostics API to determine if this Pos object references other views. /// /// internal override bool ReferencesOtherViews () { return true; } } } /// /// /// A Dim object describes the dimensions of a . Dim is the type of the /// and properties of . Dim objects enable /// Computed Layout (see ) to automatically manage the dimensions of a view. /// /// /// Integer values are implicitly convertible to an absolute . These objects are created using /// the static methods described below. The objects can be combined with the addition and /// subtraction operators. /// /// /// /// /// /// /// Dim Object Description /// /// /// /// /// /// /// Creates a object that automatically sizes the view to fit /// the view's SubViews. /// /// /// /// /// /// /// /// Creates a object that computes the dimension by executing the provided /// function. The function will be called every time the dimension is needed. /// /// /// /// /// /// /// /// Creates a object that is a percentage of the width or height of the /// SuperView. /// /// /// /// /// /// /// /// Creates a object that fills the dimension from the View's X position /// to the end of the super view's width, leaving the specified number of columns for a margin. /// /// /// /// /// /// /// /// Creates a object that tracks the Width of the specified /// . /// /// /// /// /// /// /// /// Creates a object that tracks the Height of the specified /// . /// /// /// /// /// /// public class Dim { /// /// Specifies how will compute the dimension. /// public enum DimAutoStyle { /// /// The dimension will be computed using both the view's and /// (whichever is larger). /// Auto, /// /// The Subview in with the largest corresponding position plus dimension /// will determine the dimension. /// The corresponding dimension of the view's will be ignored. /// Subviews, /// /// The corresponding dimension of the view's , formatted using the /// settings, /// will be used to determine the dimension. /// The corresponding dimensions of the will be ignored. /// Text } /// /// /// public enum Dimension { /// /// No dimension specified. /// None = 0, /// /// The height dimension. /// Height = 1, /// /// The width dimension. /// Width = 2 } /// /// Creates a object that automatically sizes the view to fit all of the view's SubViews and/or Text. /// /// /// This initializes a with two SubViews. The view will be automatically sized to fit the two /// SubViews. /// /// var button = new Button () { Text = "Click Me!", X = 1, Y = 1, Width = 10, Height = 1 }; /// var textField = new TextField { Text = "Type here", X = 1, Y = 2, Width = 20, Height = 1 }; /// var view = new Window () { Title = "MyWindow", X = 0, Y = 0, Width = Dim.Auto (), Height = Dim.Auto () }; /// view.Add (button, textField); /// /// /// The object. /// /// Specifies how will compute the dimension. The default is . /// /// Specifies the minimum dimension that view will be automatically sized to. /// Specifies the maximum dimension that view will be automatically sized to. NOT CURRENTLY SUPPORTED. public static Dim Auto (DimAutoStyle style = DimAutoStyle.Auto, Dim min = null, Dim max = null) { if (max != null) { throw new NotImplementedException (@"max is not implemented"); } return new DimAuto (style, min, max); } /// Determines whether the specified object is equal to the current object. /// The object to compare with the current object. /// /// if the specified object is equal to the current object; otherwise, /// . /// public override bool Equals (object other) { return other is Dim abs && abs == this; } /// /// Creates a object that fills the dimension, leaving the specified number of columns for a /// margin. /// /// The Fill dimension. /// Margin to use. public static Dim Fill (int margin = 0) { return new DimFill (margin); } /// /// Creates a function object that computes the dimension by executing the provided function. /// The function will be called every time the dimension is needed. /// /// The function to be executed. /// The returned from the function. public static Dim Function (Func function) { return new DimFunc (function); } /// Serves as the default hash function. /// A hash code for the current object. public override int GetHashCode () { return Anchor (0).GetHashCode (); } /// Creates a object that tracks the Height of the specified . /// The height of the other . /// The view that will be tracked. public static Dim Height (View view) { return new DimView (view, Dimension.Height); } /// Adds a to a , yielding a new . /// The first to add. /// The second to add. /// The that is the sum of the values of left and right. public static Dim operator + (Dim left, Dim right) { if (left is DimAbsolute && right is DimAbsolute) { return new DimAbsolute (left.Anchor (0) + right.Anchor (0)); } var newDim = new DimCombine (true, left, right); (left as DimView)?.Target.SetNeedsLayout (); return newDim; } /// Creates an Absolute from the specified integer value. /// The Absolute . /// The value to convert to the pos. public static implicit operator Dim (int n) { return new DimAbsolute (n); } /// /// Subtracts a from a , yielding a new /// . /// /// The to subtract from (the minuend). /// The to subtract (the subtrahend). /// The that is the left minus right. public static Dim operator - (Dim left, Dim right) { if (left is DimAbsolute && right is DimAbsolute) { return new DimAbsolute (left.Anchor (0) - right.Anchor (0)); } var newDim = new DimCombine (false, left, right); (left as DimView)?.Target.SetNeedsLayout (); return newDim; } /// Creates a percentage object that is a percentage of the width or height of the SuperView. /// The percent object. /// A value between 0 and 100 representing the percentage. /// /// If the dimension is computed using the View's position ( or /// ). /// If the dimension is computed using the View's . /// /// /// This initializes a that will be centered horizontally, is 50% of the way down, is 30% the /// height, /// and is 80% the width of the SuperView. /// /// var textView = new TextField { /// X = Pos.Center (), /// Y = Pos.Percent (50), /// Width = Dim.Percent (80), /// Height = Dim.Percent (30), /// }; /// /// public static Dim Percent (float percent, bool usePosition = false) { if (percent is < 0 or > 100) { throw new ArgumentException ("Percent value must be between 0 and 100"); } return new DimFactor (percent / 100, usePosition); } /// Creates an Absolute from the specified integer value. /// The Absolute . /// The value to convert to the . public static Dim Sized (int n) { return new DimAbsolute (n); } /// Creates a object that tracks the Width of the specified . /// The width of the other . /// The view that will be tracked. public static Dim Width (View view) { return new DimView (view, Dimension.Width); } /// /// Gets a dimension that is anchored to a certain point in the layout. /// This method is typically used internally by the layout system to determine the size of a View. /// /// The width of the area where the View is being sized (Superview.ContentSize). /// /// An integer representing the calculated dimension. The way this dimension is calculated depends on the specific /// subclass of Dim that is used. For example, DimAbsolute returns a fixed dimension, DimFactor returns a /// dimension that is a certain percentage of the super view's size, and so on. /// internal virtual int Anchor (int width) { return 0; } /// /// Calculates and returns the dimension of a object. It takes into account the location of the /// , it's SuperView's ContentSize, and whether it should automatically adjust its size based on its content. /// /// /// The starting point from where the size calculation begins. It could be the left edge for width calculation or the /// top edge for height calculation. /// /// The size of the SuperView's content. It could be width or height. /// The View that holds this Pos object. /// Width or Height /// /// The calculated size of the View. The way this size is calculated depends on the specific subclass of Dim that /// is used. /// internal virtual int Calculate (int location, int superviewContentSize, View us, Dimension dimension) { return Math.Max (Anchor (superviewContentSize - location), 0); } /// /// Diagnostics API to determine if this Dim object references other views. /// /// internal virtual bool ReferencesOtherViews () { return false; } internal class DimAbsolute (int n) : Dim { private readonly int _n = n; public override bool Equals (object other) { return other is DimAbsolute abs && abs._n == _n; } public override int GetHashCode () { return _n.GetHashCode (); } public override string ToString () { return $"Absolute({_n})"; } internal override int Anchor (int width) { return _n; } internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension) { // DimAbsolute.Anchor (int width) ignores width and returns n return Math.Max (Anchor (0), 0); } } internal class DimAuto (DimAutoStyle style, Dim min, Dim max) : Dim { internal readonly Dim _max = max; internal readonly Dim _min = min; internal readonly DimAutoStyle _style = style; internal int Size; public override bool Equals (object other) { return other is DimAuto auto && auto._min == _min && auto._max == _max && auto._style == _style; } public override int GetHashCode () { return HashCode.Combine (base.GetHashCode (), _min, _max, _style); } public override string ToString () { return $"Auto({_style},{_min},{_max})"; } internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension) { if (us == null) { return _max?.Anchor (0) ?? 0; } var textSize = 0; var subviewsSize = 0; int autoMin = _min?.Anchor (superviewContentSize) ?? 0; if (superviewContentSize < autoMin) { Debug.WriteLine ($"WARNING: DimAuto specifies a min size ({autoMin}), but the SuperView's bounds are smaller ({superviewContentSize})."); return superviewContentSize; } if (_style is Dim.DimAutoStyle.Text or Dim.DimAutoStyle.Auto) { textSize = int.Max (autoMin, dimension == Dimension.Width ? us.TextFormatter.Size.Width : us.TextFormatter.Size.Height); } if (_style is Dim.DimAutoStyle.Subviews or Dim.DimAutoStyle.Auto) { subviewsSize = us.Subviews.Count == 0 ? 0 : us.Subviews .Where (v => dimension == Dimension.Width ? v.X is not Pos.PosAnchorEnd : v.Y is not Pos.PosAnchorEnd) .Max (v => dimension == Dimension.Width ? v.Frame.X + v.Frame.Width : v.Frame.Y + v.Frame.Height); } int max = int.Max (textSize, subviewsSize); Thickness thickness = us.GetAdornmentsThickness (); if (dimension == Dimension.Width) { max += thickness.Horizontal; } else { max += thickness.Vertical; } max = int.Max (max, autoMin); return int.Min (max, _max?.Anchor (superviewContentSize) ?? superviewContentSize); } /// /// Diagnostics API to determine if this Dim object references other views. /// /// internal override bool ReferencesOtherViews () { return _style is Dim.DimAutoStyle.Subviews or Dim.DimAutoStyle.Auto; } } internal class DimCombine (bool add, Dim left, Dim right) : Dim { internal bool _add = add; internal Dim _left = left, _right = right; public override string ToString () { return $"Combine({_left}{(_add ? '+' : '-')}{_right})"; } internal override int Anchor (int width) { int la = _left.Anchor (width); int ra = _right.Anchor (width); if (_add) { return la + ra; } return la - ra; } internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension) { int leftNewDim = _left.Calculate (location, superviewContentSize, us, dimension); int rightNewDim = _right.Calculate (location, superviewContentSize, us, dimension); int newDimension; if (_add) { newDimension = leftNewDim + rightNewDim; } else { newDimension = Math.Max (0, leftNewDim - rightNewDim); } return newDimension; } /// /// Diagnostics API to determine if this Dim object references other views. /// /// internal override bool ReferencesOtherViews () { if (_left.ReferencesOtherViews ()) { return true; } if (_right.ReferencesOtherViews ()) { return true; } return false; } } internal class DimFactor (float factor, bool remaining = false) : Dim { private readonly float _factor = factor; private readonly bool _remaining = remaining; public override bool Equals (object other) { return other is DimFactor f && f._factor == _factor && f._remaining == _remaining; } public override int GetHashCode () { return _factor.GetHashCode (); } public bool IsFromRemaining () { return _remaining; } public override string ToString () { return $"Factor({_factor},{_remaining})"; } internal override int Anchor (int width) { return (int)(width * _factor); } internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension) { return _remaining ? Math.Max (Anchor (superviewContentSize - location), 0) : Anchor (superviewContentSize); } } internal class DimFill (int margin) : Dim { private readonly int _margin = margin; public override bool Equals (object other) { return other is DimFill fill && fill._margin == _margin; } public override int GetHashCode () { return _margin.GetHashCode (); } public override string ToString () { return $"Fill({_margin})"; } internal override int Anchor (int width) { return width - _margin; } } // Helper class to provide dynamic value by the execution of a function that returns an integer. internal class DimFunc (Func n) : Dim { private readonly Func _function = n; public override bool Equals (object other) { return other is DimFunc f && f._function () == _function (); } public override int GetHashCode () { return _function.GetHashCode (); } public override string ToString () { return $"DimFunc({_function ()})"; } internal override int Anchor (int width) { return _function (); } } internal class DimView : Dim { private readonly Dimension _side; internal DimView (View view, Dimension side) { Target = view; _side = side; } public View Target { get; init; } public override bool Equals (object other) { return other is DimView abs && abs.Target == Target; } public override int GetHashCode () { return Target.GetHashCode (); } public override string ToString () { if (Target == null) { throw new NullReferenceException (); } string sideString = _side switch { Dimension.Height => "Height", Dimension.Width => "Width", _ => "unknown" }; return $"View({sideString},{Target})"; } internal override int Anchor (int width) { return _side switch { Dimension.Height => Target.Frame.Height, Dimension.Width => Target.Frame.Width, _ => 0 }; } internal override bool ReferencesOtherViews () { return true; } } }