using LemonUI.Elements; using System; using System.Drawing; namespace LemonUI.Menus { /// /// Basic elements for a slidable item. /// public abstract class NativeSlidableItem : NativeItem { #region Private Fields private bool alwaysVisible = false; #endregion #region Internal Fields /// /// The arrow pointing to the Left. /// [Obsolete("arrowLeft is Obsolete, use LeftArrow instead.")] internal protected ScaledTexture arrowLeft = null; /// /// The arrow pointing to the Right. /// [Obsolete("arrowRight is Obsolete, use RightArrow instead.")] internal protected ScaledTexture arrowRight = null; #endregion #region Public Properties /// /// The arrow pointing to the Left. /// public ScaledTexture LeftArrow { get; } /// /// The arrow pointing to the Right. /// public ScaledTexture RightArrow { get; } /// /// Whether the arrows should always be shown regardless of the visibility of the Item. /// public bool ArrowsAlwaysVisible { get => alwaysVisible; set { alwaysVisible = value; Recalculate(); } } #endregion #region Constructors /// /// Creates a new item that can be sliden. /// /// The title of the Item. /// The description of the Item. 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 Local Events private void NativeSlidableItem_EnabledChanged(object sender, EventArgs e) => Recalculate(); #endregion #region Public Functions /// /// Recalculates the item positions and sizes with the specified values. /// /// The position of the item. /// The size of the item. /// If this item has been selected. 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); } /// /// Moves to the previous item. /// public abstract void GoLeft(); /// /// Moves to the next item. /// public abstract void GoRight(); /// /// Draws the left and right arrow. /// 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 } }