using Shared;
using HDL_ON.UI.CSS;
using System;
using System.Collections.Generic;
using System.Text;
namespace HDL_ON.Stan
{
///
/// 底部弹窗的菜单选择控件(不需要加入父控件,AddMenu添加菜单)
///
public class BottomMenuSelectControl
{
#region ■ 变量声明___________________________
///
/// 菜单高度
///
private int menuHeight = Application.GetRealHeight(44);
///
/// 菜单桌布控件
///
private FrameLayout frameMenuTable = null;
///
/// 整个弹窗对象
///
private Dialog FrameDialog = null;
///
/// 点击背景时,是否关闭弹窗
///
public bool ClickBackClose = true;
#endregion
#region ■ 初始化_____________________________
///
/// 底部弹窗的菜单选择控件(不需要加入父控件,AddMenu添加菜单)
///
/// 菜单总数(不含取消菜单)
public BottomMenuSelectControl(int i_menuCount)
{
//初始化控件
this.InitControl(i_menuCount);
}
///
/// 初始化控件
///
/// 菜单总数(不含取消菜单)
private void InitControl(int menuCount)
{
//整个灰色界面
this.FrameDialog = new Dialog();
FrameDialog.Show();
var dialogBody = new NormalFrameLayout();
dialogBody.Height = FrameDialog.Height;
FrameDialog.AddChidren(dialogBody);
dialogBody.ButtonClickEvent += (sender, e) =>
{
if (ClickBackClose == true)
{
FrameDialog.Close();
}
};
//取消菜单
var frameCancel = new FrameLayout();
frameCancel.Y = dialogBody.Height - this.menuHeight - Application.GetRealHeight(12);
frameCancel.Gravity = Gravity.CenterHorizontal;
frameCancel.Radius = (uint)Application.GetRealHeight(12);
frameCancel.Width = Application.GetRealWidth(343);
frameCancel.Height = this.menuHeight;
frameCancel.BackgroundColor = CSS_Color.MainBackgroundColor;
FrameDialog.AddChidren(frameCancel);
var btnCancel = new NormalViewControl(Application.GetRealWidth(150), this.menuHeight, false);
btnCancel.Gravity = Gravity.Center;
btnCancel.TextAlignment = TextAlignment.Center;
btnCancel.TextColor = CSS_Color.AuxiliaryColor2;
btnCancel.TextSize = CSS_FontSize.SubheadingFontSize;
btnCancel.TextID = StringId.Cancel;
frameCancel.AddChidren(btnCancel);
btnCancel.ButtonClickEvent += (sender, e) =>
{
//关闭界面
FrameDialog.Close();
};
//菜单的桌布控件
int framebackHeight = this.menuHeight * menuCount;
this.frameMenuTable = new FrameLayout();
frameMenuTable.Y = frameCancel.Y - framebackHeight - Application.GetRealHeight(8);
frameMenuTable.Height = framebackHeight;
frameMenuTable.Width = Application.GetRealWidth(343);
frameMenuTable.Gravity = Gravity.CenterHorizontal;
frameMenuTable.BackgroundColor = CSS_Color.MainBackgroundColor;
frameMenuTable.Radius = (uint)Application.GetRealWidth(12);
FrameDialog.AddChidren(frameMenuTable);
}
#endregion
#region ■ 一般方法___________________________
///
/// 添加菜单
///
/// 菜单文本
/// 菜单选择的事件
/// 文本颜色(设置为0,则使用默认的蓝色字体)
/// 菜单点击时,是否无条件关闭界面
public void AddMenu(string strMenu, Action selectEvent, uint textColor = 0, bool clickClose = true)
{
//线
if (this.frameMenuTable.ChildrenCount > 0)
{
var btnLine = new NormalViewControl(frameMenuTable.Width, HdlControlResourse.BottomLineHeight, false);
btnLine.BackgroundColor = CSS_Color.DividingLineColor;
btnLine.Y = this.frameMenuTable.GetChildren(this.frameMenuTable.ChildrenCount - 1).Bottom;
this.frameMenuTable.AddChidren(btnLine);
}
//菜单
var btnMenu = new NormalViewControl(Application.GetRealWidth(300), this.menuHeight, false);
if (this.frameMenuTable.ChildrenCount > 0)
{
btnMenu.Y = this.frameMenuTable.GetChildren(this.frameMenuTable.ChildrenCount - 1).Bottom;
}
btnMenu.Gravity = Gravity.CenterHorizontal;
btnMenu.TextAlignment = TextAlignment.Center;
btnMenu.TextColor = textColor == 0 ? CSS_Color.MainColor : textColor;
btnMenu.TextSize = CSS_FontSize.SubheadingFontSize;
btnMenu.Text = strMenu;
this.frameMenuTable.AddChidren(btnMenu);
btnMenu.ButtonClickEvent += (sender, e) =>
{
if (clickClose == true)
{
//关闭界面
FrameDialog.Close();
}
selectEvent?.Invoke();
selectEvent = null;
};
}
#endregion
}
}