wxr
2024-11-01 c0c734d7a84cf7105401878ffc4b64cbb67621d1
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using HDL_ON.UI.Music;
using System;
using Shared;
 
namespace HDL_ON.UI.UI2.FuntionControlView.Aks.CommonView
{
    public class TypeSingleFramLayout
    {
        /// <summary>
        /// 是否可以点击
        /// </summary>
        private bool mIsClick = true;
        private uint UpBackgroundColor = BaseFramLayout.unParentBackgroundColor;
        private uint DownBackgroundColor = BaseFramLayout.seleBackgroundColor;
 
        /// <summary>
        /// 设置控制点击事件
        /// </summary>
        /// <param name="isClick">false点击无效</param>
        public void setClick(bool isClick)
        {
            this.mIsClick = isClick;
        }
       
        /// <summary>
        /// 单个类型容器
        /// </summary>
        public FrameLayout singleFramLayout = new FrameLayout
        {
            BackgroundColor = MusicColor.ViewColor,
            //Gravity = Gravity.CenterHorizontal,
            Width = Application.GetRealWidth(101),
            Height = Application.GetRealHeight(34),//40
            Radius = (uint)Application.GetRealHeight(17),
        };
 
        public Button btnLeftImage = new Button
        {
            X = Application.GetRealWidth(16),
            Width = Application.GetRealWidth(16),
            Height = Application.GetRealWidth(16),
            UnSelectedImagePath = "AksIcon/yingku.png",
            Gravity = Gravity.CenterVertical,
            Name = "btnLeftImage",
        };
 
        public Button btnName = new Button
        {
 
            Width = Application.GetRealWidth(32),
            Height = Application.GetRealHeight(23),
            TextID = StringId.yingku,
            TextSize = TextSize.Text16,
            TextColor = MusicColor.TextColor,
            TextAlignment = TextAlignment.Center,
            Gravity = Gravity.CenterVertical,
            Padding = new Padding(0, 0, 0, 0),
            Name = "btnName",
        };
 
        public Button btnRightImage = new Button
        {
 
            Width = Application.GetRealWidth(5),
            Height = Application.GetRealWidth(8),
            UnSelectedImagePath = "AksIcon/yingkunext.png",
            Gravity = Gravity.CenterVertical,
            Name = "btnRightImage",
        };
 
 
        public void AddView(FrameLayout layout)
        {
            layout.AddChidren(singleFramLayout);
            singleFramLayout.AddChidren(btnLeftImage);
            singleFramLayout.AddChidren(btnName);
            singleFramLayout.AddChidren(btnRightImage);
            btnName.X = btnLeftImage.Right + Application.GetRealWidth(4);
            btnRightImage.X = btnName.Right + Application.GetRealWidth(8);
        }
 
 
 
        public void SetClickUpBackgroundColor(uint backgroundColor)
        {
            this.UpBackgroundColor = backgroundColor;
 
        }
 
        public void SetClickDownBackgroundColor(uint backgroundColor)
        {
            this.DownBackgroundColor = backgroundColor;
        }
 
        /// <summary>
        /// 事件监听方法
        /// </summary>
        /// <param name="action">回调(第一个是父类对象;</param>
        public void SetClickListener(Action<FrameLayout> action)
        {
            EventHandler<MouseEventArgs> UpClick = (sender, e) =>
            {
                action?.Invoke(singleFramLayout);
                //singleFramLayout.BackgroundColor = this.UpBackgroundColor;
 
                //弹起来还原背景颜色
            };
            singleFramLayout.MouseUpEventHandler += UpClick;
            btnLeftImage.MouseUpEventHandler += UpClick;
            btnName.MouseUpEventHandler += UpClick;
            btnRightImage.MouseUpEventHandler += UpClick;
 
            EventHandler<MouseEventArgs> DownClick = (sender, e) =>
            {
                //按下去改变背景颜色
                //singleFramLayout.BackgroundColor = this.DownBackgroundColor;
 
            };
            singleFramLayout.MouseDownEventHandler += DownClick;
            btnLeftImage.MouseDownEventHandler += DownClick;
            btnName.MouseDownEventHandler += DownClick;
            btnRightImage.MouseDownEventHandler += DownClick;
        }
 
 
        /// <summary>
        /// 自动计算控件长度
        /// </summary>
        /// <param name="orientation">位置(左或右)</param>
        /// <param name="frame">父容器</param>
        /// <param name="btnName">备注控件</param>
        /// <param name="btnImage">图标备注控件</param>
        /// <param name="btnNameWidth">备注控件宽度</param>
        /// <param name="btnNameWidthMaxValue">备注控件宽度最大值</param> 
        /// <param name="parentDefaultWidthMaxValue">父控件宽度默认最大值</param>
        public void CustomCalculationWidth(Orientation orientation, FrameLayout frame, Button btnName, Button btnImage, int btnNameWidth,int btnNameWidthMaxValue = 110, int parentDefaultWidthMaxValue = 101)
        {
 
            int parentRightX = 226;
            int parentLeftX = 16;
 
 
            if (btnName.GetTextWidth() > Application.GetRealWidth(btnNameWidth))
            {
                frame.Width = Application.GetRealWidth(parentDefaultWidthMaxValue - btnNameWidth) + btnName.GetTextWidth();
                if (orientation == Orientation.right)
                {
                    frame.X = Application.GetRealWidth(parentRightX + btnNameWidth) - btnName.GetTextWidth();
                }
                else if (orientation == Orientation.left)
                {
                    frame.X = Application.GetRealWidth(parentLeftX);
                }
                btnName.Width = btnName.GetTextWidth();
                btnImage.X = btnName.Right + Application.GetRealWidth(8);
            }
 
            if (btnName.GetTextWidth() > Application.GetRealWidth(btnNameWidthMaxValue))
            {
 
                btnName.Width = Application.GetRealWidth(btnNameWidthMaxValue);
                if (orientation == Orientation.right)
                {
                    frame.X =Application.GetRealWidth(parentRightX+ btnNameWidth) - btnName.Width;
                }
                else if (orientation == Orientation.left)
                {
                    frame.X = Application.GetRealWidth(parentLeftX);
                }
                frame.Width = Application.GetRealWidth(parentDefaultWidthMaxValue - btnNameWidth) + btnName.Width;
                btnImage.X = btnName.Right + Application.GetRealWidth(8);
            }
 
        }
 
        public enum Orientation
        {
            left,
            right,
 
        }
    }
}