黄学彪
2021-01-28 1fcf2302f79f9cbea5ef17c3688311ed65cfabb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using Shared;
using HDL_ON.UI.CSS;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace HDL_ON.Stan
{
    /// <summary>
    /// 有标题的弹窗型菜单选择控件(Y轴最好减掉12)
    /// </summary>
    public class DialogTitleMenuControl : NormalFrameLayout
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listView = null;
        /// <summary>
        /// 标题(初始化之后会置空)
        /// </summary>
        private string StrTitle = null;
        /// <summary>
        /// 行高度
        /// </summary>
        private int RowHeight = HdlControlResourse.ListViewRowHeight;
        /// <summary>
        /// 行数
        /// </summary>
        private int RowCount = 0;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 有标题的弹窗型菜单选择控件(Y轴最好减掉12)
        /// </summary>
        /// <param name="i_RowCount">菜单行数(不含标题)</param>
        /// <param name="i_title">标题</param>
        public DialogTitleMenuControl(int i_RowCount, string i_title)
        {
            //最大显示5个
            this.RowCount = i_RowCount > 5 ? 5 : i_RowCount;
            this.StrTitle = i_title;
        }
 
        /// <summary>
        /// 初始化控件
        /// </summary>
        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 ■ 添加菜单___________________________
 
        /// <summary>
        /// 添加菜单行(它最终的父控件需要手动关闭)
        /// </summary>
        /// <param name="i_textValue">显示的文字</param>
        /// <param name="i_iconPath">图片(</param>
        /// <param name="i_select">是否是选择状态</param>
        /// <param name="clickEvent">单击菜单执行的事件</param>
        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;
            };
        }
 
        /// <summary>
        /// 生成行控件
        /// </summary>
        /// <param name="i_iconPath">图标</param>
        /// <param name="i_text">显示的文字</param>
        /// <param name="i_fontColor">字体颜色</param>
        /// <returns></returns>
        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
    }
}