revig / universal-button-widget

A LCB widget which can be used as a button, as a toggle-button and as a segmented control.
MIT License
8 stars 3 forks source link

Test of ubFormattedWidth #5

Open trevixdesign opened 2 years ago

trevixdesign commented 2 years ago

I did a test of a Universal button similar to "next card>" where the ">" is a SVG drawing, supposily always aligned right. Label is aligned left Icon gravity is right The change of label is not reflected on the formatted width, being herratic...Please note: the width in msg is opposite to the width in the property inspector. The only way to make it works is to put a "wait x seconds with messages" after the change of label and before the ubFormattedWidth function Any help is appreciated. Thanks

This is the code, from another button, used to verify the formatted width:

on mouseUp pMouseButton
     put the topRight of  widget "UbtnTest"  into tTopRight
     put the buttonText of widget "UbtnTest" into tLabel
     if tLabel = "next card" then
          set the buttonText of widget "UbtnTest" to "up"
     else
          set the buttonText of widget "UbtnTest" to "next card"
     end if
--wait 1 seconds with messages
     put the ubFormattedWidth of widget "UbtnTest" into tWidth
     put tWidth into msg
     set the width of widget "UbtnTest" to tWidth 
     set the topRight of widget "UbtnTest" to tTopRight
end mouseUp
revig commented 2 years ago

You are right, I noticed issues with the calculation of ubFormattedWidth and there is also a redraw problem. May be I will ditch the property and replace it with a handler call. This way the widget could be redrawn by setting the width of the widget to the "formatted width".

revig commented 2 years ago

The way I intended to solve the problem didn't work as I expected. Adjusting the button's width right after changing the button label still needs to be a delayed. But I added a LC handler "ubResizeToFormattedWidth" to the widget's default script which should eliminate the glitches you observed by dynamically changing the button label. Provided that you add the ubResizeToFormattedWidth handler to the script object of the widget your sample script should read as follows:

command ubSwitchLabel
   local tTopRight, tLabel

   put the topRight of  widget 1  into tTopRight
   put the buttonText of widget 1 into tLabel

   set the iconSizeRatio of widget 1 to 0.55

   if tLabel = "next card" then
      set the buttonText of widget 1 to "up"
   else
      set the buttonText of widget 1 to "next card"
   end if

   dispatch "ubResizeToFormattedWidth" to widget 1
   set the topRight of widget 1 to tTopRight

   if the buttonText of widget 1 = "next card" then
      set the iconSizeRatio of widget 1 to 0.55
   else
      set the iconSizeRatio of widget 1 to 1
   end if
end ubSwitchLabel

Adjust the text margin in the "Text" section of the Property Inspector and possibly you may need to increase the delay in the ubResizeToFormattedWidth handler.

trevixdesign commented 2 years ago

Hello. Thanks for the effort but it still doesn’t work very well. See attached test stack. As a suggestion, it should have a more general way of handling the formatted size, without the need to manually calibrate the margins according to the length of text. In my case, for example, I localise using properties profile (there are hundred in several language). They often share the code while having different label length.

Cordiali saluti

Roberto Trevisan


Trevix Design di Trevisan Roberto


Il giorno 26 ott 2022, alle ore 12:55, Ralf Bitter @.***> ha scritto:

The way I intended to solve the problem didn't work as I expected. Adjusting the button's width right after changing the button label still needs to be a delayed. But I added a LC handler "ubResizeToFormattedWidth" to the widget's default script which should eliminate the glitches you observed by dynamically changing the button label. Provided that you add the ubResizeToFormattedWidth handler to the script object of the widget your sample script should read as follows:

command ubSwitchLabel local tTopRight, tLabel

put the topRight of widget 1 into tTopRight put the buttonText of widget 1 into tLabel

set the iconSizeRatio of widget 1 to 0.55

if tLabel = "next card" then set the buttonText of widget 1 to "up" else set the buttonText of widget 1 to "next card" end if

dispatch "ubResizeToFormattedWidth" to widget 1 set the topRight of widget 1 to tTopRight

if the buttonText of widget 1 = "next card" then set the iconSizeRatio of widget 1 to 0.55 else set the iconSizeRatio of widget 1 to 1 end if end ubSwitchLabel Adjust the text margin in the "Text" section of the Property Inspector and possibly you may need to increase the delay in the ubResizeToFormattedWidth handler.

— Reply to this email directly, view it on GitHub https://github.com/revig/universal-button-widget/issues/5#issuecomment-1291853089, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKGJKWIIJSALTP4FAPW6GULWFEE2ZANCNFSM6AAAAAAQ7Y5Y5Q. You are receiving this because you authored the thread.

revig commented 2 years ago

I don't see any attachment. Could you please attach the stack again as ZIP file?

trevixdesign commented 2 years ago

Here you go.

Cordiali saluti

Roberto Trevisan


Trevix Design di Trevisan Roberto

Torino Italy ph: +39 340 6300631 web: https://www.trevix.it email: @.*** Skype: trevisan.roberto Via Cavallermaggiore 10 10139 Torino

C.F. TRVRRT54E23G914B PEC: @. cod. destinatario:non disponibile all informations and attachments are confidential and a trevix design intellectual property, if you receive this message in error, please delete it and contact @.


Il giorno 27 ott 2022, alle ore 13:03, Ralf Bitter @.***> ha scritto:

I don't see any attachment. Could you please attach the stack again as ZIP file?

— Reply to this email directly, view it on GitHub https://github.com/revig/universal-button-widget/issues/5#issuecomment-1293357484, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKGJKWNP4S3JGTEOZHNVITTWFJOQDANCNFSM6AAAAAAQ7Y5Y5Q. You are receiving this because you authored the thread.

revig commented 2 years ago

If you see a link to your test stack there must be something wrong on my end, because your last comment again does not contain a link to a file. I suggest you send the stack as an email attachment to my known email address.

trevixdesign commented 2 years ago

Trying again SVGTestButtons2.livecode.zip

revig commented 2 years ago

Checked your test stack and noticed that you forgot, like described in the documentation, to add the ubResizeToFormattedWidth default handler to the widget's script object. And keep in mind that you no longer need to use the wait command in your own scripts. Possibly you may need to adjust the time period of the wait command in the ubResizeToFormattedWidth handler though.

One more note: I noticed that you tried to change the button label "on preOpenCard". Unfortunately this does not work, may be due to the same reason why adjusting the button width using lock screen fails. I replaced preOpenCard with openCard. However, this has the effect that the process of switching the label and resizing is visible. I know this solution for your issue is far from perfect, but this is what I can offer without completely recreating the widget.

Please see the attached test stack including my modifications. SVGTestButtons2Mod.livecode.zip