Skip to content

Commit

Permalink
Merge pull request #139 from LemonUIbyLemon/feat/spacers
Browse files Browse the repository at this point in the history
Added extra features to NativeSeparatorItem
  • Loading branch information
justalemon authored Dec 16, 2023
2 parents ee5a2a6 + 9051553 commit 92dcc33
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 28 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)
else if (lastSelected && !(this is NativeSeparatorItem))
{
background.Color = Colors.BackgroundHovered;
title.Color = Colors.TitleHovered;
Expand Down
71 changes: 51 additions & 20 deletions LemonUI/Menus/NativeMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,8 +1282,13 @@ private void ProcessControls()
}

// If the cursor is inside of the selection rectangle
if (GameScreen.IsCursorInArea(item.title.Position.X - itemOffsetX, item.title.Position.Y - itemOffsetY, Width, itemHeight))
if (item.IsHovered)
{
if (item is NativeSeparatorItem)
{
return;
}

// If the item is selected, activate it
if (item == selectedItem)
{
Expand Down Expand Up @@ -1426,7 +1431,7 @@ private void Draw()
continue;
}

if (item.IsHovered && UseMouse)
if (item.IsHovered && UseMouse && !(item is NativeSeparatorItem))
{
hoveredRect.Position = item.lastPosition;
hoveredRect.Size = item.lastSize;
Expand Down Expand Up @@ -1774,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 @@ -1797,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

0 comments on commit 92dcc33

Please sign in to comment.