Skip to content

Commit 03a79a1

Browse files
committed
Fixed descriptions not being updated when the item is hovered
Closes #47
1 parent e57dd85 commit 03a79a1

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

LemonUI/Menus/NativeMenu.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,12 +1019,10 @@ private void UpdateItems()
10191019
// Set the position of the rectangle that marks the current item
10201020
selectedRect.Position = new PointF(pos.X, pos.Y + ((index - firstItem) * itemHeight));
10211021
// And then do the description background and text
1022-
descriptionText.Text = Items.Count == 0 || SelectedIndex == -1 ? NoItemsText : SelectedItem.Description;
10231022
float description = pos.Y + ((Items.Count > maxItems ? maxItems : Items.Count) * itemHeight) + heightDiffDescImg;
1024-
int lineCount = descriptionText.LineCount;
1025-
descriptionRect.Size = new SizeF(width, (lineCount * (descriptionText.LineHeight + 5)) + (lineCount - 1) + 10);
10261023
descriptionRect.Position = new PointF(pos.X, description);
10271024
descriptionText.Position = new PointF(pos.X + posXDescTxt, description + heightDiffDescTxt);
1025+
UpdateDescription();
10281026

10291027
// Save the size of the items
10301028
SizeF size = new SizeF(width, itemHeight);
@@ -1043,6 +1041,15 @@ private void UpdateItems()
10431041
RecalculatePanel();
10441042
}
10451043
/// <summary>
1044+
/// Updates the size and text of the description.
1045+
/// </summary>
1046+
private void UpdateDescription()
1047+
{
1048+
descriptionText.Text = Items.Count == 0 || SelectedIndex == -1 ? NoItemsText : SelectedItem.Description;
1049+
int lineCount = descriptionText.LineCount;
1050+
descriptionRect.Size = new SizeF(width, (lineCount * (descriptionText.LineHeight + 5)) + (lineCount - 1) + 10);
1051+
}
1052+
/// <summary>
10461053
/// Processes the button presses.
10471054
/// </summary>
10481055
private void ProcessControls()
@@ -1525,17 +1532,19 @@ public void Clear()
15251532
/// </summary>
15261533
public void Process()
15271534
{
1528-
// If the menu is not visible, return
15291535
if (!visible)
15301536
{
15311537
return;
15321538
}
15331539

1534-
// Otherwise, draw the elements
1540+
NativeItem selected = SelectedItem;
1541+
if (selected != null && descriptionText.Text != selected.Description)
1542+
{
1543+
UpdateDescription();
1544+
}
1545+
15351546
Draw();
1536-
// And then work on the controls
15371547
ProcessControls();
1538-
// And finish by drawing the instructional buttons
15391548
Buttons.Draw();
15401549
}
15411550
/// <summary>

LemonUI/Menus/NativeSubmenuItem.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,28 @@ public NativeSubmenuItem(NativeMenu menu, NativeMenu parent, string endlabel) :
4242

4343
#endregion
4444

45+
#region Functions
46+
47+
/// <inheritdoc/>
48+
public override void Draw()
49+
{
50+
// There is no Process(), so let's use draw to update the description
51+
if (Description != Menu.Description)
52+
{
53+
Description = Menu.Description;
54+
}
55+
56+
base.Draw();
57+
}
58+
59+
#endregion
60+
4561
#region Local Events
4662

4763
private void NativeSubmenuItem_Activated(object sender, EventArgs e)
4864
{
49-
// Try to close the parent menu
5065
Menu.Parent.Visible = false;
51-
// And show the menu only if the parent menu is closed
66+
5267
if (!Menu.Parent.Visible)
5368
{
5469
Menu.Visible = true;

0 commit comments

Comments
 (0)