x


How to set position in ScrollView?

Hello,

How to set position in ScrollView?

For example I have 300 buttons inside ScrollView and want to set position to make 200-th button visible.

more ▼

asked May 15 '10 at 06:54 PM

Santa gravatar image

Santa
477 20 24 37

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You can use GUIStyle.CalcHeight to get the height of a line, then set the scrollview .y position to 200*calculatedHeight to go to the 200th button.

more ▼

answered May 15 '10 at 07:58 PM

Eric5h5 gravatar image

Eric5h5
81.5k 42 133 529

Thanks! It's already can give what I need. But there is also some space between lines. In my case it is buttons and space between them. I see that it is 2 pixels, but can't find any variable inside GUIStyle where it could be. Is there a way to calculate it in script? Or may be it's always 2 pixels?

May 15 '10 at 09:49 PM Santa

@Santa: Probably whatever the padding or margin is set to for the GUIStyle. However I think that's included in the CalcHeight maybe?

May 15 '10 at 10:27 PM Eric5h5

No, it isn't in CalcHeight. Both Padding and Margin for the button GUIStyle has 4 in all values. And the space between two buttons is 2. I've checked it and one of them is what I need. I've tried to change both from 4 to 16 and got the result. BUT visually it is still 2 pixels, and mathematically I should use more. Interesting.

May 16 '10 at 07:34 PM Santa
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3812
x915
x77
x65

asked: May 15 '10 at 06:54 PM

Seen: 2587 times

Last Updated: May 15 '10 at 06:54 PM