using Shared; using HDL_ON.UI.CSS; using System; using System.Collections.Generic; using System.Text; namespace HDL_ON.Stan { /// /// 有标题的弹窗型菜单选择控件(Y轴最好减掉12) /// public class DialogTitleMenuControl : NormalFrameLayout { #region ■ 变量声明___________________________ /// /// 列表控件 /// private VerticalListControl listView = null; /// /// 标题(初始化之后会置空) /// private string StrTitle = null; /// /// 行高度 /// private int RowHeight = HdlControlResourse.ListViewRowHeight; /// /// 行数 /// private int RowCount = 0; #endregion #region ■ 初始化_____________________________ /// /// 有标题的弹窗型菜单选择控件(Y轴最好减掉12) /// /// 菜单行数(不含标题) /// 标题 public DialogTitleMenuControl(int i_RowCount, string i_title) { //最大显示5个 this.RowCount = i_RowCount > 5 ? 5 : i_RowCount; this.StrTitle = i_title; } /// /// 初始化控件 /// private void InitControl() { //已经初始化过,不需要再次初始化 if (this.StrTitle == null) { return; } this.BackgroundImagePath = "FunctionIcon/Electrical/Fan/DialogTitleMenuGroud" + this.RowCount + ".png"; //标题行 var rowTitle = new FrameRowControl(); rowTitle.LeftOffset = Application.GetRealWidth(24) - HdlControlResourse.XXLeft; rowTitle.Y = Application.GetRealHeight(8); rowTitle.Width = this.Width; rowTitle.Height = this.RowHeight; this.AddChidren(rowTitle); //标题 var btnTitle = rowTitle.AddLeftCaption(this.StrTitle, 100); //从X轴开始,铺满整一行 btnTitle.Width = rowTitle.Width - btnTitle.X; btnTitle.TextColor = CSS_Color.FirstLevelTitleColor; btnTitle.TextSize = CSS_FontSize.SubheadingFontSize; //线 var btnLine = rowTitle.AddBottomLine(); btnLine.Width = rowTitle.Width - Application.GetRealWidth(24) * 2; btnLine.Gravity = Gravity.CenterHorizontal; btnLine.BackgroundColor = CSS_Color.BackgroundColor; this.StrTitle = null; //列表控件 this.listView = new VerticalListControl(); listView.Y = rowTitle.Bottom; listView.Height = this.RowCount * this.RowHeight; this.AddChidren(listView); } #endregion #region ■ 添加菜单___________________________ /// /// 添加菜单行(它最终的父控件需要手动关闭) /// /// 显示的文字 /// 图片( /// 是否是选择状态 /// 单击菜单执行的事件 public void AddRowMenu(string i_textValue, string i_iconPath, bool i_select, Action clickEvent) { //先初始化控件 this.InitControl(); uint fontColor = i_select == true ? CSS_Color.MainColor : CSS_Color.FirstLevelTitleColor; //生成行控件 var frameRow = this.CreatRowControl(i_iconPath, i_textValue, fontColor); frameRow.ButtonClickEvent += (sender, e) => { //调用回调函数 clickEvent?.Invoke(); clickEvent = null; }; } /// /// 生成行控件 /// /// 图标 /// 显示的文字 /// 字体颜色 /// private FrameRowControl CreatRowControl(string i_iconPath, string i_text, uint i_fontColor) { //它的上一行 var rowBefor = this.listView.GetChildren(this.listView.ChildrenCount - 1) as FrameRowControl; if (rowBefor != null) { //画底线 var btnLine = rowBefor.AddBottomLine(); btnLine.Width = rowBefor.Width - Application.GetRealWidth(24) * 2; btnLine.Gravity = Gravity.CenterHorizontal; btnLine.BackgroundColor = CSS_Color.BackgroundColor; } //行 var rowContr = new FrameRowControl(); rowContr.LeftOffset = Application.GetRealWidth(24) - HdlControlResourse.XXLeft; rowContr.Width = this.Width; rowContr.Height = this.RowHeight; this.listView.AddChidren(rowContr); //图标 rowContr.AddLeftIcon(24, i_iconPath); //显示文本 var btnView = rowContr.AddLeftCaption(i_text, 92); //从X轴开始,铺满整一行 btnView.Width = rowContr.Width - btnView.X; btnView.TextColor = i_fontColor; return rowContr; } #endregion } }