using System;
namespace LemonUI.Menus
{
///
/// Item used for opening submenus.
///
public class NativeSubmenuItem : NativeItem
{
#region Public Properties
///
/// The menu opened by this item.
///
public NativeMenu Menu { get; }
#endregion
#region Constructors
///
/// Creates a new Item that opens a Submenu.
///
/// The menu that this item will open.
/// The parent menu where this item will be located.
public NativeSubmenuItem(NativeMenu menu, NativeMenu parent) : this(menu, parent, ">>>")
{
}
///
/// Creates a new Item that opens a Submenu.
///
/// The menu that this item will open.
/// The parent menu where this item will be located.
/// The alternative title of the item, shown on the right.
public NativeSubmenuItem(NativeMenu menu, NativeMenu parent, string endlabel) : base(menu.Subtitle, menu.Description, endlabel)
{
Menu = menu ?? throw new ArgumentNullException(nameof(menu));
Menu.Parent = parent ?? throw new ArgumentNullException(nameof(parent));
Activated += NativeSubmenuItem_Activated;
}
#endregion
#region Functions
///
public override void Draw()
{
// There is no Process(), so let's use draw to update the description
if (Description != Menu.Description)
{
Description = Menu.Description;
}
base.Draw();
}
#endregion
#region Local Events
private void NativeSubmenuItem_Activated(object sender, EventArgs e)
{
Menu.Parent.Visible = false;
if (!Menu.Parent.Visible)
{
Menu.Visible = true;
}
}
#endregion
}
}