update UIElements

This commit is contained in:
何冠峰
2025-02-05 18:49:11 +08:00
parent 7e1dc7ef24
commit 4e6c146bde
7 changed files with 80 additions and 296 deletions
@@ -14,22 +14,17 @@ namespace YooAsset.Editor
/// <summary>
/// 单元列宽度
/// </summary>
public Length Width = 100f;
public Length Width;
/// <summary>
/// 单元列最小宽度
/// </summary>
public Length MinWidth = 30f;
public Length MinWidth;
/// <summary>
/// 单元列最大宽度
/// </summary>
public Length MaxWidth = MaxValue;
/// <summary>
/// 文本的锚点类型
/// </summary>
public TextAnchor TxtAnchor = TextAnchor.MiddleLeft;
public Length MaxWidth;
/// <summary>
/// 可伸缩
@@ -45,6 +40,25 @@ namespace YooAsset.Editor
/// 可排序
/// </summary>
public bool Sortable = false;
public ColumnStyle(Length width)
{
if (width.value > MaxValue)
width = MaxValue;
Width = width;
MinWidth = width;
MaxWidth = width;
}
public ColumnStyle(Length width, Length minWidth, Length maxWidth)
{
if (maxWidth.value > MaxValue)
maxWidth = MaxValue;
Width = width;
MinWidth = minWidth;
MaxWidth = maxWidth;
}
}
}
#endif
@@ -108,13 +108,11 @@ namespace YooAsset.Editor
}
/// <summary>
/// 设置标题
/// 获取标题UI元素
/// </summary>
public void SetHeaderTitle(string elementName, string headerTitle)
public VisualElement GetHeaderElement(string elementName)
{
var toolbarBtn = _toolbar.Q<ToolbarButton>(elementName);
if (toolbarBtn != null)
toolbarBtn.text = headerTitle;
return _toolbar.Q<ToolbarButton>(elementName);
}
/// <summary>
@@ -126,7 +124,6 @@ namespace YooAsset.Editor
toolbarBtn.userData = column;
toolbarBtn.name = column.ElementName;
toolbarBtn.text = column.HeaderTitle;
toolbarBtn.style.unityTextAlign = column.ColumnStyle.TxtAnchor;
toolbarBtn.style.flexGrow = 0;
toolbarBtn.style.width = column.ColumnStyle.Width;
toolbarBtn.style.minWidth = column.ColumnStyle.Width;
@@ -311,14 +308,17 @@ namespace YooAsset.Editor
{
VisualElement listViewElement = new VisualElement();
listViewElement.style.flexDirection = FlexDirection.Row;
foreach (var colum in _columns)
foreach (var column in _columns)
{
var cellElement = colum.MakeCell.Invoke();
cellElement.name = colum.ElementName;
var cellElement = column.MakeCell.Invoke();
cellElement.name = column.ElementName;
cellElement.style.flexGrow = 0f;
cellElement.style.width = column.ColumnStyle.Width;
cellElement.style.minWidth = column.ColumnStyle.Width;
cellElement.style.maxWidth = column.ColumnStyle.Width;
SetCellElementStyle(cellElement);
listViewElement.Add(cellElement);
colum.CellElements.Add(cellElement);
column.CellElements.Add(cellElement);
}
return listViewElement;
}