Skip to content

Commit

Permalink
Merge the features of NativeSpacerItem into NativeSeparatorItem
Browse files Browse the repository at this point in the history
  • Loading branch information
justalemon committed Dec 16, 2023
1 parent 436cfca commit 9051553
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 81 deletions.
2 changes: 1 addition & 1 deletion LemonUI/Menus/NativeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public virtual void UpdateColors()
badgeRight.Color = Colors.BadgeRightDisabled;
}
}
else if (lastSelected && !(this is NativeSpacerItem))
else if (lastSelected && !(this is NativeSeparatorItem))
{
background.Color = Colors.BackgroundHovered;
title.Color = Colors.TitleHovered;
Expand Down
66 changes: 46 additions & 20 deletions LemonUI/Menus/NativeMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ private void ProcessControls()
// If the cursor is inside of the selection rectangle
if (item.IsHovered)
{
if (item is NativeSpacerItem)
if (item is NativeSeparatorItem)
{
return;
}
Expand Down Expand Up @@ -1431,7 +1431,7 @@ private void Draw()
continue;
}

if (item.IsHovered && UseMouse && !(item is NativeSpacerItem))
if (item.IsHovered && UseMouse && !(item is NativeSeparatorItem))
{
hoveredRect.Position = item.lastPosition;
hoveredRect.Size = item.lastSize;
Expand Down Expand Up @@ -1779,21 +1779,34 @@ public void Back()
/// </summary>
public void Previous()
{
// If there are no items, return
if (Items.Count == 0)
{
return;
}

// If we are on the first item, go back to the last one
if (SelectedIndex <= 0)
{
SelectedIndex = Items.Count - 1;
}
// Otherwise, reduce it by one
else
int nextIndex = SelectedIndex;

while (true)
{
SelectedIndex -= 1;
nextIndex -= 1;

if (nextIndex < 0)
{
nextIndex = Items.Count - 1;
}

if (Items[nextIndex] is NativeSeparatorItem)
{
continue;
}

if (nextIndex == SelectedIndex)
{
return;
}

SelectedIndex = nextIndex;
return;
}
}
/// <summary>
Expand All @@ -1802,21 +1815,34 @@ public void Previous()
/// </summary>
public void Next()
{
// If there are no items, return
if (Items.Count == 0)
{
return;
}

// If we are on the last item, go back to the first one
if (Items.Count - 1 == SelectedIndex)
{
SelectedIndex = 0;
}
// Otherwise, increase it by one
else
int nextIndex = SelectedIndex;

while (true)
{
SelectedIndex += 1;
nextIndex += 1;

if (nextIndex >= Items.Count)
{
nextIndex = 0;
}

if (Items[nextIndex] is NativeSeparatorItem)
{
continue;
}

if (nextIndex == SelectedIndex)
{
return;
}

SelectedIndex = nextIndex;
return;
}
}

Expand Down
37 changes: 30 additions & 7 deletions LemonUI/Menus/NativeSeparatorItem.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@
namespace LemonUI.Menus
#if FIVEM
using CitizenFX.Core.UI;
#elif RAGEMP
using RAGE.Game;
#elif SHVDN3 || SHVDNC
using GTA.UI;
#endif
using System.Drawing;

namespace LemonUI.Menus
{
/// <summary>
/// A Blank Separator Item for creating empty spaces between menu items.
/// An item used to have a space between the items with text or no text.
/// </summary>
public class NativeSeparatorItem : NativeItem
{
#region Constructors

/// <summary>
/// Creates a new Menu Separator.
/// Creates a new separator.
/// </summary>
public NativeSeparatorItem() : this(string.Empty)
{
}
/// <summary>
/// Creates a new separator with a specific title.
/// </summary>
public NativeSeparatorItem() : base(string.Empty, string.Empty, string.Empty)
/// <param name="title">The title of the item.</param>
public NativeSeparatorItem(string title) : base(title, string.Empty, string.Empty)
{
this.title.Alignment = Alignment.Center;
}

#endregion

#region Functions

/// <summary>
/// Draws nothing.
/// </summary>
/// <inheritdoc/>
public override void Recalculate(PointF pos, SizeF size, bool selected)
{
base.Recalculate(pos, size, selected);

title.Position = new PointF(pos.X + (size.Width * 0.5f), title.Position.Y);
}
/// <inheritdoc/>
public override void Draw()
{
title.Draw();
}

#endregion
Expand Down
53 changes: 0 additions & 53 deletions LemonUI/Menus/NativeSpacerItem.cs

This file was deleted.

0 comments on commit 9051553

Please sign in to comment.