Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm making a scroll bar for chat box in my game now but I can't calculate the height of thumb in scroll bar.

I try

(containerHeight / contentHeight) * thumbHeight

but it's not working.

please give me an idea, thanks.

Illustration: illustration of variables

share|improve this question

closed as not a real question by bobobobo, Sean Middleditch, msell, Byte56, Nicol Bolas Jun 14 '13 at 16:21

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Hi man, containerHeight, contentHeight, and thumbHeight are all variables internal to your program. We have no idea what they are supposed to do or what data it represents. –  bobobobo Jun 14 '13 at 2:47
    
that ratio seems reasonable. Are you sure you're not getting the division truncated because of integer variables? –  Jimmy Jun 14 '13 at 2:51
    
if it helps to make the question more clear, I added an illustration of what I assume the variables mean –  Jimmy Jun 14 '13 at 3:02
    
How is it not working? How is this not just a "debug my code" question? –  Sean Middleditch Jun 14 '13 at 3:11
2  
When you need a GUI which is advanced enough to have scrollbars, you should look into using a GUI library. –  Philipp Jun 14 '13 at 8:57
show 3 more comments

1 Answer 1

I think you're just looking for the equation: X / Y = A / B, where X is to A what Y is to B then algebra yields:

X / Y = A / B

Multiply both sides by Y to get:

X = (A / B) * Y

Using some variables I made up because I don't completely know if Jimmy's interpretation is alright:

TabHeight / ScrollBarHeight = ViewableHeight / TotalHeight
TabHeight = (ViewableHeight / TotalHeight) * ScrollBarHeight

As long as you know any 3 variables in the equation, you can solve for the 4th.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.