- Home /
How to make a scroll bar work?
I am displaying lines from a log file on screen, the size of the file makes it impractical to place everything inside a scrollView due to the memory and performance implications, so I'm trying to handle the scroll bar my self, but it seems like VerticalScrollbar just displays the scroll bar. I don't believe this is just an ornamental item but the manual does not explain how to catch the events generated by the scroll bar, and the scroll bar itself seems frozen.
So... how do I make this scroll bar work?
Answer by georgeq · Mar 21, 2014 at 08:32 PM
SOLVED:
I just can't believe how easy it is, but the manual has no good explanation and lacks of an example. The code below is specific to my project, but I hope this example can be useful for someone.
short y = 50;
for(i=0;i<mark;i++){
GUI.Label(new Rect(10,y,c1,height),String.Format("{0:yyyy/MM/dd HH:mm:ss}",view[i].time));
GUI.Label(new Rect(c1+10,y,Screen.width-c1-40,height),view[i].descrip);
y += height;
}
long op = max-pos;
long np = (long) GUI.VerticalScrollbar(new Rect(Screen.width-20,50,20,height*rows),op,rows,0,max-rows);
if(np!=op){
pos = max-np;
guilog.JumpTo(pos);
for(i=0;i<rows;i++){
view[i] = new Log();
if(log.ValidRow()){
view[i].time = guilog.time;
view[i].descrip = guilog.descrip;
guilog.Previous();
}
}
}
So easy that's hard to believe.