Page 1 of 1

Tri-state switch control

Posted: Mon Jul 31, 2023 5:13 am
by stam
Hi all,

the default switch button control is great - if you want a binary choice.

As part of a project I needed a tri-state control (not just left/right, but left/centre/right) so rolled my own...

Sharing it both because others may find it useful but also because resizing is still a bit iffy (I try to maintain aspect ratio, which works but it's a bit... twitchy), so hoping others may have a better way of doing it and grateful for advice... usage should be self explanatory...

S.

Re: Tri-state switch control

Posted: Mon Jul 31, 2023 11:51 am
by bn
Stam,

That is a nice control. Thank you.

Re: twitchy:

at margins of 4 (your current setting)

try in resizeControl handler

Code: Select all

   put tNewRect into tRect
   add 4 to item 1 of tRect -- change
   add 6 to item 2 of tRect -- change
Don't ask me why, it has to do with the margins and all. Do not have the time to really understand this right now.
But is less "twitchy"

Kind regards
Bernd

Re: Tri-state switch control

Posted: Mon Jul 31, 2023 2:43 pm
by stam
Bernd, as always thank you.
I don't understand why either but it works ;)
Currently this is set as a 2:1 width/height ratio but will add a custom prop that can modify this to produce more elongated controls (ratio of 2.5 or 3 seems good for this) and will post on Sample Stacks/LiveCodeShare.

And when I get time, sparse as it is, I'll look into making this into one of the new script widgets, seems like a good candidate for this...

Thanks once again,
Stam

Re: Tri-state switch control

Posted: Thu Aug 03, 2023 2:35 am
by stam
bn wrote:
Mon Jul 31, 2023 11:51 am
Don't ask me why, it has to do with the margins and all. Do not have the time to really understand this right now.
But is less "twitchy"
Hi Bernd, just a quick note to say that building this as a script widget was both quick and fun - and no longer any need to control aspect ratio (and no twitch ;) ) - aspect ratio changes as it should do with resizing and it's much smoother now.
And more importantly both the value of the switch and the colours can be set in the IDE's property inspector (this does require LC10 DP5 or higher to work though...)

I've shared the source code and a compiled extension under MIT licence here: https://github.com/stam66/tristate

Best regards
Stam