From 2e5eaedcdcd38fa67d27e00a62c4a70db30d2172 Mon Sep 17 00:00:00 2001 From: Yoshi Askharoun Date: Sun, 18 Feb 2024 22:23:59 -0600 Subject: [PATCH] Add public PredefinedLayouts --- UIX/Microsoft/Iris/Layout/ILayout.cs | 3 +- .../Iris/Layout/PredefinedLayouts.cs | 63 +++++++++++++++++++ UIX/Microsoft/Iris/Layouts/AnchorLayout.cs | 9 +++ UIX/Microsoft/Iris/Layouts/DefaultLayout.cs | 8 +++ UIX/Microsoft/Iris/Layouts/DockLayout.cs | 8 +++ UIX/Microsoft/Iris/Layouts/FlowLayout.cs | 15 +++++ UIX/Microsoft/Iris/Layouts/GridLayout.cs | 14 +++++ UIX/Microsoft/Iris/Layouts/PopupLayout.cs | 8 +++ UIX/Microsoft/Iris/Layouts/RotateLayout.cs | 8 +++ UIX/Microsoft/Iris/Layouts/ScaleLayout.cs | 11 ++++ UIX/Microsoft/Iris/Layouts/ScrollingLayout.cs | 9 +++ UIX/Microsoft/Iris/Layouts/StackLayout.cs | 8 +++ UIX/Microsoft/Iris/Markup/UIX/LayoutSchema.cs | 34 +--------- UIX/Microsoft/Iris/ViewItems/ImageLayout.cs | 11 ++++ UIX/Microsoft/Iris/ViewItems/Text.cs | 5 ++ .../Iris/ViewItems/TextRunRenderer.cs | 9 +++ 16 files changed, 191 insertions(+), 32 deletions(-) create mode 100644 UIX/Microsoft/Iris/Layout/PredefinedLayouts.cs diff --git a/UIX/Microsoft/Iris/Layout/ILayout.cs b/UIX/Microsoft/Iris/Layout/ILayout.cs index edc46e4..59d20c1 100644 --- a/UIX/Microsoft/Iris/Layout/ILayout.cs +++ b/UIX/Microsoft/Iris/Layout/ILayout.cs @@ -5,10 +5,11 @@ // Assembly location: C:\Program Files\Zune\UIX.dll using Microsoft.Iris.Render; +using System; namespace Microsoft.Iris.Layout { - public interface ILayout + public interface ILayout : IEquatable { Size Measure(ILayoutNode layoutNode, Size constraint); diff --git a/UIX/Microsoft/Iris/Layout/PredefinedLayouts.cs b/UIX/Microsoft/Iris/Layout/PredefinedLayouts.cs new file mode 100644 index 0000000..e57aaef --- /dev/null +++ b/UIX/Microsoft/Iris/Layout/PredefinedLayouts.cs @@ -0,0 +1,63 @@ +using Microsoft.Iris.Layouts; +using Microsoft.Iris.Render; +using System.Collections.Generic; + +namespace Microsoft.Iris.Layout; + +public static class PredefinedLayouts +{ + public static bool TryGetFromName(string name, out ILayout layout) + { + return s_NameToLayoutMap.TryGetValue(name.ToLowerInvariant(), out layout); + } + + public static bool TryConvertToString(ILayout layout, out string name) + { + foreach (var kvp in s_NameToLayoutMap) + { + if (kvp.Value.Equals(layout)) + { + name = kvp.Key; + return true; + } + } + + name = null; + return false; + } + + public static ILayout Anchor { get; } = new AnchorLayout(); + public static ILayout Default { get; } = DefaultLayout.Instance; + public static ILayout Dock { get; } = new DockLayout(); + public static ILayout Grid { get; } = new GridLayout(); + public static ILayout Scale { get; } = new ScaleLayout(); + public static ILayout Popup { get; } = new PopupLayout(); + public static ILayout Stack { get; } = new StackLayout(); + public static ILayout Form { get; } = new AnchorLayout + { + SizeToHorizontalChildren = false, + SizeToVerticalChildren = false + }; + public static ILayout HorizontalFlow { get; } = new FlowLayout + { + Orientation = Orientation.Horizontal + }; + public static ILayout VerticalFlow { get; } = new FlowLayout + { + Orientation = Orientation.Vertical + }; + + private static readonly Dictionary s_NameToLayoutMap = new(10) + { + ["anchor"] = Anchor, + ["default"] = Default, + ["dock"] = Dock, + ["grid"] = Grid, + ["scale"] = Scale, + ["popup"] = Popup, + ["stack"] = Stack, + ["form"] = Form, + ["horizontalflow"] = HorizontalFlow, + ["verticalflow"] = VerticalFlow, + }; +} diff --git a/UIX/Microsoft/Iris/Layouts/AnchorLayout.cs b/UIX/Microsoft/Iris/Layouts/AnchorLayout.cs index 595ded8..c338413 100644 --- a/UIX/Microsoft/Iris/Layouts/AnchorLayout.cs +++ b/UIX/Microsoft/Iris/Layouts/AnchorLayout.cs @@ -350,6 +350,15 @@ namespace Microsoft.Iris.Layouts return null; } + public bool Equals(ILayout other) + { + if (other is not AnchorLayout o) return false; + + return DefaultChildAlignment == o.DefaultChildAlignment + && SizeToHorizontalChildren == o.SizeToHorizontalChildren + && SizeToVerticalChildren == o.SizeToVerticalChildren; + } + internal static DataCookie InputData => s_dataProperty; internal enum LayoutPhase diff --git a/UIX/Microsoft/Iris/Layouts/DefaultLayout.cs b/UIX/Microsoft/Iris/Layouts/DefaultLayout.cs index 09082d2..5383f65 100644 --- a/UIX/Microsoft/Iris/Layouts/DefaultLayout.cs +++ b/UIX/Microsoft/Iris/Layouts/DefaultLayout.cs @@ -6,6 +6,7 @@ using Microsoft.Iris.Layout; using Microsoft.Iris.Render; +using System; namespace Microsoft.Iris.Layouts { @@ -42,5 +43,12 @@ namespace Microsoft.Iris.Layouts foreach (ILayoutNode layoutChild in layoutNode.LayoutChildren) layoutChild.Arrange(slot); } + + public bool Equals(ILayout other) + { + if (other is not DefaultLayout o) return false; + + return DefaultChildAlignment == o.DefaultChildAlignment; + } } } diff --git a/UIX/Microsoft/Iris/Layouts/DockLayout.cs b/UIX/Microsoft/Iris/Layouts/DockLayout.cs index 3a579e9..4c0cfb1 100644 --- a/UIX/Microsoft/Iris/Layouts/DockLayout.cs +++ b/UIX/Microsoft/Iris/Layouts/DockLayout.cs @@ -120,5 +120,13 @@ namespace Microsoft.Iris.Layouts dockLayoutInput = _defaultLayoutInput ?? s_defaultLayoutInput; return dockLayoutInput; } + + public bool Equals(ILayout other) + { + if (other is not DockLayout o) return false; + + return DefaultChildAlignment == o.DefaultChildAlignment + && DefaultLayoutInput.ToString() == other.DefaultChildAlignment.ToString(); + } } } diff --git a/UIX/Microsoft/Iris/Layouts/FlowLayout.cs b/UIX/Microsoft/Iris/Layouts/FlowLayout.cs index 173ae88..0b6c7ef 100644 --- a/UIX/Microsoft/Iris/Layouts/FlowLayout.cs +++ b/UIX/Microsoft/Iris/Layouts/FlowLayout.cs @@ -696,6 +696,21 @@ namespace Microsoft.Iris.Layouts return majorMinor; } + public bool Equals(ILayout other) + { + if (other is not FlowLayout o) return false; + + return DefaultChildAlignment == o.DefaultChildAlignment + && Orientation == o.Orientation + && Spacing == o.Spacing + && AllowWrap == o.AllowWrap + && StripAlignment == o.StripAlignment + && Repeat == o.Repeat + && RepeatGap == o.RepeatGap + && MissingItemPolicy == o.MissingItemPolicy + && MinimumSampleSize == o.MinimumSampleSize; + } + internal class Record { public int Index; diff --git a/UIX/Microsoft/Iris/Layouts/GridLayout.cs b/UIX/Microsoft/Iris/Layouts/GridLayout.cs index a5b7989..61f281e 100644 --- a/UIX/Microsoft/Iris/Layouts/GridLayout.cs +++ b/UIX/Microsoft/Iris/Layouts/GridLayout.cs @@ -538,6 +538,20 @@ namespace Microsoft.Iris.Layouts return roundUp ? (int)Math.Ceiling(num) : (int)Math.Floor(num); } + public bool Equals(ILayout other) + { + if (other is not GridLayout o) return false; + + return DefaultChildAlignment == o.DefaultChildAlignment + && Orientation == o.Orientation + && ReferenceSize == o.ReferenceSize + && Rows == o.Rows + && Columns == o.Columns + && Spacing == o.Spacing + && Repeat == o.Repeat + && RepeatGap == o.RepeatGap; + } + private enum ViewIntersectionType { BeginOffscreen, diff --git a/UIX/Microsoft/Iris/Layouts/PopupLayout.cs b/UIX/Microsoft/Iris/Layouts/PopupLayout.cs index f74349b..51a230e 100644 --- a/UIX/Microsoft/Iris/Layouts/PopupLayout.cs +++ b/UIX/Microsoft/Iris/Layouts/PopupLayout.cs @@ -12,6 +12,7 @@ using Microsoft.Iris.Render; using Microsoft.Iris.RenderAPI.Drawing; using Microsoft.Iris.Session; using Microsoft.Iris.UI; +using Microsoft.Iris.ViewItems; using System; using System.Collections; @@ -271,6 +272,13 @@ namespace Microsoft.Iris.Layouts } } + public bool Equals(ILayout other) + { + if (other is not PopupLayout o) return false; + + return DefaultChildAlignment == o.DefaultChildAlignment; + } + private class PlacementTargetInfo { public ViewItem child; diff --git a/UIX/Microsoft/Iris/Layouts/RotateLayout.cs b/UIX/Microsoft/Iris/Layouts/RotateLayout.cs index 38702ff..7c068c1 100644 --- a/UIX/Microsoft/Iris/Layouts/RotateLayout.cs +++ b/UIX/Microsoft/Iris/Layouts/RotateLayout.cs @@ -71,5 +71,13 @@ namespace Microsoft.Iris.Layouts private static Rectangle RotateRect180(Rectangle rect, Point offset) => new Rectangle(-rect.Right + offset.X, -rect.Bottom + offset.Y, rect.Width, rect.Height); private static Rectangle RotateRect270(Rectangle rect, Point offset) => new Rectangle(-rect.Bottom + offset.X, rect.X + offset.Y, rect.Height, rect.Width); + + public bool Equals(ILayout other) + { + if (other is not RotateLayout o) return false; + + return DefaultChildAlignment == o.DefaultChildAlignment + && AngleDegrees == o.AngleDegrees; + } } } diff --git a/UIX/Microsoft/Iris/Layouts/ScaleLayout.cs b/UIX/Microsoft/Iris/Layouts/ScaleLayout.cs index b070cdb..16acac8 100644 --- a/UIX/Microsoft/Iris/Layouts/ScaleLayout.cs +++ b/UIX/Microsoft/Iris/Layouts/ScaleLayout.cs @@ -8,6 +8,7 @@ using Microsoft.Iris.Drawing; using Microsoft.Iris.Layout; using Microsoft.Iris.Render; using Microsoft.Iris.RenderAPI.Drawing; +using Microsoft.Iris.ViewItems; using System; namespace Microsoft.Iris.Layouts @@ -92,5 +93,15 @@ namespace Microsoft.Iris.Layouts view.Height = (int)Math.Round(view.Height / (double)scale.Height); return view; } + + public bool Equals(ILayout other) + { + if (other is not ScaleLayout o) return false; + + return DefaultChildAlignment == o.DefaultChildAlignment + && MinimumScale == o.MinimumScale + && MaximumScale == o.MaximumScale + && MaintainAspectRatio == o.MaintainAspectRatio; + } } } diff --git a/UIX/Microsoft/Iris/Layouts/ScrollingLayout.cs b/UIX/Microsoft/Iris/Layouts/ScrollingLayout.cs index 12dd386..c3cb7bc 100644 --- a/UIX/Microsoft/Iris/Layouts/ScrollingLayout.cs +++ b/UIX/Microsoft/Iris/Layouts/ScrollingLayout.cs @@ -329,5 +329,14 @@ namespace Microsoft.Iris.Layouts public static bool ScrollFocusIntoView => s_allowScrollFocusIntoView; public static void DisallowScrollFocusIntoView() => s_allowScrollFocusIntoView = false; + + public bool Equals(ILayout other) + { + if (other is not ScrollingLayout o) return false; + + return DefaultChildAlignment == o.DefaultChildAlignment + && Orientation == o.Orientation + && Prefetch == o.Prefetch; + } } } diff --git a/UIX/Microsoft/Iris/Layouts/StackLayout.cs b/UIX/Microsoft/Iris/Layouts/StackLayout.cs index d6c4539..86c78db 100644 --- a/UIX/Microsoft/Iris/Layouts/StackLayout.cs +++ b/UIX/Microsoft/Iris/Layouts/StackLayout.cs @@ -7,6 +7,7 @@ using Microsoft.Iris.Layout; using Microsoft.Iris.Library; using Microsoft.Iris.Render; +using Microsoft.Iris.ViewItems; using System; namespace Microsoft.Iris.Layouts @@ -96,5 +97,12 @@ namespace Microsoft.Iris.Layouts stackLayoutInput = s_defaultLayoutInput; return stackLayoutInput; } + + public bool Equals(ILayout other) + { + if (other is not StackLayout o) return false; + + return DefaultChildAlignment == o.DefaultChildAlignment; + } } } diff --git a/UIX/Microsoft/Iris/Markup/UIX/LayoutSchema.cs b/UIX/Microsoft/Iris/Markup/UIX/LayoutSchema.cs index cc559e6..351e1ff 100644 --- a/UIX/Microsoft/Iris/Markup/UIX/LayoutSchema.cs +++ b/UIX/Microsoft/Iris/Markup/UIX/LayoutSchema.cs @@ -5,26 +5,22 @@ // Assembly location: C:\Program Files\Zune\UIX.dll using Microsoft.Iris.Layout; -using Microsoft.Iris.Layouts; using Microsoft.Iris.Library; -using Microsoft.Iris.Render; -using System.Collections.Generic; namespace Microsoft.Iris.Markup.UIX { internal static class LayoutSchema { - private static Dictionary s_NameToLayoutMap = new Dictionary(10); public static UIXTypeSchema Type; private static Result ConvertFromString(object valueObj, out object instanceObj) { string str = (string)valueObj; instanceObj = null; - object obj; - if (!s_NameToLayoutMap.TryGetValue(str.ToLowerInvariant(), out obj)) + + if (!PredefinedLayouts.TryGetFromName(str, out var layout)) return Result.Fail("Unable to convert \"{0}\" to type '{1}'", str, "Layout"); - ILayout layout = (ILayout)obj; + instanceObj = layout; return Result.Success; } @@ -55,30 +51,6 @@ namespace Microsoft.Iris.Markup.UIX return ConvertFromString(parameter1, out instanceObj1).Failed ? parameter2 : instanceObj1; } - static LayoutSchema() - { - s_NameToLayoutMap.Add("anchor", new AnchorLayout()); - s_NameToLayoutMap.Add("default", DefaultLayout.Instance); - s_NameToLayoutMap.Add("dock", new DockLayout()); - s_NameToLayoutMap.Add("grid", new GridLayout()); - s_NameToLayoutMap.Add("scale", new ScaleLayout()); - s_NameToLayoutMap.Add("popup", new PopupLayout()); - s_NameToLayoutMap.Add("stack", new StackLayout()); - s_NameToLayoutMap.Add("form", new AnchorLayout() - { - SizeToHorizontalChildren = false, - SizeToVerticalChildren = false - }); - s_NameToLayoutMap.Add("horizontalflow", new FlowLayout() - { - Orientation = Orientation.Horizontal - }); - s_NameToLayoutMap.Add("verticalflow", new FlowLayout() - { - Orientation = Orientation.Vertical - }); - } - public static void Pass1Initialize() => Type = new UIXTypeSchema(132, "Layout", null, 153, typeof(ILayout), UIXTypeFlags.Immutable); public static void Pass2Initialize() diff --git a/UIX/Microsoft/Iris/ViewItems/ImageLayout.cs b/UIX/Microsoft/Iris/ViewItems/ImageLayout.cs index d0c7d2b..e781c1d 100644 --- a/UIX/Microsoft/Iris/ViewItems/ImageLayout.cs +++ b/UIX/Microsoft/Iris/ViewItems/ImageLayout.cs @@ -72,5 +72,16 @@ namespace Microsoft.Iris.ViewItems } void ILayout.Arrange(ILayoutNode layoutNode, LayoutSlot slot) => DefaultLayout.Arrange(layoutNode, slot); + + public bool Equals(ILayout other) + { + if (other is not ImageLayout o) return false; + + return DefaultChildAlignment == o.DefaultChildAlignment + && SourceSize == o.SourceSize + && MinimumSize == o.MinimumSize + && MaintainAspectRatio == o.MaintainAspectRatio + && Fill == o.Fill; + } } } diff --git a/UIX/Microsoft/Iris/ViewItems/Text.cs b/UIX/Microsoft/Iris/ViewItems/Text.cs index df5792c..49b431b 100644 --- a/UIX/Microsoft/Iris/ViewItems/Text.cs +++ b/UIX/Microsoft/Iris/ViewItems/Text.cs @@ -1430,6 +1430,11 @@ namespace Microsoft.Iris.ViewItems text._bits = (uint)((Bits)text._bits & ~changeBit); } + public bool Equals(ILayout other) + { + return this == other; + } + private class MarkedRange { public string tagName; diff --git a/UIX/Microsoft/Iris/ViewItems/TextRunRenderer.cs b/UIX/Microsoft/Iris/ViewItems/TextRunRenderer.cs index 96cdea3..36dfcfa 100644 --- a/UIX/Microsoft/Iris/ViewItems/TextRunRenderer.cs +++ b/UIX/Microsoft/Iris/ViewItems/TextRunRenderer.cs @@ -115,5 +115,14 @@ namespace Microsoft.Iris.ViewItems } void ILayout.Arrange(ILayoutNode layoutNode, LayoutSlot slot) => DefaultLayout.Arrange(layoutNode, slot); + + public bool Equals(ILayout other) + { + if (other is not TextRunRenderer o) return false; + + return DefaultChildAlignment == o.DefaultChildAlignment + && Color == o.Color + && Data.ToString() == o.Data.ToString(); + } } }