Button text on icon image

Ken Ray kray at sonsothunder.com
Mon May 23 13:24:41 EDT 2005


On 5/23/05 12:02 PM, "Klaus Major" <klaus at major-k.de> wrote:
>> But do you mean sure that it now appears in front of the image, or
>> sure that it used to appear behind the image? Anyway, I'm sure of
>> both, just not sure when the change occurred.
>>> That's what i know, fiddling with the margins property, but never
>>> with satisfying results...
>> One way is to have the text left-aligned, set the top, right and
>> bottom margins to 0, and then increase the left margin until you're
>> happy. But this isn't so good when you want to dynamically change
>> the label. So I was hoping to keep the label center-aligned, and
>> adjust top and bottom margins.
>> But finding the right settings is difficult.
> 
> This is only possible, if at all, on ONE platform*** only ONE
> (static) label and with lots of testing...
> *** The slight font differences!

Ah ha! OK, Klaus, I think I've hit on the magic equation... test it and see
if it works for you:

on mouseUp
  CenterIt (long id of btn 2),4
end mouseUp

on CenterIt pBtnID,pMargin
  put the height of pBtnID into tHt
  put the textHeight of pBtnID into tTxHt
  put the icon of pBtnID into tIconID
  put the formattedHeight of img id tIconID into tFmtHt
  put round((tHt - tTxHt)/2) into tBotMargin
  put tBotMargin + tFmtHt into tTopMargin
  set the margins of pBtnID to
pMargin,tTopMargin-pMargin,pMargin,tBotMargin+pMargin
end CenterIt


The only "hard part" here is that you need to factor in the formattedHeight
of the icon's image - and if you don't know where it is, you can't get it's
formattedHeight. For the purposes of the code above, it is assumed that the
icon is on the same card (hidden), but you can adapt to suit.

Jeanne had the right suggestion - be able to get the "long name" or "long
id" of an image used as an icon so you can know where it is located.
Consider voting for Bug 521
(http://support.runrev.com/bugdatabase/show_bug.cgi?id=521).

Let me know how it works for you,


Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com



More information about the use-livecode mailing list