陈嘉乐
2020-06-24 adb12dcdbb2ddaeac687c3aa9e57bb7ed459ab7e
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/CompoundControls/SceneFunctionSwitchControl.cs
@@ -8,7 +8,7 @@
    /// <para>场景和功能之间相互切换的Tab控件(完成初始化后,会根据默认选择调用回调函数)</para>
    /// <para>2020.03.10变更:它变更为文字型菜单控件</para>
    /// </summary>
    public class SceneFunctionSwitchControl : FrameLayout
    public class SceneFunctionSwitchControl : HorizontalScrolViewLayout
    {
        #region ■ 变量声明___________________________
@@ -16,6 +16,10 @@
        /// 选择事件(从0开始)
        /// </summary>
        public Action<int> SelectTabEvent = null;
        /// <summary>
        /// 前回选择的索引
        /// </summary>
        public int OldSelectIndex = 0;
        private int m_nowSelectIndex = 0;
        /// <summary>
@@ -49,43 +53,57 @@
        public SceneFunctionSwitchControl()
        {
            this.Height = Application.GetRealHeight(90);
            this.Y = Application.GetRealHeight(40);
        }
        /// <summary>
        ///  初始化控件(事件要至于它之前)
        /// </summary>
        /// <param name="listTitleText">菜单文字列表</param>
        public void InitControl(List<string> listTitleText)
        /// <param name="rightSpace">右边空白宽度</param>
        public void InitControl(List<string> listTitleText, int rightSpace = 0)
        {
            if (listTitleText.Count == 0) { return; }
            this.listNameControl.Clear();
            this.listLineControl.Clear();
            var btnTemp = new NormalViewControl(10, 10, false);
            btnTemp.TextSize = 16;
            //做成头部菜单文字
            int XX = 0;
            for (int i = 0; i < listTitleText.Count; i++)
            {
                btnTemp.Text = listTitleText[i];
                //开始初始化
                XX = this.InitTitleTextControl(i, listTitleText[i], btnTemp.GetRealWidthByText(), XX);
                //添加标题控件
                this.AddTitleTextControl(i, listTitleText[i], btnTemp.GetRealWidthByText());
            }
            //添加右边空白宽度
            if (rightSpace > 0)
            {
                //添加一个间隔间距
                var frameSpace = new FrameLayout();
                frameSpace.Width = Application.GetRealWidth(rightSpace);
                this.AddChidren(frameSpace);
            }
            //回调方法
            this.frameDefult.ButtonClickEvent?.Invoke(null, null);
        }
        /// <summary>
        /// 初始化标题控件
        /// 添加标题控件
        /// </summary>
        /// <param name="i_index"></param>
        /// <param name="titleText"></param>
        private int InitTitleTextControl(int i_index, string titleText, int realWidth, int XX)
        private void AddTitleTextControl(int i_index, string titleText, int realWidth)
        {
            //添加一个间隔间距
            var frameSpace = new FrameLayout();
            frameSpace.Width = Application.GetRealWidth(58);
            this.AddChidren(frameSpace);
            //场景框(点击范围有点小,需要扩大它的点击范围)
            var frameBack = new FrameLayoutStatuControl();
            frameBack.UseClickStatu = false;
            frameBack.Height = Application.GetRealHeight(90);
            frameBack.Width = realWidth;
            frameBack.X = XX + Application.GetRealWidth(58);
            this.AddChidren(frameBack);
            //名称
            var btnName = new NormalViewControl(frameBack.Width, Application.GetRealHeight(63), false);
@@ -103,17 +121,17 @@
            {
                btnName.TextColor = UserCenterColor.Current.TextGrayColor3;
            }
            frameBack.AddChidren(btnName, ChidrenBindMode.BindEventOnly);
            frameBack.AddChidren(btnName, ChidrenBindMode.BindEvent);
            //添加缓存
            this.listNameControl.Add(btnName);
            //底线
            var btnLine = new NormalViewControl(40, 10, true);
            btnLine.Y = btnName.Bottom + Application.GetRealHeight(14);
            btnLine.Y = btnName.Bottom + Application.GetRealHeight(6);
            btnLine.X = btnName.X + btnName.Width / 2 - Application.GetRealWidth(40) / 2;
            btnLine.Radius = (uint)Application.GetRealHeight(10) / 2;
            btnLine.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
            frameBack.AddChidren(btnLine, ChidrenBindMode.BindEventOnly);
            frameBack.AddChidren(btnLine, ChidrenBindMode.BindEvent);
            if (m_nowSelectIndex != i_index)
            {
                btnLine.Visible = false;
@@ -129,6 +147,7 @@
                    //手动点击的才处理
                    return;
                }
                this.OldSelectIndex = this.m_nowSelectIndex;
                this.m_nowSelectIndex = i_index;
                //当前文字变色
                btnName.TextSize = 16;
@@ -150,9 +169,6 @@
                }
                this.SelectTabEvent?.Invoke(i_index);
            };
            //返回这个控件的右坐标
            return frameBack.Right;
        }
        #endregion
@@ -174,11 +190,21 @@
        #region ■ 一般方法___________________________
        /// <summary>
        /// 设置初始选择(请在初始化完成之前调用)
        /// 设置初始选择
        /// </summary>
        /// <param name="index">从0开始</param>
        public void SetDefultIndex(int index)
        {
            if (frameDefult != null && frameDefult.Parent != null)
            {
                if (index < this.listNameControl.Count)
                {
                    this.ScrollToViewIndex(index * 2 + 1);
                    //调用点击事件
                    this.listNameControl[index].ButtonClickEvent(null, null);
                }
                return;
            }
            this.m_nowSelectIndex = index;
        }