Bug in switch button widget?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

Bug in switch button widget?

Post by SWEdeAndy »

Hi all,

I just noticed something odd with the switch button widget:
The hiliteChanged command is triggered even if the hilite did not change, if you click outside the visible part of the switch button, but within the rect of the widget.

Example:

Code: Select all

on hiliteChanged
   put the hilited of me after msg
end hiliteChanged
If you click within the widget rect, but outside the actual button, it still executes the script, but without the switch flipping.

This causes errors if you only want something to happen if the user actually flips the switch (which is kind of the point with it). Of course, a workaround is to put things like ”if the hilite of me is true then…”. But there are still scenarios when that would not work - try this one for example:

Code: Select all

on hiliteChanged
   if the hilite of me is true then add 1 to fld 1
   else add -1 to fld 1
end hiliteChanged
Poke around the switch button and you get funny results…

Reducing the size of the widget rect doesn’t help, as the visual part then shrinks too, so the margin is constant. And there’s no margin property to set.

I’ve tried this in MacOS 10.13.4, Business 9.0.0 and Indy 8.1.9, both in IDE and standalone, and it’s the same. I haven’t tried in mobile (and touching the narrow area around the button without flipping it would be harder in mobile, so maybe less of a problem there).

I can figure out various scripting solutions to deal with this problem, so I’m not asking for advice on that.
I just wonder if this is a bug and if it’s known?

/Andreas
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
sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

Re: Bug in switch button widget?

Post by sphere »

Just quickly checked.
Indeed it reacts when pushing in the rect but not on the button itself, but it always answers false.

Also strange is, but i did not check and maybe it is the same, if you have a custom button of which the rect is bigger or it has a strnage form not filling the rect. And the part that is not filling is transparent, then the button is also not triggered, but maybe it also gives false. If that is so, then this is the way it works i guess and not a bug.
I always use: if the Hilite of me is true (or false) then blablabla
SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 328
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: Bug in switch button widget?

Post by SWEdeAndy »

Well, the hilite of me returns "false" if the hilite is false, "true" if it's true.

But a command called hiliteChanged should not execute its code unless the hilite did actually change, in my opinion. So I'd call this a bug. If it's not then I hope someone can explain the logic to me. :?

It's kind of a useless command if I have to script some hilite checking anyway, because the 'Changed' part can't be trusted.
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
bwmilby
Posts: 463
Joined: Wed Jun 07, 2017 5:37 am
Contact:

Re: Bug in switch button widget?

Post by bwmilby »

I would suggest making a bug report to Bugzilla. This looks like something I could take a look at fixing next week if nobody beats me to it. Pleas post the report here so I can track it.
sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

Re: Bug in switch button widget?

Post by sphere »

SWEdeAndy wrote: Fri Apr 13, 2018 12:58 pm Well, the hilite of me returns "false" if the hilite is false, "true" if it's true.
Yes indeed but clicking in the rect but not on the switch itself returns a false, so that part does not seem a bug to me
But a command called hiliteChanged should not execute its code unless the hilite did actually change, in my opinion. So I'd call this a bug. If it's not then I hope someone can explain the logic to me. :?
If this is the case when clicking in the rect but not the switch itself, then i agree. The hilite did not change, the widget only returned false
SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 328
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: Bug in switch button widget?

Post by SWEdeAndy »

Yes indeed but clicking in the rect but not on the switch itself returns a false, so that part does not seem a bug to me
Well, it returns the state of the hilite correctly: if the state of the switch is on, i.e. the hilite is true, then clicking in the rect outside the button returns true (if the script has the line "put the hilite of me").

But the problem, as we seem to agree, is that it shouldn't return anything, since the hilite didn't change.

I'll try to file a bug report - it's a first for me, so I'll try to figure out how to do that... :D
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
sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

Re: Bug in switch button widget?

Post by sphere »

ah yes you're right.

Let's see what the devs come up with, once you file the bug report.
SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 328
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: Bug in switch button widget?

Post by SWEdeAndy »

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
bwmilby
Posts: 463
Joined: Wed Jun 07, 2017 5:37 am
Contact:

Re: Bug in switch button widget?

Post by bwmilby »

PR submitted against develop-9.0
https://github.com/livecode/livecode/pull/6486
sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

Re: Bug in switch button widget?

Post by sphere »

Great! THX
SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 328
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: Bug in switch button widget?

Post by SWEdeAndy »

Cool, thanks bwmilby! :D
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
Post Reply