gui slider formula
BlitzMax Forums/BlitzMax Programming/gui slider formula
| ||
Hi I have created a list box. The list can be scrolled with up/down buttons which works fine. I am adding in a slider bar but having difficulty with the maths. The list box has the following variables: lines: number of viewable lines in the list box itemCount: total number of items in the list (1 based) firstItem: the first viewable item in the list (this obviously changes as the list scrolls up & down) So to display the list I am effectively showing items from firstItem to (firstItem + lines - 1). The slider bar value needs to be within the range 0 to 1 (which is then used to calculate the coords). So, given that I know the above values, how do I calculate the slider position? I know there is a formula for it, I just can't work it out! |
| ||
If total_number_of_items=100 then each item will be (1/total_number_of_items) = 1/100 = 0.01 If you can display 30 items per page the slider value will be (1.0/100)*30 = 0.3 with each additional scroll 'point' being 0.01. Is that what you mean? |
| ||
Thanks Tony, that's definately on the right track. After a bit of thinking, I realised that although (in your example) there are 100 items, there are only 70 scroll increments as 30 items are viewable. So, the code is: sliderPos# = 1.0 / (itemCount - lines) 'scroll increment sliderPos#:* firstItem - 1 'slider pos of current view Thanks again for your help :) |
| ||
Do you need it for your internal calculation or to move the content? The slider itself is able to do it when you simply set the slider ranges: SetSliderRange(slider:TGadget,range0,range1) For the default SLIDER_SCROLLBAR style the range0,range1 parameters are treated as a visible / total ratio which dictates both the size of the knob and it's maximum value. |
| ||
I'm not using maxgui, it's my own gui system I am developing. I've got it all working now - moving the content was fairly simple (by doing pretty much the reverse calculation to what I posted above) |