Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075929 Posts in 44152 Topics- by 36119 Members - Latest Member: Royalhandstudios

December 29, 2014, 04:00:59 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Calculating scrollbar's length
Pages: [1]
Print
Author Topic: Calculating scrollbar's length  (Read 376 times)
kamac
Level 10
*****


Notorious posts editor


View Profile Email
« on: January 26, 2013, 04:15:20 AM »

Help me because I am lost.
Crazy

I've tried to think of some expression that would calculate scrollbar's length, when knowing maximal pixel content value and real pixel content value.

Here's the list of what do I need that expression to be/return:
- Scrollbar length must be in %, where 100% is maximal length
- The longer real pixel content, the smaller is scrollbar's length

|| For example ||
Let's assume our maximal content's pixel length is 400 and our real pixel content's length is 100, therefore I need scrollbar to be about 75% of it's length

Now, another example: max. length: 400, real length: 400, then I need scrollbar to be at 0% - 1% size.

And the last example: max. length: 400, real length: 2, then I need scrollbar to be at 95% - 99% size.

I am lost in equations Sad
Logged

Nothing to do here
kamac
Level 10
*****


Notorious posts editor


View Profile Email
« Reply #1 on: January 26, 2013, 04:44:13 AM »

Alright, I think I've got it...

(maxVal-val)/maxVal

does the trick I think. Got to test first.
Logged

Nothing to do here
rivon
Level 10
*****



View Profile
« Reply #2 on: January 26, 2013, 07:25:44 AM »

You got it wrong. If you have 400px of content and only 100px is displayed, then the scrollbar should have length of 25% of max length. Therefore length = maxval/val * 100 (if you need it in percent, otherwise don't multiply it by 100).
Logged
roc
Level 0
**


View Profile
« Reply #3 on: January 26, 2013, 08:09:12 AM »

Help me because I am lost.
Crazy

I've tried to think of some expression that would calculate scrollbar's length, when knowing maximal pixel content value and real pixel content value.

Here's the list of what do I need that expression to be/return:
- Scrollbar length must be in %, where 100% is maximal length
- The longer real pixel content, the smaller is scrollbar's length

|| For example ||
Let's assume our maximal content's pixel length is 400 and our real pixel content's length is 100, therefore I need scrollbar to be about 75% of it's length

Now, another example: max. length: 400, real length: 400, then I need scrollbar to be at 0% - 1% size.

And the last example: max. length: 400, real length: 2, then I need scrollbar to be at 95% - 99% size.

I am lost in equations Sad

Maybe I'm misreading this, but you want the size of the grabby part of the scrollbar to increase as the ratio of view size/content size decreases? Won't that raise all kinds of hell when you have a real length of 2, a max length of 400 and only 1-4% of the scrollbar gutter to divide those remaining 398 content unit thingies up amongst?

If that's the case or if I misread and you meant the gutter instead of the other bit, yeah you got it right the second time.  If you're looking for this effect:


15/20 lines visible, 75% scrollbar size

then a simple view_size / max_size should give you the proper size of the grabby thing (what the hell is this called anyway), and as rivon said multiply by 100 if you need it in percent.
Logged
kamac
Level 10
*****


Notorious posts editor


View Profile Email
« Reply #4 on: January 26, 2013, 09:27:38 AM »

Quote
You got it wrong. If you have 400px of content and only 100px is displayed, then the scrollbar should have length of 25% of max length. Therefore length = maxval/val * 100 (if you need it in percent, otherwise don't multiply it by 100).

Actually, no.

If I do maxval/val * 100 it will not work.

Consider that I have only one item added (say 32x32 image), while the view is 800px height.
800/32*100 = 2500%

Right.

While my example returns the following (*100 is optional):
(800-32)/800 * 100% = 96%
96% of full grabby's size. Not 2500%.

So, roc was right that I was right Cool


Quote
Maybe I'm misreading this, but you want the size of the grabby part of the scrollbar to increase as the ratio of view size/content size decreases? Won't that raise all kinds of hell when you have a real length of 2, a max length of 400 and only 1-4% of the scrollbar gutter to divide those remaining 398 content unit thingies up amongst?

I didn't want to mess it up adding that I'd make an condition statement to check if size isn't too small. (if percent < smallest_acceptable then percent = smallest_acceptable)

view_size / max_size isn't proper either.

I don't know whether we don't understand eachother, or whatever, but I think my solution works for me just fine.



Final expression's thought:
The bigger difference between max view and actual view, the bigger thumb's size. (That grabby thing)


Anyways, got it working with my expression sample.
Cheers.
Logged

Nothing to do here
impulse9
Level 5
*****



View Profile WWW
« Reply #5 on: January 26, 2013, 10:02:29 AM »

This is how I did it.

Code:
void OxGUI :: GUIVerticalScrollBar :: RefreshView()
{
const int totalH = canvas->getH() - 36;

scrollH = totalH / maxVal;

if (scrollH < 12)
{
scrollH = 12;
// prevent division by zero
scrollPos = (maxVal == 1)?0:((val * (totalH - scrollH)) / (maxVal-1));
}
else
scrollPos = (val * totalH) / maxVal; // maxVal is guarranteed to be >= 1
}

totalH is the height of the scrolling area (minus the height of the buttons).
scrollH is the height of the scroller
scrollPos is the vertical position of the scroller

The rest of the code is just there to ensure scroller is always at least 12 pixels tall (otherwise the user wouldn't be able to click it when maxVal would get big enough).

The result:

Logged

rivon
Level 10
*****



View Profile
« Reply #6 on: January 26, 2013, 10:53:52 AM »

Quote
You got it wrong. If you have 400px of content and only 100px is displayed, then the scrollbar should have length of 25% of max length. Therefore length = maxval/val * 100 (if you need it in percent, otherwise don't multiply it by 100).

Actually, no.

If I do maxval/val * 100 it will not work.

Consider that I have only one item added (say 32x32 image), while the view is 800px height.
800/32*100 = 2500%

Right.
Sorry, I reversed it. Should have been val/maxval. That way you would get 4%, which is right.

You know, the scrollbar's length symbolizes the size of the view area compared to the max area. So, if you have a page of length 200px and the view is 100px, then the scrollbar would have 50% length as 100 is half of 200. If you had a page length 500px and view 100px, then the scrollbar would have 20% length. That way, when you move the scrollbar by one scrollbar length, you move the whole view by one page (or one "view"). Got it?
Logged
kamac
Level 10
*****


Notorious posts editor


View Profile Email
« Reply #7 on: January 26, 2013, 10:59:50 AM »

Quote
Got it?

Yuss.
Logged

Nothing to do here
roc
Level 0
**


View Profile
« Reply #8 on: January 26, 2013, 12:25:35 PM »

If you had a page length 500px and view 100px, then the scrollbar would have 20% length. That way, when you move the scrollbar by one scrollbar length, you move the whole view by one page (or one "view").

This is what I was trying to convey with view_size = 100px, max_size = 500px for this example, I'm still not sure I understood what you were going for but I'm glad you got the result you wanted Smiley
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic