using System;
|
using Shared;
|
using HDL_ON.UI.Music;
|
using System.Collections.Generic;
|
using HDL_ON.UI.UI2.FuntionControlView.Aks.Entity;
|
|
namespace HDL_ON.UI.UI2.FuntionControlView.Aks.CommonView
|
{
|
/// <summary>
|
/// 水平滑动容器
|
/// </summary>
|
public class HorizontalFramLayout : HorizontalScrolViewLayout
|
{
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="width">容器宽度</param>
|
/// <param name="height">容器高度</param>
|
public HorizontalFramLayout(int width, int height)
|
{
|
this.Height = Application.GetRealHeight(height);
|
this.Width = Application.GetRealWidth(width);
|
}
|
|
/// <summary>
|
/// 选择事件
|
/// </summary>
|
public Action<Filters> SelectTypeEvent = null;
|
|
/// <summary>
|
/// 初始化控件
|
/// </summary>
|
/// <param name="mList">显示数据列表</param>
|
/// <param name="defaultIndex">默认值索引范围[0,mList.count-1],大于范围,该值视为无效</param>
|
public void InitControl(List<Filters> mList, int defaultIndex = -1)
|
{
|
if (mList == null || mList.Count == 0)
|
{
|
return;
|
}
|
bool isBool = false;
|
Button btnSelected = new Button();
|
for (int i = 0; i < mList.Count; i++)
|
{
|
|
var filters = mList[i];
|
Button button = new Button
|
{
|
Height = Application.GetRealHeight(28),
|
Width = Application.GetRealWidth(20),
|
SelectedBackgroundColor = MusicColor.ViewColor,
|
BackgroundColor = 0x00000000,
|
Text = mList[i].filterName,
|
TextSize = TextSize.Text14,
|
TextColor = MusicColor.TextColor,
|
SelectedTextColor = MusicColor.MusicTxet14SelectedColor,
|
TextAlignment = TextAlignment.Center,
|
Padding = new Padding(4, 4, 4, 4),
|
Radius = (uint)Application.GetRealHeight(4),
|
Tag = filters,
|
};
|
|
//重新计算组件宽度
|
button.Width = button.GetTextWidth() + Application.GetRealWidth(4 + 4);
|
this.AddChidren(button);
|
//间隔,弄个空的进去占位置
|
Button btnSpacing = new Button
|
{
|
Height = Application.GetRealHeight(28),
|
Width = Application.GetRealWidth(20),
|
BackgroundColor = 0x00000000,
|
};
|
this.AddChidren(btnSpacing);
|
button.MouseDownEventHandler += (sen, e) =>
|
{
|
btnSelected.IsSelected = false;
|
button.IsSelected = true;
|
btnSelected = button;
|
if (button.Tag == null || !(button.Tag is Filters))
|
{
|
return;
|
}
|
SelectTypeEvent?.Invoke((Filters)button.Tag);
|
|
};
|
if (defaultIndex != -1 && defaultIndex == i)
|
{
|
btnSelected.IsSelected = false;
|
button.IsSelected = true;
|
btnSelected = button;
|
isBool = true;
|
}
|
}
|
|
if (isBool)
|
{
|
if (defaultIndex < mList.Count)
|
{
|
//默认索引回调,初始化时执行
|
SelectTypeEvent?.Invoke(mList[defaultIndex]);
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
/// 控件摧毁
|
/// </summary>
|
public override void RemoveFromParent()
|
{
|
this.SelectTypeEvent = null;
|
base.RemoveFromParent();
|
}
|
|
}
|
}
|