Resize-aware fields?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
stam
Posts: 3069
Joined: Sun Jun 04, 2006 9:39 pm

Resize-aware fields?

Post by stam » Thu Feb 03, 2022 4:23 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Resize-aware fields?

Post by dunbarx » Thu Feb 03, 2022 5:20 pm

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.

detectFieldChange.livecode.zip
(1.07 KiB) Downloaded 142 times

Craig

stam
Posts: 3069
Joined: Sun Jun 04, 2006 9:39 pm

Re: Resize-aware fields?

Post by stam » Thu Feb 03, 2022 5:46 pm

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...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Resize-aware fields?

Post by dunbarx » Thu Feb 03, 2022 5:59 pm

Ah.

So you do want the fields to respond after you manually resize the stack? I thought you:
i cannot see away a field can be aware when it has been resized
"it" being the field itself. And:
on resizeControl only fires when the developer drags a corner of the field to resize it, so that's no good.
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.

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

stam
Posts: 3069
Joined: Sun Jun 04, 2006 9:39 pm

Re: Resize-aware fields?

Post by stam » Thu Feb 03, 2022 7:20 pm

dunbarx wrote:
Thu Feb 03, 2022 5:59 pm
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.
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
but that's tedious and error-prone (for example if i remove a field from the layout i have to remember to remove the corresponding line form the resizeStack handler or calamity ensues...)

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?

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 324
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: Resize-aware fields?

Post by SWEdeAndy » Thu Feb 03, 2022 7:50 pm

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:

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
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.
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

stam
Posts: 3069
Joined: Sun Jun 04, 2006 9:39 pm

Re: Resize-aware fields?

Post by stam » Fri Feb 04, 2022 12:26 am

SWEdeAndy wrote:
Thu Feb 03, 2022 7:50 pm
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
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
examples of messages given on this web page are:
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...

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10045
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Resize-aware fields?

Post by FourthWorld » Fri Feb 04, 2022 2:30 am

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply