Using Behaviors for Triggering UI Design - Run Time
Richard Gaskin
ambassador at fourthworld.com
Wed Mar 30 09:53:42 EDT 2016
Sannyasin Brahmanathaswami wrote:
> Let's say we have a series of fields that have just a few words of
> text in them we want to center vertically. Text varies. Our designers
> may want to change the words over time. I don't want to have to go
> in and manually adjust the top and bottom margins to achieve the
> position.
>
> So then this is were dynamic runtime GUI layout/typesetting may be
> the way to go. Once the UI is all finished one could turn it off
> because the properties would be set for the fields.
>
> We could create a behavior (ideally an external.livecodescript text
> file) with this in it
>
> command centerTextVertically
> put the formattedheight of me into tTotalTextHeight
> put ( the height of me - tTotalTextHeight ) / 2 into tTopBottomMargins
> set topmargin of me to tTopBottomMargins
> end centerTextVertically
>
> put the long ID of the button that contains that into the field; then
> make multiple copies of that field place them on the UI.
>
> 1) When, how and what is the most efficient way...to trigger this?
> in a preopenstack or preopencard handler? so that the UI fields are
> all centered when the card renders?
>
> But then it needs to be a behavior of the stack or card, but then the
> reference to "me" fails to target the fields which all have the same
> name.
If it makes sense to put those fields into a group you can use
preOpenControl.
> 2) Still waiting on how to set a behavior to an
> external.livecodescript. Dictionary only descripts the long id of a
> button method.
Behaviors can be either buttons or stacks, and the stacks need not be
script-only.
When setting any behavior the syntax is:
set the behavior of <obj> to <absoluteObjReference>
...where <absoluteObjReference> is usually the long ID of a button, but
can be any unambiguous object reference.
FWIW you can use "the long id" for any object, even stacks.
In all cases, once set a behavior is resolved to a "rugged long ID", a
long ID where the stack portion is changed from the full file path as we
normally find it to just the stack name, allowing portability.
For example:
button id 1004 of cd id 1003 of stack "/home/rg/something/rsrc.livecode"
...becomes:
button id of cd id 1003 of stack "rsrc"
So when using a stack as a behavior you can write:
set the behavior of btn "Something" to the long id of stack "rsrc"
...or even more simply, since stack names are already unique:
set the behavior of btn "Something" to the name of stack "rsrc"
--
Richard Gaskin
Fourth World Systems
Software Design and Development for the Desktop, Mobile, and the Web
____________________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the use-livecode
mailing list