using System.Numerics; using Robust.Shared.Maths; namespace Robust.Client.UserInterface; /// /// Defines an axis that certain controls can be laid out along. /// /// public enum Axis : byte { /// /// Items are laid out left to right. /// Horizontal, /// /// Items are laid out right to left. /// HorizontalReverse, /// /// Items are laid out top to bottom. /// Vertical, /// /// Items are laid out bottom to top. /// VerticalReverse, } /// /// Interface that implements the rules of an . /// /// /// /// To make it easier to write code that supports all 4 layout axis, layout code is advised to use generics over this /// type and its implementors. /// /// /// An axis has a "main" and a "cross" axis. For example, /// has the main axis go left to right, and the cross axis go top to bottom. /// /// /// The functions in this interface primarily allow converting between "UI space" (the normal UI coordinate system) and /// "axis space" (same as UI space for ). This allows you to write all code as if you're /// doing only horizontal layout, but automatically have it work on all axis. /// /// /// /// /// /// [NotContentImplementable] public interface IAxisImplementation { // // To/from axis space conversions // /// /// Convert a size value (e.g. from ) from UI space to axis space. /// static abstract Vector2 SizeToAxis(Vector2 size); /// /// Convert a size value (e.g. for ) from axis space to UI space. /// static abstract Vector2 SizeFromAxis(Vector2 size); /// /// Convert a box (e.g. for ) from axis space to UI space. /// /// The box to convert, in axis space. /// The amount of space, in UI space, that the layout is happening relative to. static abstract UIBox2 BoxFromAxis(UIBox2 box, Vector2 spaceSize); // // Control // /// /// Gets the "expand flag" ( or ) for a /// control that is appropriate for the main axis. /// static abstract bool GetMainExpandFlag(Control control); } /// /// Axis implementation for . /// public struct HorizontalAxis : IAxisImplementation { public static Vector2 SizeToAxis(Vector2 size) { return size; } public static Vector2 SizeFromAxis(Vector2 size) { return size; } public static UIBox2 BoxFromAxis(UIBox2 box, Vector2 spaceSize) { return box; } public static bool GetMainExpandFlag(Control control) { return control.HorizontalExpand; } } /// /// Axis implementation for . /// public struct HorizontalReverseAxis : IAxisImplementation { public static Vector2 SizeToAxis(Vector2 size) { return size; } public static Vector2 SizeFromAxis(Vector2 size) { return size; } public static UIBox2 BoxFromAxis(UIBox2 box, Vector2 spaceSize) { return new UIBox2(spaceSize.X - box.Right, box.Top, spaceSize.X - box.Left, box.Bottom); } public static bool GetMainExpandFlag(Control control) { return control.HorizontalExpand; } } /// /// Axis implementation for . /// public struct VerticalAxis : IAxisImplementation { public static Vector2 SizeToAxis(Vector2 size) { return new Vector2(size.Y, size.X); } public static Vector2 SizeFromAxis(Vector2 size) { return new Vector2(size.Y, size.X); } public static UIBox2 BoxFromAxis(UIBox2 box, Vector2 spaceSize) { return new UIBox2(box.Top, box.Left, box.Bottom, box.Right); } public static bool GetMainExpandFlag(Control control) { return control.VerticalExpand; } } /// /// Axis implementation for . /// public struct VerticalReverseAxis : IAxisImplementation { public static Vector2 SizeToAxis(Vector2 size) { return new Vector2(size.Y, size.X); } public static Vector2 SizeFromAxis(Vector2 size) { return new Vector2(size.Y, size.X); } public static UIBox2 BoxFromAxis(UIBox2 box, Vector2 spaceSize) { return new UIBox2(box.Top, spaceSize.Y - box.Right, box.Bottom, spaceSize.Y - box.Left); } public static bool GetMainExpandFlag(Control control) { return control.VerticalExpand; } }