Tri-state switch control

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

Tri-state switch control

Post by stam » Mon Jul 31, 2023 5:13 am

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.
Attachments
sk3Switch.livecode.zip
(3.67 KiB) Downloaded 80 times
tri-state.jpg

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

Re: Tri-state switch control

Post by bn » Mon Jul 31, 2023 11:51 am

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

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

Re: Tri-state switch control

Post by stam » Mon Jul 31, 2023 2:43 pm

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

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

Re: Tri-state switch control

Post by stam » Thu Aug 03, 2023 2:35 am

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

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”