Skip to content

Commit

Permalink
Fixed descriptions not being updated when the item is hovered
Browse files Browse the repository at this point in the history
Closes #47
  • Loading branch information
justalemon committed Dec 4, 2021
1 parent e57dd85 commit 03a79a1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
23 changes: 16 additions & 7 deletions LemonUI/Menus/NativeMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,12 +1019,10 @@ private void UpdateItems()
// Set the position of the rectangle that marks the current item
selectedRect.Position = new PointF(pos.X, pos.Y + ((index - firstItem) * itemHeight));
// And then do the description background and text
descriptionText.Text = Items.Count == 0 || SelectedIndex == -1 ? NoItemsText : SelectedItem.Description;
float description = pos.Y + ((Items.Count > maxItems ? maxItems : Items.Count) * itemHeight) + heightDiffDescImg;
int lineCount = descriptionText.LineCount;
descriptionRect.Size = new SizeF(width, (lineCount * (descriptionText.LineHeight + 5)) + (lineCount - 1) + 10);
descriptionRect.Position = new PointF(pos.X, description);
descriptionText.Position = new PointF(pos.X + posXDescTxt, description + heightDiffDescTxt);
UpdateDescription();

// Save the size of the items
SizeF size = new SizeF(width, itemHeight);
Expand All @@ -1043,6 +1041,15 @@ private void UpdateItems()
RecalculatePanel();
}
/// <summary>
/// Updates the size and text of the description.
/// </summary>
private void UpdateDescription()
{
descriptionText.Text = Items.Count == 0 || SelectedIndex == -1 ? NoItemsText : SelectedItem.Description;
int lineCount = descriptionText.LineCount;
descriptionRect.Size = new SizeF(width, (lineCount * (descriptionText.LineHeight + 5)) + (lineCount - 1) + 10);
}
/// <summary>
/// Processes the button presses.
/// </summary>
private void ProcessControls()
Expand Down Expand Up @@ -1525,17 +1532,19 @@ public void Clear()
/// </summary>
public void Process()
{
// If the menu is not visible, return
if (!visible)
{
return;
}

// Otherwise, draw the elements
NativeItem selected = SelectedItem;
if (selected != null && descriptionText.Text != selected.Description)
{
UpdateDescription();
}

Draw();
// And then work on the controls
ProcessControls();
// And finish by drawing the instructional buttons
Buttons.Draw();
}
/// <summary>
Expand Down
19 changes: 17 additions & 2 deletions LemonUI/Menus/NativeSubmenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,28 @@ public NativeSubmenuItem(NativeMenu menu, NativeMenu parent, string endlabel) :

#endregion

#region Functions

/// <inheritdoc/>
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

#region Local Events

private void NativeSubmenuItem_Activated(object sender, EventArgs e)
{
// Try to close the parent menu
Menu.Parent.Visible = false;
// And show the menu only if the parent menu is closed

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

0 comments on commit 03a79a1

Please sign in to comment.