mac
2024-07-25 3f6685c77beeb12baf840733fb890860f4c26e7c
HDL_ON/UI/UI2/FuntionControlView/Aks/CommonView/TypeSingleFramLayout.cs
@@ -6,19 +6,32 @@
{
    public class TypeSingleFramLayout
    {
        /// <summary>
        /// 是否可以点击
        /// </summary>
        private bool mIsClick = true;
        private uint UpBackgroundColor = BaseFramLayout.unParentBackgroundColor;
        private uint DownBackgroundColor = BaseFramLayout.seleBackgroundColor;
        private uint UpBackgroundColor = MusicColor.ViewColor;
        private uint DownBackgroundColor = 0xFFEFEFEF;
        /// <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,
            //Gravity = Gravity.CenterHorizontal,
            Width = Application.GetRealWidth(101),
            Height = Application.GetRealHeight(40),
            Radius = (uint)Application.GetRealHeight(20),
            Height = Application.GetRealHeight(34),//40
            Radius = (uint)Application.GetRealHeight(17),
        };
        public Button btnLeftImage = new Button
@@ -41,7 +54,7 @@
            TextColor = MusicColor.TextColor,
            TextAlignment = TextAlignment.Center,
            Gravity = Gravity.CenterVertical,
            IsMoreLines = true,
            Padding = new Padding(0, 0, 0, 0),
            Name = "btnName",
        };
@@ -87,8 +100,9 @@
        {
            EventHandler<MouseEventArgs> UpClick = (sender, e) =>
            {
                action?.Invoke(singleFramLayout);
                //singleFramLayout.BackgroundColor = this.UpBackgroundColor;
                //弹起来还原背景颜色
            };
            singleFramLayout.MouseUpEventHandler += UpClick;
@@ -100,12 +114,70 @@
            {
                //按下去改变背景颜色
                //singleFramLayout.BackgroundColor = this.DownBackgroundColor;
                action?.Invoke(singleFramLayout);
            };
            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,
        }
    }
}