Script widget - traversalOn woes [SOLVED]

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: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Script widget - traversalOn woes [SOLVED]

Post by stam » Mon Dec 18, 2023 3:32 am

Hi all,
I'm hoping someone with experience in script widgets or LCB widgets may be able to provide some insight...

Based on a group control I recently posted, I'm creating a script widget that acts as a field with placeholderText that optionally appears/disappears with animation and optionally can be used as a password field that hides/unhides text with bullet points.
So far this works fabulously. but I hit one snag I can't seem to work around: traversalOn. Not being able to tab in or out of this field is obviously a major issue.
The code is available here: https://github.com/stam66/placeholderField (MIT licence)

For some reason the default traversalOn of the widget is false (i.e. can't tab in or out of this). ]
I can set it to true quite easily with the messageBox and like magic tabbing in and out is as expected.

However, I can't seem to be able to set the traversalOn with the script of the script widget itself, or modify it with the property inspector as I would expect.
Or, more correctly, I found one way to set this, but it stops the widget from rendering (until it's resized).


I have a widget property: widgetTraversalOn with getter and setter handlers. The setter sets the boolean value and calls updateVisualControls (which sets all the relevant properties). In this handler, the line:

Code: Select all

set the traversalOn of me to the widgetTraversalOn of me
works, Inasmuch as the traversalOn of the generated widget in the extension builder's test stack is true (the default value for widgetTraversalOn), but the widget renders topLeft (instead of middle of the stack), with no visible elements (which wasn't the case previously).
noRenderOnCreate.jpg

It remains selectable and if resize it, it draws normally and after this works normally.
renderOnResize.jpg

If I put code above anywhere else (eg directly in the setter, a separate command, send in time, etc), the widget renders normally:
normalNoTraversal.jpg
but the traversalOn for the widget is false and can't be set with the property inspector (although the widget's property wigetTraversalOn is set) so tabbing in/out can't happen, which is highly undesirable.


After a couple of hours at this last seemingly tiny hurdle I'm not sure I can think of anything else...
Any suggestions?

many thanks
Stam
Last edited by stam on Tue Dec 19, 2023 12:47 pm, edited 1 time in total.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Script widget - traversalOn woes

Post by bn » Mon Dec 18, 2023 3:44 pm

Hi Stam,

change handler setTraversalOn to

Code: Select all

command setTraversalOn
    set the traversalOn of the owner of me to the widgetTraversalOn of me
end setTraversalOn
There is something going on with referencing in Script Widgets
https://quality.livecode.com/show_bug.cgi?id=24455

change handler openControl to

Code: Select all

on openControl
    if not sHasCreatedVisuals then createVisualControls
    updateVisualControls
    resizeFields
    send "setTraversalOn" to me in 50 milliseconds
end openControl
That works for me

Kind regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Script widget - traversalOn woes

Post by bn » Mon Dec 18, 2023 5:48 pm

Hi Stam,

If you want the user to be able to tab out of the widget add

Code: Select all

on tabKey
   lock messages
   pass tabKey
   unlock messages
end tabKey
Seems to work without untoward effects in short testing.

Please note that if it is a password field then the moving of "placeholder text" is visible behind the right side of the text field behind field "disclose".
Setting field "disclose" to opaque in handler "createVisualControls" helps a lot if desired.

Kind regards
Bernd

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Script widget - traversalOn woes

Post by stam » Mon Dec 18, 2023 6:48 pm

Hi Bernd!

That's interesting... when setting the traversalOn from the messageBox, I was to tab in and out of the field with no problems and without using the tabKey handler. Is this really needed?

Also interesting: I had already tried both of your solutions prior to posting the above (send in time - which is why the setTraversalOn handler even exists - and set the traversalOn of the owner of me), but nothing worked.

I guess I'll try again... and thanks for noting the issue with disclose, will sort...

Many thanks as always,
Stam

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Script widget - traversalOn woes

Post by bn » Mon Dec 18, 2023 7:43 pm

bn wrote:
Mon Dec 18, 2023 3:44 pm
Those the important changes that set traversalOn working right while the widget is build.
Also when placing the widget on a new stack.
They might cure your woes...

You made no mention of it so I thought you might have overlooked them.
Kind regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Script widget - traversalOn woes

Post by bn » Tue Dec 19, 2023 1:59 am

Hi Stam,

I am embarrassed that I did not read your reply carefully, I was in a hurry, sorry about that.

Re tabbing out: it works if you have the placeholder text showing but not when there is text in the text field.
It is probably a matter of taste whether you should be able to tab out of your text or not (think password)

I left the on tabKey handler in and also set the opaque of field "disclose"

I upload the modified version of your 0.9 version that works for me. I have tested it numerous times restarting LC in between deleting dict and api.
It worked consistently.
Tabbing is most fun when you add just another field to the test stack. Then it tabs between the two. Otherwise it does not know where to tab to.

If that does not work for you I am at a loss as to why.

Kind regards
Bernd
Attachments
com.livecode.sk.widget.placeholderField.livecodescript.zip
(7.25 KiB) Downloaded 55 times

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Script widget - traversalOn woes

Post by stam » Tue Dec 19, 2023 12:06 pm

As always - thank you Bernd!
All works perfectly now. I realised I had the 'send in time' command in the updateVisualControls handler, whereas you added it to the openControl handler and it works perfectly. As does the tabKey handler (although I'm not sure why lockMessages is needed - but hey, if it works I'm not questioning it :) and more importantly does not stop the fieldAction message from being emitted which was my concern).

For my purposes this is now feature complete. I've updated the widget on GitHub with minor tidying up - many thanks for adding the polish!
Stam


PS: Script widgets still don't seem ready for prime time. Half of the problem is defining and displaying the widget's properties which can take nearly 3/5 of the code. For example of the 880 lines of code(!) required for this tiny widget, 556 lines are dedicated to creating, displaying and documenting properties, making editing the widget's code a hassle.

I think in the ideal world, code relating to establishing the properties would be a separate file, but not sure how feasible that is...

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Script widget - traversalOn woes [SOLVED]

Post by bn » Wed Dec 20, 2023 11:12 am

Hi Stam,

Thanks for making this very nifty and useful widget.
As does the tabKey handler (although I'm not sure why lockMessages is needed - but hey, if it works I'm not questioning it :) and more importantly does not stop the fieldAction message from being emitted which was my concern).
Try to remove the lockMessages and see what happens. :)

Kind regards
Bernd

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Script widget - traversalOn woes [SOLVED]

Post by stam » Wed Dec 20, 2023 5:21 pm

bn wrote:
Wed Dec 20, 2023 11:12 am
Try to remove the lockMessages and see what happens. :)

Kind regards
Bernd
Nah I trust you and time is short ;)

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Script widget - traversalOn woes [SOLVED]

Post by stam » Sun Dec 31, 2023 4:25 am

Hi @newcouffa,
In case it wasn’t clear, I have incorporated the changes and thanked Bernd for his suggestions.

There are some other minor issues I need to address but I haven’t got time at present, as my actual (non-coding) day job takes precedence and it’s hectic at present, this being the busiest time of year for health services…

The widget and source code are available on the GitHub link above. Feel free to download and use as you see fit (MIT licence is extremely permissive), and hey, if you feel motivated you can always look at addressing the issues I raised for myself as a reminder. I will get round to these eventually!

Stam

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”