Measuring GUI elements (slider thumb)

Iam writing a custom GUI element and I would like to know how I should go about some dynamic measuring in the best way possible.

The element Iam working on right now is a vertical slider with a label that follows the position of the slider thumb(the label displays the current slider value).

In order for this to visually and dynamically work the way I want(to have the label fixed just outside the slider thumb). Iam struggling abit on how to accomplish this the best way possible. I need to take into account the changes in size of the thumb made by different settings on the skin applied to the slider thumb in order to reach the level of dynamic i want.

So my question is... is there a way(simply a function or alike) to measure the size of the thumb where all the factors that can change the visual size of the thumb is taking into account.. padding, overflow, fixedHeight/width and so on? or do I need to write a check for all these factors individually?

thanks

/ NisEik

There is no way to automatically measure the size of a given GUI element.

You can calculate the thumb Rect of a vertical slider something like this:

// thumb is the GUIStyle for the thumb
// slider is the GUIStyle for the slider
// position is the rect for the slider
// value, start, and end is the slider value, and the start and end of the slider range

float thumbSize = thumb.fixedHeight != 0 ? thumb.fixedHeight : thumb.padding.vertical;

float pixelsPerValue = (position.height - slider.padding.vertical - thumbSize) / (end - start);

Rect thumbRect = new Rect ( 
    position.x + slider.padding.left,
    (value - start) * pixelsPerValue + position.y + slider.padding.top,
    position.width - slider.padding.horizontal, 
    thumbSize
);