Skip to content

Commit

Permalink
Add XNAListBoxItem.Visible property for support of hiding list box it…
Browse files Browse the repository at this point in the history
…ems without needing to remove them from the list box
  • Loading branch information
Rampastring committed Jan 29, 2024
1 parent f832ca1 commit 829ef9d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
18 changes: 17 additions & 1 deletion XNAControls/XNAListBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,10 @@ private int GetTotalLineCount()
int lineCount = 0;

foreach (XNAListBoxItem item in Items)
lineCount += item.TextLines.Count;
{
if (item.Visible)
lineCount += item.TextLines.Count;
}

return lineCount;
}
Expand Down Expand Up @@ -728,6 +731,9 @@ private void ScrollUp()

for (int i = SelectedIndex - 1; i > -1; i--)
{
if (!Items[i].Visible)
continue;

if (Items[i].Selectable)
{
SelectedIndex = i;
Expand All @@ -750,6 +756,9 @@ private void ScrollDown()
int scrollLineCount = 1;
for (int i = SelectedIndex + 1; i < Items.Count; i++)
{
if (!Items[i].Visible)
continue;

if (Items[i].Selectable)
{
SelectedIndex = i;
Expand All @@ -759,6 +768,7 @@ private void ScrollDown()
ScrollBar.RefreshButtonY(ViewTop);
return;
}

scrollLineCount++;
}

Expand Down Expand Up @@ -883,6 +893,9 @@ private int GetItemIndexOnCursor(Point mouseLocation)
{
XNAListBoxItem lbItem = Items[i];

if (!lbItem.Visible)
continue;

height += lbItem.TextLines.Count * LineHeight;

if (height > mouseLocation.Y)
Expand Down Expand Up @@ -998,6 +1011,9 @@ public override void Draw(GameTime gameTime)
{
XNAListBoxItem lbItem = Items[i];

if (!lbItem.Visible)
continue;

DrawListBoxItem(i, height);

height += lbItem.TextLines.Count * LineHeight;
Expand Down
6 changes: 6 additions & 0 deletions XNAControls/XNAListBoxItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,11 @@ public float Alpha
}
}

/// <summary>
/// Whether this list box item is visible.
/// Invisible list box items are not drawn and cannot be selected.
/// </summary>
public bool Visible { get; set; } = true;

public List<string> TextLines;
}

0 comments on commit 829ef9d

Please sign in to comment.