Dynamic labels for buttons with (oddshaped) icon images?

Wilhelm Sanke sanke at hrz.uni-kassel.de
Wed Feb 11 05:44:16 EST 2009


In my last post of this thread I had proposed the following script 
(based on the original proposals of Jacqueline and Klaus) to position 
the label of a button with an icon image:

> "on mouseUp
>  put the icon of btn 12 into tID
>  put the height of img ID tID into timgheight
>  set the height of btn 12 to (timgheight  + the textheight of btn 12)
>  put the height of btn 12 into tBtHeight
> # the line above to simplify the following computations
>  put (2* (tBtHeight-(the textheight of btn 12 + the effective textsize 
> of btn 12))) / tBtHeight into tDivFactor
>  put (the height of btn 12 - the textheight of btn 12 - the effective 
> textsize of btn 12) / tdivfactor into tMargin
>  set the margins of btn 12 to 0,tMargin,0,tMargin
> end mouseUp" 
> (Pay attention to possible line breaks in the mail). 
and added:

> The script above (most accurately) places the label "on top" of the 
> icon with any icon image height and fontsize. What we might still need 
> is an extra tiny "jiggle" factor that achieves another mini-adjustment 
> of 1 to 3 pixels.
Having arrived at that level of insight it was quite natural to conclude 
that we could fine-tune the position of the label with a scrollbar that 
adjusts the relevant margin items by increments of 1. This works fine 
here; I will add the scrollbar (and other enhancements) to the next 
version of sample stack "DynamicImageButtons".

I have also tried to automate the setting of the group rect to the 
height and width of the icon image and then to set the topleft of the 
group rect to the topleft of the button. You have to make certain 
adjustments here that take into account that the height of a group is 
greater than the original height of the control that was grouped by 8 
pixels.
I did not yet find out out how to exactly synchronize the toplefts of 
button and group, and I remember that there are generally problems when 
you try to adjust the position of controls inside a group by script.

But of course - other than the problem of adjusting the label position - 
it is quite easy to adjust the group rect manually to the size of the 
icon image.

Regards,

Wilhelm Sanke
<http://www.sanke.org/MetaMedia>



More information about the use-livecode mailing list