using HDL_ON.UI.Music;
using System;
using Shared;
namespace HDL_ON.UI.UI2.FuntionControlView.Aks.CommonView
{
public class TypeMultiFramLayout:BaseFramLayout
{
private uint UpBackgroundColor = 0x00000000;
private uint DownBackgroundColor = 0xff454635;
public TypeMultiFramLayout()
{
this.BackgroundColor = MusicColor.ViewColor;
this.Height = Application.GetRealHeight(40);
this.Radius = (uint)Application.GetRealHeight(20);
}
Button btnLeftImage = new Button
{
X = Application.GetRealWidth(16),
Width = Application.GetRealWidth(16),
Height = Application.GetRealWidth(16),
UnSelectedImagePath = "AksIcon/yingku.png",
Gravity = Gravity.CenterVertical,
Name = "btnLeftImage",
};
Button btnName1 = new Button
{
Width = Application.GetRealWidth(32),
Height = Application.GetRealHeight(23),
TextSize = TextSize.Text16,
TextColor = MusicColor.TextColor,
TextAlignment = TextAlignment.Center,
Gravity = Gravity.CenterVertical,
IsMoreLines = true,
Name = "btnName",
};
Button btnRightImage = new Button
{
Width = Application.GetRealWidth(16),
Height = Application.GetRealWidth(16),
UnSelectedImagePath = "AksIcon/yingkunext.png",
Gravity = Gravity.CenterVertical,
Name = "btnRightImage",
};
public void AddBtnLeftImage()
{
this.AddChidren(btnLeftImage);
}
public void AddBtnName(int gap = 4)
{
if (this.IsAddBtn(btnLeftImage))
{
btnName1.X = btnLeftImage.Right + Application.GetRealWidth(gap);
}
//if (btnName.GetTextWidth() < btnName.Width)
//{
// btnName.Width = btnName.GetTextWidth();
//}
this.AddChidren(btnName1);
}
public void AddBtnRightImage(int gap = 8)
{
if (this.IsAddBtn(btnName1))
{
btnRightImage.X = btnName1.Right + Application.GetRealWidth(gap);
if (gap == 8)
{
btnRightImage.Width = Application.GetRealWidth(5);
btnRightImage.Height = Application.GetRealHeight(8);
}
}
this.AddChidren(btnRightImage);
}
public Button GetBtnLeftImage()
{
return btnLeftImage;
}
public Button GetBtnName()
{
return btnName1;
}
public Button GetBtnRightImage()
{
return btnRightImage;
}
public void SetClickUpBackgroundColor(uint backgroundColor)
{
this.UpBackgroundColor = backgroundColor;
}
public void SetClickDownBackgroundColor(uint backgroundColor)
{
this.DownBackgroundColor = backgroundColor;
}
///
/// 事件监听方法
///
/// 回调(第一个是父类对象;第二个是图标对象;第三个是状态对象
public void SetClickListener(Action action)
{
EventHandler UpClick = (sender, e) =>
{
this.BackgroundColor = this.UpBackgroundColor;
action?.Invoke(this, btnLeftImage, btnName1, btnRightImage);
//弹起来还原背景颜色
};
this.MouseUpEventHandler += UpClick;
btnLeftImage.MouseUpEventHandler += UpClick;
btnName1.MouseUpEventHandler += UpClick;
btnRightImage.MouseUpEventHandler += UpClick;
EventHandler DownClick = (sender, e) =>
{
//按下去改变背景颜色
this.BackgroundColor = this.DownBackgroundColor;
};
this.MouseDownEventHandler += DownClick;
btnLeftImage.MouseDownEventHandler += DownClick;
btnName1.MouseDownEventHandler += DownClick;
btnRightImage.MouseDownEventHandler += DownClick;
}
///
/// 在父布局查找子控件是否存在
///
/// 查找对象
/// 存在为true,否则为false
private bool IsAddBtn(View btn)
{
if (this.ChildrenCount <= 0 || btn == null)
{
return false;
}
for (int i = 0; i < this.ChildrenCount; i++)
{
View view = this.GetChildren(i);
if (view == null)
{
continue;
}
if (view is Button)
{
if (view.Name == btn.Name)
{
return true;
}
}
}
return false;
}
}
}