wjc
2023-08-10 ff423b88a0dc521932305b5bd44b1786d3e42722
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
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.ViewColor,
                    BackgroundColor = 0x00000000,
                    Text = mList[i].filterName,
                    TextSize = TextSize.Text14,
                    TextColor = MusicColor.TextColor,
                    SelectedTextColor = MusicColor.MusicTxet14SelectedColor,
                    TextAlignment = TextAlignment.Center,
                    Padding = new Padding(4, 4, 4, 4),
                    Radius = (uint)Application.GetRealHeight(4),
                    Tag = filters,
                };
 
                //重新计算组件宽度
                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) =>
                {
                    btnSelected.IsSelected = false;
                    button.IsSelected = true;
                    btnSelected = button;
                    if (button.Tag == null || !(button.Tag is Filters))
                    {
                        return;
                    }
                    SelectTypeEvent?.Invoke((Filters)button.Tag);
 
                };
                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();
        }
 
    }
}