using System;
using HDL_ON.UI.Music;
using Shared;
using System.Collections.Generic;
namespace HDL_ON.UI.UI2.FuntionControlView.Aks.CommonView
{
///
/// 自定义圆角容器
///
public class CornerFramLayout : BaseFramLayout
{
private int topMargin;
private int leftMargin;
private int bottomMargin;
private int rightMargin;
///
/// 一行几个元素
///
private int mRowNumber;
private List mList;
public Action selectAction = null;
///
/// 当前选择的索引(内部使用)
///
private int CurrnetSelectIndex = -1;
///
///
///
/// 容器宽度
/// 容器高度
///一行几个元素
///圆角值
public CornerFramLayout(int width, int height, int rowNumber,int radius=0)
{
this.BackgroundColor = MusicColor.WhiteColor;
this.Width = Application.GetRealWidth(width);
this.Height = Application.GetRealHeight(height);
this.Radius = (uint)Application.GetRealHeight(radius);
this.mRowNumber = rowNumber;
}
///
/// 设置内边距
///
/// 上边距
/// 下边距
/// 左边距
/// 右边距
public void SetMargin(int top, int bottom, int left, int right)
{
this.topMargin = top;
this.bottomMargin = bottom;
this.leftMargin = left;
this.rightMargin = right;
}
///
/// 设置列表数据(请在初始化完成之前调用)
///
///
public void SetList(List list)
{
if (list == null)
{
list = new List();
}
this.mList = list;
}
///
/// 获取测试列表数据
///
public List GetTestList(int count)
{
var list = new List();
for (int i = 1; i <= count; i++)
{
list.Add(i);
}
return list;
}
///
/// 动态加载按键界面
///
public void LoadButtonPage()
{
if (this.mRowNumber == 0)
{
return;
}
int line = 0;
int xCount = 0;
for (int i = 1; i <= this.mList.Count; i++)
{
ButtonFramLayout buttonFram = new ButtonFramLayout();
this.AddChidren(buttonFram);
buttonFram.Tag = i - 1;
buttonFram.Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight(ButtonFramLayout.heightFrameLayout * line);
buttonFram.X = Application.GetRealWidth(this.leftMargin) + Application.GetRealWidth(ButtonFramLayout.widthFrameLayout * xCount);
buttonFram.AddImageView();
buttonFram.AddNameView();
if (!IsLastRight(i))
{
buttonFram.AddRightLine();
}
if (!IsLastColumn(i))
{
buttonFram.AddBottomLine();
}
buttonFram.GetNameButton().Text = i.ToString();
xCount++;
if (i % this.mRowNumber == 0)
{
line++;
xCount = 0;
}
buttonFram.SetClickListener((fl, btnIcon, btnName) =>
{
selectAction?.Invoke((int)buttonFram.Tag);
});
//if (CurrnetSelectIndex != -1 && CurrnetSelectIndex == i)
//{
// selectAction?.Invoke((int)buttonFram.Tag);
//}
}
}
///
/// 动态加载图片界面
///
public void LoadImagePage()
{
if (this.mRowNumber == 0)
{
return;
}
int line = 0;
int xCount = 0;
for (int i = 1; i <= this.mList.Count; i++)
{
ImageFramlayout imageFram = new ImageFramlayout();
imageFram.AddView(this);
//this.AddChidren(imageFram);
imageFram.Tag = i - 1;
imageFram.Y = Application.GetRealHeight(this.topMargin)+ Application.GetRealHeight((ImageFramlayout.heightFrameLayout + 20) * line);
imageFram.X = Application.GetRealWidth((ImageFramlayout.widthFrameLayout + 8) * xCount);
//imageFram.AddImageView();
//imageFram.AddScoreButton();
//imageFram.AddNameButton();
imageFram.btnName.Text = i.ToString();
xCount++;
if (i % this.mRowNumber == 0)
{
line++;
xCount = 0;
}
imageFram.SetClickListener((fl) =>
{
selectAction?.Invoke((int)imageFram.Tag);
});
//if (CurrnetSelectIndex != -1 && CurrnetSelectIndex == i)
//{
// selectAction?.Invoke((int)imageFram.Tag);
//}
}
}
///
/// 设置初始选择(请在初始化完成之前调用)
///
/// 从列表0开始计算第一个元素,设置超过列表最大(new List().count-1)值视为无效
public void SetIndex(int index = -1)
{
if (index == -1) { return; }
this.CurrnetSelectIndex = index;
}
///
/// 最后一行
///
///
///
private bool IsLastColumn(int value)
{
int lineCount = this.mList.Count / this.mRowNumber;
int number = this.mList.Count % this.mRowNumber;
if (number != 0)
{
if (value > lineCount * this.mRowNumber)
{
return true;
}
}
else
{
if (value > lineCount-- * this.mRowNumber)
{
return true;
}
}
return false;
}
///
/// 最后右边那一个
///
///
///
private bool IsLastRight(int value)
{
if (value % this.mRowNumber == 0)
{
return true;
};
return false;
}
}
}