mac
2023-08-30 f17556d2ee4ade808f776653286690ab235463d5
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
using System;
using Shared;
using HDL_ON.UI.Music;
using System.Collections.Generic;
using HDL_ON.UI.UI2.FuntionControlView.Aks.Entity;
 
namespace HDL_ON.UI.UI2.FuntionControlView.Aks.CommonView
{
    /// <summary>
    /// 水平滑动容器
    /// </summary>
    public class HorizontalFramLayout : HorizontalScrolViewLayout
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="width">容器宽度</param>
        /// <param name="height">容器高度</param>
        public HorizontalFramLayout(int width, int height)
        {
            this.Height = Application.GetRealHeight(height);
            this.Width = Application.GetRealWidth(width);
        }
 
        /// <summary>
        /// 选择事件
        /// </summary>
        public Action<Filters> SelectTypeEvent = null;
 
        /// <summary>
        /// 初始化控件
        /// </summary>
        /// <param name="mList">显示数据列表</param>
        /// <param name="defaultIndex">默认值索引范围[0,mList.count-1],大于范围,该值视为无效</param>
        public void InitControl(List<Filters> mList, int defaultIndex = -1)
        {
            if (mList == null || mList.Count == 0)
            {
                return;
            }
            bool isBool = false;
            Button btnSelected = new Button();
            for (int i = 0; i < mList.Count; i++)
            {
 
                var filters = mList[i];
                Button button = new Button
                {
                    Height = Application.GetRealHeight(28),
                    Width = Application.GetRealWidth(20),
                    SelectedBackgroundColor = MusicColor.MusicTxet14SelectedColor,
                    BackgroundColor = 0x00000000,
                    Text = mList[i].filterName,
                    TextSize = TextSize.Text14,
                    TextColor = MusicColor.TextColor,
                    SelectedTextColor = MusicColor.WhiteColor,
                    TextAlignment = TextAlignment.Center,
                    Padding = new Padding(4, 4, 4, 4),
                    Radius = (uint)Application.GetRealHeight(4),
                    Tag = filters,
                    Name = i.ToString(),
                };
 
                //重新计算组件宽度
                button.Width = button.GetTextWidth() + Application.GetRealWidth(4 + 4);
                this.AddChidren(button);
                //间隔,弄个空的进去占位置
                Button btnSpacing = new Button
                {
                    Height = Application.GetRealHeight(28),
                    Width = Application.GetRealWidth(20),
                    BackgroundColor = 0x00000000,
                };
                this.AddChidren(btnSpacing);
                button.MouseDownEventHandler += (sen, e) =>
                {
                    if (btnSelected.Name == button.Name)
                    {
                        //点击同一个组件无效
                        return;
                    }
                    btnSelected.IsSelected = false;
                    button.IsSelected = true;
                    btnSelected = button;
                    if (button.Tag == null || !(button.Tag is Filters))
                    {
                        return;
                    }
                    var filtersSelected = (Filters)button.Tag;
 
                    SelectTypeEvent?.Invoke(filtersSelected);
 
                };
                if (defaultIndex != -1 && defaultIndex == i)
                {
                    btnSelected.IsSelected = false;
                    button.IsSelected = true;
                    btnSelected = button;
                    isBool = true;
                }
            }
 
            if (isBool)
            {
                if (defaultIndex < mList.Count)
                {
                    //默认索引回调,初始化时执行
                    SelectTypeEvent?.Invoke(mList[defaultIndex]);
                }
 
            }
 
        }
 
 
 
 
 
        /// <summary>
        /// 控件摧毁
        /// </summary>
        public override void RemoveFromParent()
        {
            this.SelectTypeEvent = null;
            base.RemoveFromParent();
        }
 
    }
}