Resize-aware fields?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Resize-aware fields?
Hi all,
i'm in need of a fields that resize their text both based on contents (ie if too much text, size reduces and vice versa) and on control dimensions (make the field smaller - text becomes smaller and vice versa).
These features are fairly easy to implement - I've added a behaviour that resizes the text appropriately in both these scenarios.
However, i cannot see away a field can be aware when it has been resized and i loathe to add a call to the field from on resizeStack, as any number of cards may have any number of these fields on them and I'd have to add a call for each field which isn't really sustainable.
Adding an on resizeStack handler to the behaviour script (which performs the action and then passes the handler) seems to do nothing.
on resizeControl only fires when the developer drags a corner of the field to resize it, so that's no good.
Is there a way i can get fields in question to respond to resizeStack event without specifically calling the specific field's handler from the on resizeStack event? is there some kind of publish/subscribe mechanism i can take advantage of for this?
many thanks
Stam
i'm in need of a fields that resize their text both based on contents (ie if too much text, size reduces and vice versa) and on control dimensions (make the field smaller - text becomes smaller and vice versa).
These features are fairly easy to implement - I've added a behaviour that resizes the text appropriately in both these scenarios.
However, i cannot see away a field can be aware when it has been resized and i loathe to add a call to the field from on resizeStack, as any number of cards may have any number of these fields on them and I'd have to add a call for each field which isn't really sustainable.
Adding an on resizeStack handler to the behaviour script (which performs the action and then passes the handler) seems to do nothing.
on resizeControl only fires when the developer drags a corner of the field to resize it, so that's no good.
Is there a way i can get fields in question to respond to resizeStack event without specifically calling the specific field's handler from the on resizeStack event? is there some kind of publish/subscribe mechanism i can take advantage of for this?
many thanks
Stam
Re: Resize-aware fields?
Hi.
So you resize a field under script control? If so, and I hate to mention it, but an idle handler can check on such things. See if the attached stack helps at all, and does not make you throw up.
I used Idler handlers back in the early days of HC. But they went out of style, for some good reasons, but as usual the prevailing sentiment went too far. Anyway, cllick on the button. The big field will get wider, and its new width will appear in the lower field.
Craig
So you resize a field under script control? If so, and I hate to mention it, but an idle handler can check on such things. See if the attached stack helps at all, and does not make you throw up.
I used Idler handlers back in the early days of HC. But they went out of style, for some good reasons, but as usual the prevailing sentiment went too far. Anyway, cllick on the button. The big field will get wider, and its new width will appear in the lower field.
Craig
Re: Resize-aware fields?
Thanks Craig,
No i don't resize a field under script control - but the field may be resized as it's on a GM-based layout.
I'm not sure an idle handler solves the problem of having to reference each field to be resized - i can do this in the on resizeStack handler.
I was hoping that there may be some way to 'subscribe to' or 'trap' the resize stack event and have each field respond to this on it's own...
A while back i remember reading a 'publish and subscribe' mechanic by Andre Garzia, i'll dig that up but was hoping someone else may have some recommendations...
No i don't resize a field under script control - but the field may be resized as it's on a GM-based layout.
I'm not sure an idle handler solves the problem of having to reference each field to be resized - i can do this in the on resizeStack handler.
I was hoping that there may be some way to 'subscribe to' or 'trap' the resize stack event and have each field respond to this on it's own...
A while back i remember reading a 'publish and subscribe' mechanic by Andre Garzia, i'll dig that up but was hoping someone else may have some recommendations...
Re: Resize-aware fields?
Ah.
So you do want the fields to respond after you manually resize the stack? I thought you:
See this thread, which talks about the resizeStack message, and what I believe are its peccadilloes.
viewtopic.php?f=9&t=36721
But I still do not quite know what you want. If you resize the stack, do the fields need to know that they must then resize as well, to keep the same proportions? Let me know, because that seems very doable.
Craig
So you do want the fields to respond after you manually resize the stack? I thought you:
"it" being the field itself. And:i cannot see away a field can be aware when it has been resized
I thought you wanted to make a field tell you when it had been resized on it s own, and used "idle" to keep checking on it.on resizeControl only fires when the developer drags a corner of the field to resize it, so that's no good.
See this thread, which talks about the resizeStack message, and what I believe are its peccadilloes.
viewtopic.php?f=9&t=36721
But I still do not quite know what you want. If you resize the stack, do the fields need to know that they must then resize as well, to keep the same proportions? Let me know, because that seems very doable.
Craig
Re: Resize-aware fields?
Hi Craig,
the field's behaviour has a handler (lets call it dynamicTextResize) that resizes the text either based on length of text (ie more text - smaller font, less text, bigger font) and also changes font size if the field is made wider or narrower -- as it's on an adaptive layout using the GM, the field width can change when the user enlarges or shrinks the stack.
Now i could do this in the card script (and this does work):
Code: Select all
on resizeStack
send "dynamicTextResize" to field 1
send "dynamicTextResize" to field 2
send "dynamicTextResize" to field 3
...
send "dynamicTextResize" to field n
end resizeStack
It would be better if the field could somehow be notified of the resizing of the stack happening (i.e. an observer, or publish/subscribe pattern) and call "dynamicTextResize" on itself when that happens - so that all the behaviour is encapsulated in one location (the behaviour script) and doesn't have to be manually added to other locations like the card script every time i add or remove such a field from a card.
Hope that makes sense?
Re: Resize-aware fields?
But you don't have to list each field in the resizeStack handler. If you set a custom property on each relevant field (e.g. at the same time you set it's behavior), then you can have this simple run-through in the resizeStack handler:
Of course, if you have several cards, you'll need to repeat per card too.
The fields would "subscribe" by having the their cDynamicText set to true. If you create the fields by cloning/copying existing ones, the cDynamicText is included, so no extra work. If a field is deleted, well, "subscription" gone too.
Code: Select all
repeat with i=1 to number of fields of card "X"
if the cDynamicText of fld i is true then send "dynamicTextResize" to fld i
end repeat
The fields would "subscribe" by having the their cDynamicText set to true. If you create the fields by cloning/copying existing ones, the cDynamicText is included, so no extra work. If a field is deleted, well, "subscription" gone too.
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com
Re: Resize-aware fields?
Thanks Andreas - That's a clever/simple way around the issue and much lower effort than writing publish/subscribe system.
I'll look into it, but in truth, i was hoping there may be some undocumented broadcasted message i could 'subscribe' to with for example revIDESubscribe - but i can't find anything to suggest resizeStack is one of the available messages.
According to https://livecode.com/how-to-create-plug ... e-8-0-ide/, it's possible to 'subscribe' to certain messages, for example:
Code: Select all
on preOpenStack
revIDESubscribe "idePreferenceChanged:cRevScriptSize"
end preOpenStack
ideNewControl pControlID
ideControlDeleted pControlID
ideNewCard pCardID
ideCardDeleted pCardID
ideNewStack pStackID
ideStackDeleted pStackID
ideOpenStack pStackID
idePreferenceChanged pPreference
ideSelectedObjectChanged
ideToolChanged
ideNameChanged pOldName, pNewName, pObjectID
but can't check if resize is available in any form... and there's no documentation on this that i can find other than the above web page, so was hoping a liveCode ninja might know...
-
- VIP Livecode Opensource Backer
- Posts: 10045
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Resize-aware fields?
The "ide" prefix there indicates this specific to the IDE.
For standalones, or just simply getting this done quickly in general, you could make your own loop that walks through fields on preOpenCard to dispatch a message to any fields with a certain property or within a certain group.
For standalones, or just simply getting this done quickly in general, you could make your own loop that walks through fields on preOpenCard to dispatch a message to any fields with a certain property or within a certain group.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn