using HDL_ON.UI.Music; using System; using Shared; namespace HDL_ON.UI.UI2.FuntionControlView.Aks.CommonView { public class TypeSingleFramLayout { /// /// 是否可以点击 /// private bool mIsClick = true; private uint UpBackgroundColor = BaseFramLayout.unParentBackgroundColor; private uint DownBackgroundColor = BaseFramLayout.seleBackgroundColor; /// /// 设置控制点击事件 /// /// false点击无效 public void setClick(bool isClick) { this.mIsClick = isClick; } /// /// 单个类型容器 /// public FrameLayout singleFramLayout = new FrameLayout { BackgroundColor = MusicColor.ViewColor, //Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(101), Height = Application.GetRealHeight(34),//40 Radius = (uint)Application.GetRealHeight(17), }; public 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", }; public Button btnName = new Button { Width = Application.GetRealWidth(32), Height = Application.GetRealHeight(23), TextID = StringId.yingku, TextSize = TextSize.Text16, TextColor = MusicColor.TextColor, TextAlignment = TextAlignment.Center, Gravity = Gravity.CenterVertical, Padding = new Padding(0, 0, 0, 0), Name = "btnName", }; public Button btnRightImage = new Button { Width = Application.GetRealWidth(5), Height = Application.GetRealWidth(8), UnSelectedImagePath = "AksIcon/yingkunext.png", Gravity = Gravity.CenterVertical, Name = "btnRightImage", }; public void AddView(FrameLayout layout) { layout.AddChidren(singleFramLayout); singleFramLayout.AddChidren(btnLeftImage); singleFramLayout.AddChidren(btnName); singleFramLayout.AddChidren(btnRightImage); btnName.X = btnLeftImage.Right + Application.GetRealWidth(4); btnRightImage.X = btnName.Right + Application.GetRealWidth(8); } 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) => { action?.Invoke(singleFramLayout); //singleFramLayout.BackgroundColor = this.UpBackgroundColor; //弹起来还原背景颜色 }; singleFramLayout.MouseUpEventHandler += UpClick; btnLeftImage.MouseUpEventHandler += UpClick; btnName.MouseUpEventHandler += UpClick; btnRightImage.MouseUpEventHandler += UpClick; EventHandler DownClick = (sender, e) => { //按下去改变背景颜色 //singleFramLayout.BackgroundColor = this.DownBackgroundColor; }; singleFramLayout.MouseDownEventHandler += DownClick; btnLeftImage.MouseDownEventHandler += DownClick; btnName.MouseDownEventHandler += DownClick; btnRightImage.MouseDownEventHandler += DownClick; } /// /// 自动计算控件长度 /// /// 位置(左或右) /// 父容器 /// 备注控件 /// 图标备注控件 /// 备注控件宽度 /// 备注控件宽度最大值 /// 父控件宽度默认最大值 public void CustomCalculationWidth(Orientation orientation, FrameLayout frame, Button btnName, Button btnImage, int btnNameWidth,int btnNameWidthMaxValue = 110, int parentDefaultWidthMaxValue = 101) { int parentRightX = 226; int parentLeftX = 16; if (btnName.GetTextWidth() > Application.GetRealWidth(btnNameWidth)) { frame.Width = Application.GetRealWidth(parentDefaultWidthMaxValue - btnNameWidth) + btnName.GetTextWidth(); if (orientation == Orientation.right) { frame.X = Application.GetRealWidth(parentRightX + btnNameWidth) - btnName.GetTextWidth(); } else if (orientation == Orientation.left) { frame.X = Application.GetRealWidth(parentLeftX); } btnName.Width = btnName.GetTextWidth(); btnImage.X = btnName.Right + Application.GetRealWidth(8); } if (btnName.GetTextWidth() > Application.GetRealWidth(btnNameWidthMaxValue)) { btnName.Width = Application.GetRealWidth(btnNameWidthMaxValue); if (orientation == Orientation.right) { frame.X =Application.GetRealWidth(parentRightX+ btnNameWidth) - btnName.Width; } else if (orientation == Orientation.left) { frame.X = Application.GetRealWidth(parentLeftX); } frame.Width = Application.GetRealWidth(parentDefaultWidthMaxValue - btnNameWidth) + btnName.Width; btnImage.X = btnName.Right + Application.GetRealWidth(8); } } public enum Orientation { left, right, } } }