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

  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – bobobobo
    Jun 14, 2013 at 2:47
  • \$\begingroup\$ that ratio seems reasonable. Are you sure you're not getting the division truncated because of integer variables? \$\endgroup\$
    – Jimmy
    Jun 14, 2013 at 2:51
  • \$\begingroup\$ if it helps to make the question more clear, I added an illustration of what I assume the variables mean \$\endgroup\$
    – Jimmy
    Jun 14, 2013 at 3:02
  • \$\begingroup\$ How is it not working? How is this not just a "debug my code" question? \$\endgroup\$ Jun 14, 2013 at 3:11
  • 2
    \$\begingroup\$ When you need a GUI which is advanced enough to have scrollbars, you should look into using a GUI library. \$\endgroup\$
    – Philipp
    Jun 14, 2013 at 8:57

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.


Not the answer you're looking for? Browse other questions tagged .