Skip to content

File NativeSlidableItem.cs

File List > LemonUI > LemonUI > Menus > NativeSlidableItem.cs

Go to the documentation of this file


using LemonUI.Elements;
using System;
using System.Drawing;

namespace LemonUI.Menus
{
    public abstract class NativeSlidableItem : NativeItem
    {
        #region Fields

        [Obsolete("arrowLeft is Obsolete, use LeftArrow instead.")]
        internal protected ScaledTexture arrowLeft = null;
        [Obsolete("arrowRight is Obsolete, use RightArrow instead.")]
        internal protected ScaledTexture arrowRight = null;

        private bool alwaysVisible = false;

        #endregion

        #region Properties

        public ScaledTexture LeftArrow { get; }
        public ScaledTexture RightArrow { get; }
        public bool ArrowsAlwaysVisible
        {
            get => alwaysVisible;
            set
            {
                alwaysVisible = value;
                Recalculate();
            }
        }

        #endregion

        #region Constructors

        public NativeSlidableItem(string title, string description) : base(title, description)
        {
            LeftArrow = new ScaledTexture(PointF.Empty, SizeF.Empty, "commonmenu", "arrowleft");
            RightArrow = new ScaledTexture(PointF.Empty, SizeF.Empty, "commonmenu", "arrowright");
#pragma warning disable CS0618
            arrowLeft = LeftArrow;
            arrowRight = RightArrow;
#pragma warning restore CS0618
            EnabledChanged += NativeSlidableItem_EnabledChanged;
        }

        #endregion

        #region Tools

        private void NativeSlidableItem_EnabledChanged(object sender, EventArgs e) => Recalculate();

        #endregion

        #region Functions

        public override void Recalculate(PointF pos, SizeF size, bool selected)
        {
            base.Recalculate(pos, size, selected);

            LeftArrow.Size = (selected && Enabled) || ArrowsAlwaysVisible ? new SizeF(30, 30) : SizeF.Empty;
            RightArrow.Size = (selected && Enabled) || ArrowsAlwaysVisible ? new SizeF(30, 30) : SizeF.Empty;

            RightArrow.Position = new PointF(pos.X + size.Width - RightArrow.Size.Width - 5, pos.Y + 4);
        }
        public abstract void GoLeft();
        public abstract void GoRight();
        public override void Draw()
        {
            title.Draw();
            badgeLeft?.Draw();
            LeftArrow.Draw();
            RightArrow.Draw();
        }
        public override void UpdateColors()
        {
            base.UpdateColors();

            if (!Enabled)
            {
                LeftArrow.Color = Colors.ArrowsDisabled;
                RightArrow.Color = Colors.ArrowsDisabled;
            }
            else if (lastSelected)
            {
                LeftArrow.Color = Colors.ArrowsHovered;
                RightArrow.Color = Colors.ArrowsHovered;
            }
            else
            {
                LeftArrow.Color = Colors.ArrowsNormal;
                RightArrow.Color = Colors.ArrowsNormal;
            }
        }

        #endregion
    }
}