Add public PredefinedLayouts

This commit is contained in:
Yoshi Askharoun
2024-02-18 22:23:59 -06:00
parent 3bd3531f44
commit 2e5eaedcdc
16 changed files with 191 additions and 32 deletions
+2 -1
View File
@@ -5,10 +5,11 @@
// Assembly location: C:\Program Files\Zune\UIX.dll // Assembly location: C:\Program Files\Zune\UIX.dll
using Microsoft.Iris.Render; using Microsoft.Iris.Render;
using System;
namespace Microsoft.Iris.Layout namespace Microsoft.Iris.Layout
{ {
public interface ILayout public interface ILayout : IEquatable<ILayout>
{ {
Size Measure(ILayoutNode layoutNode, Size constraint); Size Measure(ILayoutNode layoutNode, Size constraint);
@@ -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<string, ILayout> s_NameToLayoutMap = new(10)
{
["anchor"] = Anchor,
["default"] = Default,
["dock"] = Dock,
["grid"] = Grid,
["scale"] = Scale,
["popup"] = Popup,
["stack"] = Stack,
["form"] = Form,
["horizontalflow"] = HorizontalFlow,
["verticalflow"] = VerticalFlow,
};
}
@@ -350,6 +350,15 @@ namespace Microsoft.Iris.Layouts
return null; 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 static DataCookie InputData => s_dataProperty;
internal enum LayoutPhase internal enum LayoutPhase
@@ -6,6 +6,7 @@
using Microsoft.Iris.Layout; using Microsoft.Iris.Layout;
using Microsoft.Iris.Render; using Microsoft.Iris.Render;
using System;
namespace Microsoft.Iris.Layouts namespace Microsoft.Iris.Layouts
{ {
@@ -42,5 +43,12 @@ namespace Microsoft.Iris.Layouts
foreach (ILayoutNode layoutChild in layoutNode.LayoutChildren) foreach (ILayoutNode layoutChild in layoutNode.LayoutChildren)
layoutChild.Arrange(slot); layoutChild.Arrange(slot);
} }
public bool Equals(ILayout other)
{
if (other is not DefaultLayout o) return false;
return DefaultChildAlignment == o.DefaultChildAlignment;
}
} }
} }
+8
View File
@@ -120,5 +120,13 @@ namespace Microsoft.Iris.Layouts
dockLayoutInput = _defaultLayoutInput ?? s_defaultLayoutInput; dockLayoutInput = _defaultLayoutInput ?? s_defaultLayoutInput;
return dockLayoutInput; return dockLayoutInput;
} }
public bool Equals(ILayout other)
{
if (other is not DockLayout o) return false;
return DefaultChildAlignment == o.DefaultChildAlignment
&& DefaultLayoutInput.ToString() == other.DefaultChildAlignment.ToString();
}
} }
} }
+15
View File
@@ -696,6 +696,21 @@ namespace Microsoft.Iris.Layouts
return majorMinor; 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 internal class Record
{ {
public int Index; public int Index;
+14
View File
@@ -538,6 +538,20 @@ namespace Microsoft.Iris.Layouts
return roundUp ? (int)Math.Ceiling(num) : (int)Math.Floor(num); 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 private enum ViewIntersectionType
{ {
BeginOffscreen, BeginOffscreen,
@@ -12,6 +12,7 @@ using Microsoft.Iris.Render;
using Microsoft.Iris.RenderAPI.Drawing; using Microsoft.Iris.RenderAPI.Drawing;
using Microsoft.Iris.Session; using Microsoft.Iris.Session;
using Microsoft.Iris.UI; using Microsoft.Iris.UI;
using Microsoft.Iris.ViewItems;
using System; using System;
using System.Collections; 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 private class PlacementTargetInfo
{ {
public ViewItem child; public ViewItem child;
@@ -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 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); 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;
}
} }
} }
+11
View File
@@ -8,6 +8,7 @@ using Microsoft.Iris.Drawing;
using Microsoft.Iris.Layout; using Microsoft.Iris.Layout;
using Microsoft.Iris.Render; using Microsoft.Iris.Render;
using Microsoft.Iris.RenderAPI.Drawing; using Microsoft.Iris.RenderAPI.Drawing;
using Microsoft.Iris.ViewItems;
using System; using System;
namespace Microsoft.Iris.Layouts namespace Microsoft.Iris.Layouts
@@ -92,5 +93,15 @@ namespace Microsoft.Iris.Layouts
view.Height = (int)Math.Round(view.Height / (double)scale.Height); view.Height = (int)Math.Round(view.Height / (double)scale.Height);
return view; 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;
}
} }
} }
@@ -329,5 +329,14 @@ namespace Microsoft.Iris.Layouts
public static bool ScrollFocusIntoView => s_allowScrollFocusIntoView; public static bool ScrollFocusIntoView => s_allowScrollFocusIntoView;
public static void DisallowScrollFocusIntoView() => s_allowScrollFocusIntoView = false; 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;
}
} }
} }
@@ -7,6 +7,7 @@
using Microsoft.Iris.Layout; using Microsoft.Iris.Layout;
using Microsoft.Iris.Library; using Microsoft.Iris.Library;
using Microsoft.Iris.Render; using Microsoft.Iris.Render;
using Microsoft.Iris.ViewItems;
using System; using System;
namespace Microsoft.Iris.Layouts namespace Microsoft.Iris.Layouts
@@ -96,5 +97,12 @@ namespace Microsoft.Iris.Layouts
stackLayoutInput = s_defaultLayoutInput; stackLayoutInput = s_defaultLayoutInput;
return stackLayoutInput; return stackLayoutInput;
} }
public bool Equals(ILayout other)
{
if (other is not StackLayout o) return false;
return DefaultChildAlignment == o.DefaultChildAlignment;
}
} }
} }
+3 -31
View File
@@ -5,26 +5,22 @@
// Assembly location: C:\Program Files\Zune\UIX.dll // Assembly location: C:\Program Files\Zune\UIX.dll
using Microsoft.Iris.Layout; using Microsoft.Iris.Layout;
using Microsoft.Iris.Layouts;
using Microsoft.Iris.Library; using Microsoft.Iris.Library;
using Microsoft.Iris.Render;
using System.Collections.Generic;
namespace Microsoft.Iris.Markup.UIX namespace Microsoft.Iris.Markup.UIX
{ {
internal static class LayoutSchema internal static class LayoutSchema
{ {
private static Dictionary<string, object> s_NameToLayoutMap = new Dictionary<string, object>(10);
public static UIXTypeSchema Type; public static UIXTypeSchema Type;
private static Result ConvertFromString(object valueObj, out object instanceObj) private static Result ConvertFromString(object valueObj, out object instanceObj)
{ {
string str = (string)valueObj; string str = (string)valueObj;
instanceObj = null; 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"); return Result.Fail("Unable to convert \"{0}\" to type '{1}'", str, "Layout");
ILayout layout = (ILayout)obj;
instanceObj = layout; instanceObj = layout;
return Result.Success; return Result.Success;
} }
@@ -55,30 +51,6 @@ namespace Microsoft.Iris.Markup.UIX
return ConvertFromString(parameter1, out instanceObj1).Failed ? parameter2 : instanceObj1; 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 Pass1Initialize() => Type = new UIXTypeSchema(132, "Layout", null, 153, typeof(ILayout), UIXTypeFlags.Immutable);
public static void Pass2Initialize() public static void Pass2Initialize()
@@ -72,5 +72,16 @@ namespace Microsoft.Iris.ViewItems
} }
void ILayout.Arrange(ILayoutNode layoutNode, LayoutSlot slot) => DefaultLayout.Arrange(layoutNode, slot); 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;
}
} }
} }
+5
View File
@@ -1430,6 +1430,11 @@ namespace Microsoft.Iris.ViewItems
text._bits = (uint)((Bits)text._bits & ~changeBit); text._bits = (uint)((Bits)text._bits & ~changeBit);
} }
public bool Equals(ILayout other)
{
return this == other;
}
private class MarkedRange private class MarkedRange
{ {
public string tagName; public string tagName;
@@ -115,5 +115,14 @@ namespace Microsoft.Iris.ViewItems
} }
void ILayout.Arrange(ILayoutNode layoutNode, LayoutSlot slot) => DefaultLayout.Arrange(layoutNode, slot); 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();
}
} }
} }