mac
2023-09-06 bee7814dba8e033d0f36060926275b90c85c779c
HDL_ON/UI/UI2/FuntionControlView/Aks/CommonView/TypeSingleFramLayout.cs
@@ -4,34 +4,39 @@
namespace HDL_ON.UI.UI2.FuntionControlView.Aks.CommonView
{
    public class TypeSingleFramLayout : BaseFramLayout
    public class TypeSingleFramLayout
    {
        private uint UpBackgroundColor = 0x00000000;
        private uint DownBackgroundColor = 0xff454635;
        public TypeSingleFramLayout(int width, int height)
        private uint UpBackgroundColor = MusicColor.ViewColor;
        private uint DownBackgroundColor = 0xFFEFEFEF;
        /// <summary>
        /// 单个类型容器
        /// </summary>
        public FrameLayout singleFramLayout = new FrameLayout
        {
            this.Width = Application.GetRealWidth(width);
            this.Height = Application.GetRealHeight(height);
            this.Radius = (uint)Application.GetRealHeight(20);
            this.BackgroundColor = MusicColor.ViewColor;
            BackgroundColor = MusicColor.ViewColor,
            Gravity = Gravity.CenterHorizontal,
            Width = Application.GetRealWidth(101),
            Height = Application.GetRealHeight(40),
            Radius = (uint)Application.GetRealHeight(20),
        };
        }
        Button btnLeftImage = new Button
        public Button btnLeftImage = new Button
        {
            X=Application.GetRealWidth(16),
            X = Application.GetRealWidth(16),
            Width = Application.GetRealWidth(16),
            Height = Application.GetRealWidth(16),
            UnSelectedImagePath = "AksIcon/yingku.png",
            Gravity = Gravity.CenterVertical,
            Name = "btnLeftImage",
        };
        Button btnName = new Button
        public Button btnName = new Button
        {
            Width = Application.GetRealWidth(32),
            Height = Application.GetRealHeight(23),
           TextID=StringId.yingku,
            TextID = StringId.yingku,
            TextSize = TextSize.Text16,
            TextColor = MusicColor.TextColor,
            TextAlignment = TextAlignment.Center,
@@ -40,69 +45,28 @@
            Name = "btnName",
        };
        Button btnRightImage = new Button
        public Button btnRightImage = new Button
        {
            Width = Application.GetRealWidth(16),
            Height = Application.GetRealWidth(16),
            Width = Application.GetRealWidth(5),
            Height = Application.GetRealWidth(8),
            UnSelectedImagePath = "AksIcon/yingkunext.png",
            Gravity = Gravity.CenterVertical,
            Name = "btnRightImage",
        };
        public void AddBtnLeftImage()
        public void AddView(FrameLayout layout)
        {
            this.AddChidren(btnLeftImage);
        }
        public void AddBtnName(int gap = 4)
        {
            this.AddChidren(btnName);
            if (this.IsAddBtn(btnLeftImage))
            {
                btnName.X = btnLeftImage.Right + Application.GetRealWidth(gap);
            }
            //if (btnName.GetTextWidth() < btnName.Width)
            //{
            //    btnName.Width = btnName.GetTextWidth();
            //}
        }
        public void AddBtnRightImage(int gap = 8)
        {
            this.AddChidren(btnRightImage);
            if (this.IsAddBtn(btnName))
            {
                btnRightImage.X = btnName.Right + Application.GetRealWidth(gap);
                if (gap == 8)
                {
                    btnRightImage.Width = Application.GetRealWidth(5);
                    btnRightImage.Height = Application.GetRealHeight(8);
                }
            }
            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 Button GetBtnLeftImage()
        {
            return btnLeftImage;
        }
        public Button GetBtnName()
        {
            return btnName;
        }
        public Button GetBtnRightImage()
        {
            return btnRightImage;
        }
        public void SetClickUpBackgroundColor(uint backgroundColor)
        {
@@ -118,16 +82,16 @@
        /// <summary>
        /// 事件监听方法
        /// </summary>
        /// <param name="action">回调(第一个是父类对象;第二个是图标对象;第三个是状态对象</param>
        public void SetClickListener(Action<FrameLayout, Button, Button, Button> action)
        /// <param name="action">回调(第一个是父类对象;</param>
        public void SetClickListener(Action<FrameLayout> action)
        {
            EventHandler<MouseEventArgs> UpClick = (sender, e) =>
            {
                this.BackgroundColor = this.UpBackgroundColor;
                action?.Invoke(this, btnLeftImage, btnName, btnRightImage);
                //singleFramLayout.BackgroundColor = this.UpBackgroundColor;
                //弹起来还原背景颜色
            };
            this.MouseUpEventHandler += UpClick;
            singleFramLayout.MouseUpEventHandler += UpClick;
            btnLeftImage.MouseUpEventHandler += UpClick;
            btnName.MouseUpEventHandler += UpClick;
            btnRightImage.MouseUpEventHandler += UpClick;
@@ -135,45 +99,13 @@
            EventHandler<MouseEventArgs> DownClick = (sender, e) =>
            {
                //按下去改变背景颜色
                this.BackgroundColor = this.DownBackgroundColor;
                //singleFramLayout.BackgroundColor = this.DownBackgroundColor;
                action?.Invoke(singleFramLayout);
            };
            this.MouseDownEventHandler += DownClick;
            singleFramLayout.MouseDownEventHandler += DownClick;
            btnLeftImage.MouseDownEventHandler += DownClick;
            btnName.MouseDownEventHandler += DownClick;
            btnRightImage.MouseDownEventHandler += DownClick;
        }
        /// <summary>
        /// 在父布局查找子控件是否存在
        /// </summary>
        /// <param name="btn">查找对象</param>
        /// <returns>存在为true,否则为false</returns>
        private bool IsAddBtn(View btn)
        {
            if (this.ChildrenCount <= 0 || btn == null)
            {
                return false;
            }
            for (int i = 0; i < this.ChildrenCount; i++)
            {
                View view = this.GetChildren(i);
                if (view == null)
                {
                    continue;
                }
                if (view is Button)
                {
                    if (view.Name == btn.Name)
                    {
                        return true;
                    }
                }
            }
            return false;
        }
    }
}