MyGUI / mygui

Fast, flexible and simple GUI.
http://mygui.info/
Other
724 stars 207 forks source link

getVScrollRange for combobox always return 1 #184

Closed corentinjaffre closed 4 years ago

corentinjaffre commented 4 years ago

I wrote a few months ago a function which centers the combobox scroll to the current selection. It seems to be broken right now, because getVScrollRange always returns 1, even if the combobox is full of data with a visible V scrollbar.

I'm doing this: float itemSize = _sender->getVScrollRange() / _sender->getItemCount(); _sender->setVScrollPosition(_sender->getIndexSelected() * itemSize); And it doesn't work anymore.

Altren commented 4 years ago

You are doing integer division, both getVScrollRange and getItemCount return size_t, thus _sender->getVScrollRange() / _sender->getItemCount() return size_t. You should do (float)_sender->getVScrollRange() / _sender->getItemCount()

Altren commented 4 years ago

Also I guess that _sender is ComboBox and it have it's internal scroll (because it have edit area). So you are changing wrong scroll bar. There is _sender->beginToItemSelected(); that makes selected item visible. Unfortunately there is no direct access to the popup list, so to make it centered you would need to call something ugly like _sender->beginToItemAt(_sender->getIndexSelected() - 2)

corentinjaffre commented 4 years ago

OK, that can explain why _sender->getVScrollRange() always return 1. Anyway beginToItemSelected() is good enough for me, so thanks a lot for your information.