Skip to content

File NativeSubmenuItem.cs

File List > LemonUI > LemonUI > Menus > NativeSubmenuItem.cs

Go to the documentation of this file


using System;

namespace LemonUI.Menus
{
    public class NativeSubmenuItem : NativeItem
    {
        #region Properties

        public NativeMenu Menu { get; }

        #endregion

        #region Constructors

        public NativeSubmenuItem(NativeMenu menu, NativeMenu parent) : this(menu, parent, ">>>")
        {
        }
        public NativeSubmenuItem(NativeMenu menu, NativeMenu parent, string endLabel) : base(menu.Name, menu.Description, endLabel)
        {
            Menu = menu ?? throw new ArgumentNullException(nameof(menu));
            Menu.Parent = parent ?? throw new ArgumentNullException(nameof(parent));

            Activated += NativeSubmenuItem_Activated;
        }

        #endregion

        #region Event Functions

        private void NativeSubmenuItem_Activated(object sender, EventArgs e)
        {
            Menu.Parent.Visible = false;

            if (!Menu.Parent.Visible)
            {
                Menu.Visible = true;
            }
        }

        #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
    }
}