#nullable enable
namespace Terminal.Gui;
///
/// Represents a dimension that tracks the Height or Width of the specified View.
///
///
/// This is a low-level API that is typically used internally by the layout system. Use the various static
/// methods on the class to create objects instead.
///
public record DimView : Dim
{
///
/// Initializes a new instance of the class.
///
/// The view the dimension is anchored to.
/// Indicates which dimension is tracked.
public DimView (View? view, Dimension dimension)
{
Target = view;
Dimension = dimension;
}
///
/// Gets the indicated dimension of the View.
///
public Dimension Dimension { get; }
///
/// Gets the View the dimension is anchored to.
///
public View? Target { get; init; }
///
public override string ToString ()
{
if (Target == null)
{
throw new NullReferenceException ();
}
return $"View({Dimension},{Target})";
}
internal override int GetAnchor (int size)
{
return Dimension switch
{
Dimension.Height => Target!.Frame.Height,
Dimension.Width => Target!.Frame.Width,
_ => 0
};
}
internal override bool ReferencesOtherViews () { return true; }
}