Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: eri0o on Sat 10/08/2019 15:11:00

Title: [SOLVED] How to get ItemCount of shown items in a ListBox ?
Post by: eri0o on Sat 10/08/2019 15:11:00
ItemCount gives me the total items in a ListBox, RowCount gives me total number of rows in a ListBox. But ListBoxes can be scrolled. Is there a way to get the number of items actually shown in a ListBox ?
Title: Re: How to get ItemCount of shown items in a ListBox ?
Post by: Crimson Wizard on Sat 10/08/2019 15:17:53
RowCount gives number of visible rows.
Title: Re: How to get ItemCount of shown items in a ListBox ?
Post by: eri0o on Sat 10/08/2019 15:23:50
Manual is wrong again then it's not, you and I are saying the same thing with different wording:

https://github.com/adventuregamestudio/ags-manual/wiki/ListBox#rowcount

QuoteRowCount
readonly int ListBox.RowCount
Gets the number of rows that can be shown within the list box. This depends on the size of the list box, and does not depend on how many items are actually stored in the list box.

This property is read-only. To change the row count, adjust the height of the list box.

Example:

Display("You can currently see %d items from the listbox's contents", lstSaveGames.RowCount);
will display the number of rows that the listbox can display.

Edit: I did another test. I get the functionality described in the manual but I get a 0 on the first room load. Wait, now I see you and I talked about the same thing. The manual is correct.

Still, I don't know how to know if the page is scrolled.

Edit2:
Code (ags) Select

_LIST BOX_
[ item a ]
[ item b ]
[ item c ]
[        ]
[        ]
[        ]
[        ]
__________


For a list box presented on the screen like the one "sketched" above, I need something that returns me 3, be the listbox scrolled or not. For the above, RowCount returns me 7.
Title: Re: How to get ItemCount of shown items in a ListBox ?
Post by: Khris on Sat 10/08/2019 15:57:10
So what does .ItemCount give? Should be 3, right?
Title: Re: How to get ItemCount of shown items in a ListBox ?
Post by: eri0o on Sat 10/08/2019 16:37:53
Yes. I recorded a video - I really suck at writing... Notice the empty slot on the end.

(https://user-images.githubusercontent.com/2244442/62823796-93f96280-bb6b-11e9-89d9-1d35e7a20d03.gif)
Title: Re: How to get ItemCount of shown items in a ListBox ?
Post by: eri0o on Sat 10/08/2019 17:07:44
Ok. I think I figured. There's a property I didn't knew called TopItem.

Code (ags) Select

int VisibleItemCount(this ListBox*){
  int d =  this.ItemCount - this.TopItem-1;
  if(d < this.RowCount){
    return d;
  }
  return this.RowCount;
}
Title: Re: [SOLVED] How to get ItemCount of shown items in a ListBox ?
Post by: Crimson Wizard on Sat 10/08/2019 17:44:54
Oh, you were asking about items actually visible at the moment, that's weird but somehow I misunderstood.