Skip to content

Commit 9aa1afe

Browse files
Merge pull request 50044 from feature/reflection into master
1 parent 55d8631 commit 9aa1afe

File tree

1 file changed

+2
-84
lines changed

1 file changed

+2
-84
lines changed

Runtime/Extensions/NodeExtensions.cs

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ record Metadata(UIDocument document, UxmlAttribute uxml, string path);
2626
static Dictionary<VisualElement, Metadata> rootMetadata = new();
2727
static List<VisualElement> search = new(256);
2828
static Dictionary<VisualElement, string> cloneMap = new(256);
29-
30-
static Dictionary<string, (float width, float height)> cachedDimensions = new();
3129
#endregion
3230

3331
#region Properties
@@ -46,8 +44,6 @@ public static void Initialize(UIDocument document, IEnumerable<IRootElement> tar
4644
{
4745
foreach (IRootElement target in targets.Where(x => x is not null))
4846
Initialize(document, target);
49-
50-
CacheDimensions(document);
5147
}
5248
public static void Initialize(UIDocument document, IRootElement target)
5349
{
@@ -510,23 +506,8 @@ public static async void MarginMe(this VisualElement value)
510506
{
511507
static int GetLines(VisualElement value, VisualElement parent, float spacing, bool horizontalDirection)
512508
{
513-
string className = value.GetClasses().Last();
514-
float valueSize;
515-
if (cachedDimensions.ContainsKey(className))
516-
valueSize = horizontalDirection
517-
? cachedDimensions[className].width
518-
: cachedDimensions[className].height;
519-
else
520-
valueSize = horizontalDirection ? value.resolvedStyle.width : value.resolvedStyle.height;
521-
522-
string parentClassName = parent.GetClasses().Last();
523-
float parentSize;
524-
if (cachedDimensions.ContainsKey(parentClassName))
525-
parentSize = horizontalDirection
526-
? cachedDimensions[parentClassName].width
527-
: cachedDimensions[parentClassName].height;
528-
else
529-
parentSize = horizontalDirection ? parent.resolvedStyle.width : parent.resolvedStyle.height;
509+
float valueSize = horizontalDirection ? value.resolvedStyle.width : value.resolvedStyle.height;
510+
float parentSize = horizontalDirection ? parent.resolvedStyle.width : parent.resolvedStyle.height;
530511

531512
return (valueSize.Invalid() || valueSize == 0) ? parent.childCount : (int)(parentSize / ((2 * valueSize + (spacing.Invalid() ? 0 : spacing)) / 2));
532513
}
@@ -585,20 +566,6 @@ static int FindIndex(VisualElement value, IEnumerable<VisualElement> children)
585566
if (index >= lines) children.ElementAt(index - lines).style.marginRight = counterMargin;
586567
}
587568
}
588-
public static float Width(this VisualElement element)
589-
{
590-
foreach (string className in element.GetClasses())
591-
if (cachedDimensions.ContainsKey(className)) return cachedDimensions[className].width;
592-
593-
return 0;
594-
}
595-
public static float Height(this VisualElement element)
596-
{
597-
foreach (string className in element.GetClasses())
598-
if (cachedDimensions.ContainsKey(className)) return cachedDimensions[className].height;
599-
600-
return 0;
601-
}
602569
#endregion
603570

604571
#region Support Methods
@@ -798,55 +765,6 @@ VisualElement FindIn(VisualElement root)
798765
}
799766
}
800767
}
801-
802-
[Obsolete("This code will be removed soon")]
803-
static void CacheDimensions(UIDocument document)
804-
{
805-
static object GetValue(object target, string name) => target.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).GetValue(target);
806-
807-
StyleSheet uss = document.visualTreeAsset.stylesheets.First();
808-
809-
object[] complexSelectors = (object[])GetValue(uss, "m_ComplexSelectors");
810-
object[] rules = (object[])GetValue(uss, "m_Rules");
811-
object[] dimensions = ((IEnumerable)GetValue(uss, "dimensions")).Cast<object>().ToArray();
812-
813-
float width = 0, height = 0;
814-
for (int i = 0; i < complexSelectors.Length; ++i)
815-
{
816-
object[] properties = (object[])GetValue(rules[i], "m_Properties");
817-
foreach (object property in properties)
818-
{
819-
string propertyName = GetValue(property, "m_Name").ToString();
820-
if (propertyName is not "width" and not "height") continue;
821-
822-
object propertyValue = ((IEnumerable)GetValue(property, "m_Values")).Cast<object>().First();
823-
string valueType = GetValue(propertyValue, "m_ValueType").ToString();
824-
if (valueType is not "Dimension") continue;
825-
826-
int valueIndex = (int)GetValue(propertyValue, "valueIndex");
827-
828-
string unit = GetValue(dimensions[(int)valueIndex], "unit").ToString();
829-
if (unit is not "Pixel") continue;
830-
831-
float value = (float)GetValue(dimensions[valueIndex], "value");
832-
833-
width = propertyName is "width" ? value : width;
834-
height = propertyName is "height"? value : height;
835-
}
836-
837-
if (width != 0 || height != 0)
838-
{
839-
object selector = ((object[])GetValue(complexSelectors[i], "m_Selectors")).First();
840-
object part = ((IEnumerable)GetValue(selector, "m_Parts")).Cast<object>().First();
841-
string className = GetValue(part, "m_Value").ToString();
842-
843-
cachedDimensions.Add(className, new(width, height));
844-
845-
width = 0;
846-
height = 0;
847-
}
848-
}
849-
}
850768
#endregion
851769
}
852770
}

0 commit comments

Comments
 (0)