tzy
2021-05-14 0fa1534827bd21d763216550d11006fc1441c6cb
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
using Shared;
using HDL_ON.UI.CSS;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace HDL_ON.Stan
{
    /// <summary>
    /// 底部弹窗的菜单选择控件(不需要加入父控件,AddMenu添加菜单)
    /// </summary>
    public class BottomMenuSelectControl
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 菜单高度
        /// </summary>
        private int menuHeight = Application.GetRealHeight(44);
        /// <summary>
        /// 菜单桌布控件
        /// </summary>
        private FrameLayout frameMenuTable = null;
        /// <summary>
        /// 整个弹窗对象
        /// </summary>
        private Dialog FrameDialog = null;
        /// <summary>
        /// 点击背景时,是否关闭弹窗
        /// </summary>
        public bool ClickBackClose = true;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 底部弹窗的菜单选择控件(不需要加入父控件,AddMenu添加菜单)
        /// </summary>
        /// <param name="i_menuCount">菜单总数(不含取消菜单)</param>
        public BottomMenuSelectControl(int i_menuCount)
        {
            //初始化控件
            this.InitControl(i_menuCount);
        }
 
        /// <summary>
        /// 初始化控件
        /// </summary>
        /// <param name="menuCount">菜单总数(不含取消菜单)</param>
        private void InitControl(int menuCount)
        {
            //整个灰色界面
            this.FrameDialog = new Dialog();
            FrameDialog.Show();
 
            var dialogBody = new NormalFrameLayout();
            dialogBody.Height = FrameDialog.Height;
            FrameDialog.AddChidren(dialogBody);
            dialogBody.ButtonClickEvent += (sender, e) =>
            {
                if (ClickBackClose == true)
                {
                    FrameDialog.Close();
                }
            };
 
            //取消菜单
            var frameCancel = new FrameLayout();
            frameCancel.Y = dialogBody.Height - this.menuHeight - Application.GetRealHeight(12);
            frameCancel.Gravity = Gravity.CenterHorizontal;
            frameCancel.Radius = (uint)Application.GetRealHeight(12);
            frameCancel.Width = Application.GetRealWidth(343);
            frameCancel.Height = this.menuHeight;
            frameCancel.BackgroundColor = CSS_Color.MainBackgroundColor;
            FrameDialog.AddChidren(frameCancel);
            var btnCancel = new NormalViewControl(Application.GetRealWidth(150), this.menuHeight, false);
            btnCancel.Gravity = Gravity.Center;
            btnCancel.TextAlignment = TextAlignment.Center;
            btnCancel.TextColor = CSS_Color.AuxiliaryColor2;
            btnCancel.TextSize = CSS_FontSize.SubheadingFontSize;
            btnCancel.TextID = StringId.Cancel;
            frameCancel.AddChidren(btnCancel);
            btnCancel.ButtonClickEvent += (sender, e) =>
            {
                //关闭界面
                FrameDialog.Close();
            };
 
            //菜单的桌布控件
            int framebackHeight = this.menuHeight * menuCount;
            this.frameMenuTable = new FrameLayout();
            frameMenuTable.Y = frameCancel.Y - framebackHeight - Application.GetRealHeight(8);
            frameMenuTable.Height = framebackHeight;
            frameMenuTable.Width = Application.GetRealWidth(343);
            frameMenuTable.Gravity = Gravity.CenterHorizontal;
            frameMenuTable.BackgroundColor = CSS_Color.MainBackgroundColor;
            frameMenuTable.Radius = (uint)Application.GetRealWidth(12);
            FrameDialog.AddChidren(frameMenuTable);
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 添加菜单
        /// </summary>
        /// <param name="strMenu">菜单文本</param>
        /// <param name="selectEvent">菜单选择的事件</param>
        /// <param name="textColor">文本颜色(设置为0,则使用默认的蓝色字体)</param>
        /// <param name="clickClose">菜单点击时,是否无条件关闭界面</param>
        public void AddMenu(string strMenu, Action selectEvent, uint textColor = 0, bool clickClose = true)
        {
            //线
            if (this.frameMenuTable.ChildrenCount > 0)
            {
                var btnLine = new NormalViewControl(frameMenuTable.Width, HdlControlResourse.BottomLineHeight, false);
                btnLine.BackgroundColor = CSS_Color.DividingLineColor;
                btnLine.Y = this.frameMenuTable.GetChildren(this.frameMenuTable.ChildrenCount - 1).Bottom;
                this.frameMenuTable.AddChidren(btnLine);
            }
 
            //菜单
            var btnMenu = new NormalViewControl(Application.GetRealWidth(300), this.menuHeight, false);
            if (this.frameMenuTable.ChildrenCount > 0)
            {
                btnMenu.Y = this.frameMenuTable.GetChildren(this.frameMenuTable.ChildrenCount - 1).Bottom;
            }
            btnMenu.Gravity = Gravity.CenterHorizontal;
            btnMenu.TextAlignment = TextAlignment.Center;
            btnMenu.TextColor = textColor == 0 ? CSS_Color.MainColor : textColor;
            btnMenu.TextSize = CSS_FontSize.SubheadingFontSize;
            btnMenu.Text = strMenu;
            this.frameMenuTable.AddChidren(btnMenu);
            btnMenu.ButtonClickEvent += (sender, e) =>
            {
                if (clickClose == true)
                {
                    //关闭界面
                    FrameDialog.Close();
                }
                selectEvent?.Invoke();
                selectEvent = null;
            };
        }
 
        #endregion
    }
}