misc: translation.

This commit is contained in:
Zhang Dian
2024-06-14 22:04:07 +08:00
parent 75a961b43a
commit 33748cfa92

View File

@@ -2,7 +2,6 @@
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Layout; using Avalonia.Layout;
using Avalonia.Utilities; using Avalonia.Utilities;
using static System.Math; using static System.Math;
namespace Ursa.Controls; namespace Ursa.Controls;
@@ -73,12 +72,14 @@ public class ElasticWrapPanel : WrapPanel
double itemHeight = ItemHeight; double itemHeight = ItemHeight;
var orientation = Orientation; var orientation = Orientation;
var children = Children; var children = Children;
// 将元素按照水平/垂直排列的方式得出同一行/列所需的空间需求
// Determine the space required for items in the same row/column based on horizontal/vertical arrangement
var curLineSize = new UVSize(orientation); var curLineSize = new UVSize(orientation);
// 计算处此 ElasticWrapPanel 所需的空间大小需求结果
// Calculate the total space requirement for this ElasticWrapPanel
var panelSize = new UVSize(orientation); var panelSize = new UVSize(orientation);
// 给定的空间大小测量 UVSize用于没有 ItemWidth 和 ItemHeight 时候测量元素空间大小
// FixToRB=True 的元素也使用这个 // Measure UVSize with the given space constraint, used for measuring elements when ItemWidth and ItemHeight are not set
var uvConstraint = new UVSize(orientation, constraint.Width, constraint.Height); var uvConstraint = new UVSize(orientation, constraint.Width, constraint.Height);
bool itemWidthSet = !double.IsNaN(itemWidth); bool itemWidthSet = !double.IsNaN(itemWidth);
bool itemHeightSet = !double.IsNaN(itemHeight); bool itemHeightSet = !double.IsNaN(itemHeight);
@@ -87,7 +88,7 @@ public class ElasticWrapPanel : WrapPanel
itemWidthSet ? itemWidth : constraint.Width, itemWidthSet ? itemWidth : constraint.Width,
itemHeightSet ? itemHeight : constraint.Height); itemHeightSet ? itemHeight : constraint.Height);
// FixToRB=True 元素使用测量需求空间 Size // Measurement space for elements with FixToRB=True
Size childFixConstraint = new Size(constraint.Width, constraint.Height); Size childFixConstraint = new Size(constraint.Width, constraint.Height);
switch (orientation) switch (orientation)
{ {
@@ -99,7 +100,7 @@ public class ElasticWrapPanel : WrapPanel
break; break;
} }
//这个给非空间测量大小 // This is the size for non-space measurement
UVSize itemSetSize = new UVSize(orientation, UVSize itemSetSize = new UVSize(orientation,
itemWidthSet ? itemWidth : 0, itemWidthSet ? itemWidth : 0,
itemHeightSet ? itemHeight : 0); itemHeightSet ? itemHeight : 0);
@@ -107,57 +108,44 @@ public class ElasticWrapPanel : WrapPanel
foreach (var child in children) foreach (var child in children)
{ {
UVSize sz; UVSize sz;
if (ElasticWrapPanel.GetIsFixToRB(child)) if (GetIsFixToRB(child))
{ {
//此元素需要设置到固定靠右/底的型为操作,测量元素大小时需要放开 // Measure the element when it needs to be fixed to the right/bottom
child.Measure(childFixConstraint); child.Measure(childFixConstraint);
sz = new UVSize(orientation, child.DesiredSize.Width, child.DesiredSize.Height); sz = new UVSize(orientation, child.DesiredSize.Width, child.DesiredSize.Height);
//主要是我对与这个固定住的元素的需求宽度高度按照那个标准有点头疼,干脆放开用最大控件算了 // Ensure the width/height is within the constraint limits
if (sz.U > 0 && itemSetSize.U > 0) if (sz.U > 0 && itemSetSize.U > 0)
{ {
if (sz.U < itemSetSize.U) if (sz.U < itemSetSize.U)
{ {
//保持比例
sz.U = itemSetSize.U; sz.U = itemSetSize.U;
} }
else else
{ {
//设置了同方向中元素的长度,所以这里要按照比例
//double lengthCount = Ceiling(sz.U / ItemSetSize.U);
//sz.U = lengthCount * ItemSetSize.U;
//这里防止意外
sz.U = Min(sz.U, uvConstraint.U); sz.U = Min(sz.U, uvConstraint.U);
} }
} }
if (sz.V > 0 && itemSetSize.V > 0 && sz.V < itemSetSize.V) if (sz.V > 0 && itemSetSize.V > 0 && sz.V < itemSetSize.V)
{ {
//设置了垂直方向元素长度如果此元素空间需求小于则按照ItemSetSize.V
sz.V = itemSetSize.V; sz.V = itemSetSize.V;
} }
if (MathUtilities.GreaterThan(curLineSize.U + sz.U, uvConstraint.U)) if (MathUtilities.GreaterThan(curLineSize.U + sz.U, uvConstraint.U))
{ {
//当前同一 列/行 如果容纳 此元素空间将超出
panelSize.U = Max(curLineSize.U, panelSize.U); panelSize.U = Max(curLineSize.U, panelSize.U);
panelSize.V += curLineSize.V; panelSize.V += curLineSize.V;
curLineSize = sz; curLineSize = sz;
//当前元素需要启1个新行
panelSize.U = Max(curLineSize.U, panelSize.U);
panelSize.V += curLineSize.V;
} }
else else
{ {
//这里是元素空间足够 填充式布局
curLineSize.U += sz.U; curLineSize.U += sz.U;
curLineSize.V = Max(sz.V, curLineSize.V); curLineSize.V = Max(sz.V, curLineSize.V);
panelSize.U = Max(curLineSize.U, panelSize.U); panelSize.U = Max(curLineSize.U, panelSize.U);
panelSize.V += curLineSize.V; panelSize.V += curLineSize.V;
} }
//下一个可能是换行元素....用于存放全新1行
curLineSize = new UVSize(orientation); curLineSize = new UVSize(orientation);
} }
else else
@@ -176,7 +164,7 @@ public class ElasticWrapPanel : WrapPanel
panelSize.V += curLineSize.V; panelSize.V += curLineSize.V;
curLineSize = sz; curLineSize = sz;
if (MathUtilities.GreaterThan(sz.U, uvConstraint.U)) // The element is wider then the constraint - give it a separate line if (MathUtilities.GreaterThan(sz.U, uvConstraint.U)) // The element is wider than the constraint - give it a separate line
{ {
panelSize.U = Max(sz.U, panelSize.U); panelSize.U = Max(sz.U, panelSize.U);
panelSize.V += sz.V; panelSize.V += sz.V;
@@ -201,62 +189,55 @@ public class ElasticWrapPanel : WrapPanel
protected override Size ArrangeOverride(Size finalSize) protected override Size ArrangeOverride(Size finalSize)
{ {
//是否元素宽度设置,是否元素高度设置
bool itemWidthSet = !double.IsNaN(ItemWidth); bool itemWidthSet = !double.IsNaN(ItemWidth);
bool itemHeightSet = !double.IsNaN(ItemHeight); bool itemHeightSet = !double.IsNaN(ItemHeight);
//这个给非空间测量大小 // This is the size for non-space measurement
UVSize itemSetSize = new UVSize(Orientation, UVSize itemSetSize = new UVSize(Orientation,
itemWidthSet ? ItemWidth : 0, itemWidthSet ? ItemWidth : 0,
itemHeightSet ? ItemHeight : 0); itemHeightSet ? ItemHeight : 0);
//给定的空间大小测量 UVSize用于没有 ItemWidth ItemHeight 时候测量元素空间大小 // Measure UVSize with the given space constraint, used for measuring elements when ItemWidth and ItemHeight are not set
//FixToRB=True 的元素也使用这个
UVSize uvFinalSize = new UVSize(Orientation, finalSize.Width, finalSize.Height); UVSize uvFinalSize = new UVSize(Orientation, finalSize.Width, finalSize.Height);
//用于存放同一方向的元素列/行 集合 // Collection of elements in the same direction (row/column)
List<UVCollection> lineUVCollection = new List<UVCollection>(); List<UVCollection> lineUVCollection = new List<UVCollection>();
#region #region Get the collection of elements in the same direction
//当前元素集合行/列 // Current collection of elements in a row/column
UVCollection curLineUIs = new UVCollection(Orientation, itemSetSize); UVCollection curLineUIs = new UVCollection(Orientation, itemSetSize);
//遍历内部元素 // Iterate over the child elements
var children = Children; var children = Children;
foreach (var child in children) foreach (var child in children)
{ {
UVSize sz; UVSize sz;
if (ElasticWrapPanel.GetIsFixToRB(child)) if (GetIsFixToRB(child))
{ {
//此元素需要设置到固定靠右/底的型为操作,测量元素大小时需要放开 // Measure the element when it needs to be fixed to the right/bottom
sz = new UVSize(Orientation, child.DesiredSize.Width, child.DesiredSize.Height); sz = new UVSize(Orientation, child.DesiredSize.Width, child.DesiredSize.Height);
double lengthCount = 1; double lengthCount = 1;
if (sz.U > 0 && itemSetSize.U > 0) if (sz.U > 0 && itemSetSize.U > 0)
{ {
if (sz.U < itemSetSize.U) if (sz.U < itemSetSize.U)
{ {
//保持比例
sz.U = itemSetSize.U; sz.U = itemSetSize.U;
} }
else else
{ {
//设置了同方向中元素的长度,所以这里要按照比例
lengthCount = Ceiling(sz.U / itemSetSize.U); lengthCount = Ceiling(sz.U / itemSetSize.U);
//sz.U = lengthCount * ItemSetSize.U;
sz.U = Min(sz.U, uvFinalSize.U); sz.U = Min(sz.U, uvFinalSize.U);
} }
} }
if (sz.V > 0 && itemSetSize.V > 0 && sz.V < itemSetSize.V) if (sz.V > 0 && itemSetSize.V > 0 && sz.V < itemSetSize.V)
{ {
//设置了垂直方向元素长度如果此元素空间需求小于则按照ItemSetSize.V
sz.V = itemSetSize.V; sz.V = itemSetSize.V;
} }
if (MathUtilities.GreaterThan(curLineUIs.TotalU + sz.U, uvFinalSize.U)) if (MathUtilities.GreaterThan(curLineUIs.TotalU + sz.U, uvFinalSize.U))
{ {
//当前同一 列/行 如果容纳 此元素空间将超出
if (curLineUIs.Count > 0) if (curLineUIs.Count > 0)
{ {
lineUVCollection.Add(curLineUIs); lineUVCollection.Add(curLineUIs);
@@ -267,12 +248,10 @@ public class ElasticWrapPanel : WrapPanel
} }
else else
{ {
//这里是元素空间足够
curLineUIs.Add(child, sz, Convert.ToInt32(lengthCount)); curLineUIs.Add(child, sz, Convert.ToInt32(lengthCount));
} }
lineUVCollection.Add(curLineUIs); lineUVCollection.Add(curLineUIs);
//下一个可能是换行元素....不管了以后闲得蛋疼再弄吧
curLineUIs = new UVCollection(Orientation, itemSetSize); curLineUIs = new UVCollection(Orientation, itemSetSize);
} }
else else
@@ -283,7 +262,6 @@ public class ElasticWrapPanel : WrapPanel
if (MathUtilities.GreaterThan(curLineUIs.TotalU + sz.U, uvFinalSize.U)) // Need to switch to another line if (MathUtilities.GreaterThan(curLineUIs.TotalU + sz.U, uvFinalSize.U)) // Need to switch to another line
{ {
//当前同一 列/行 如果容纳 此元素空间将超出
if (curLineUIs.Count > 0) if (curLineUIs.Count > 0)
{ {
lineUVCollection.Add(curLineUIs); lineUVCollection.Add(curLineUIs);
@@ -299,7 +277,6 @@ public class ElasticWrapPanel : WrapPanel
} }
else else
{ {
//空间足够
curLineUIs.Add(child, sz); curLineUIs.Add(child, sz);
} }
} }
@@ -378,7 +355,6 @@ public class ElasticWrapPanel : WrapPanel
{ {
if (itemSetSize.U > 0) if (itemSetSize.U > 0)
{ {
//说明同方向有宽度设置,这里尽量按照 ItemULength 保持
layoutSlotU = childSize.ULengthCount * itemSetSize.U + layoutSlotU = childSize.ULengthCount * itemSetSize.U +
childSize.ULengthCount * adaptULength; childSize.ULengthCount * adaptULength;
double leaveULength = uvFinalSize.U - u; double leaveULength = uvFinalSize.U - u;