determining which widget is focused object

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
rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

determining which widget is focused object

Post by rodneyt » Wed Jun 30, 2021 2:36 am

Assume following scenario. User has two browser widgets on a card. User could interact (scroll, click, move pointer within) in either widget. What is the best way to determine which widget is focus of user interaction?

It's not possible to use standard Livecode object events - e.g. I understand that the focusedObject and mousewithin don't work with widgets.

I have tried surrounding the widget with a rectangle graphic object. Even if the rect is in front (bring to front) it will not receive mousewithin events if there is a widget within the bounds of the rectangle. I.e. the widget will grab all events.

Can someone tell me the best way to determine if a widget has the user's focus (other than perhaps polling the mouse position).

Possible solution might be to monitor browser widget events as a proxy, and as soon as any event is detected you'd be able to tell the widget is focused. But this would still have some lag so is not ideal.

Surely there is a better way - interested in thoughts from others who are using browser widget.

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: determining which widget is focused object

Post by Bernard » Wed Jun 30, 2021 2:51 pm

MouseMove and MouseEnter work but only when using the pointer tool, not the browse tool.

on mouseMove
put the long id of target()
end mouseMove

MouseDown etc. appear not to register with the widget.

But if you place the mouse over the widget and ctrl+m/cmd+m to get the MB to focus then

put mousecontrol()

shows that the engine knows the mouse is within the widget. It's all a bit rum.

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

Re: determining which widget is focused object

Post by stam » Wed Jun 30, 2021 6:10 pm

if trying to determine which object is clicked on, the target will work with widgets (typically in the container of the widget i'll have a mouseDown handler that tests for the name of the target)
On other occasions i've checked the location of the mouse (eg if the mouseLoc is within the rect of widget myWidget)
At least this has helped with some stuff i've used it with, not sure if that helps you as such...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9647
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: determining which widget is focused object

Post by dunbarx » Wed Jun 30, 2021 7:08 pm

Even if the rect is in front (bring to front) it will not receive mousewithin events if there is a widget within the bounds of the rectangle. I.e. the widget will grab all events.
Is this so? I have never used a widget, but how does LC know there is one underneath another standard control? Do widgets always exist on top of everything, regardless of the layer? In other words, do widgets even have a layer property?

Craig

rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

Re: determining which widget is focused object

Post by rodneyt » Thu Jul 01, 2021 2:18 am

Bernard wrote:
Wed Jun 30, 2021 2:51 pm
MouseMove and MouseEnter work but only when using the pointer tool, not the browse tool.

on mouseMove
put the long id of target()
end mouseMove

MouseDown etc. appear not to register with the widget.
Yeah - interesting, but that's really much help. When in point tool mode the widget is effectively not executing.

rodneyt
Posts: 128
Joined: Wed Oct 17, 2018 7:32 am

Re: determining which widget is focused object

Post by rodneyt » Thu Jul 01, 2021 2:21 am

dunbarx wrote:
Wed Jun 30, 2021 7:08 pm
Even if the rect is in front (bring to front) it will not receive mousewithin events if there is a widget within the bounds of the rectangle. I.e. the widget will grab all events.
Is this so? I have never used a widget, but how does LC know there is one underneath another standard control? Do widgets always exist on top of everything, regardless of the layer? In other words, do widgets even have a layer property?

Craig
Appears so. of course if you made the gap between the rect object and the widget great enough it might register mouse within before the mouse passes out of detection (ie enters the "event horizon" of the widget out of which no information escapes). But that doesn't work for me.

The only workable solution I can see is a combination of watching all browser widget events (as a proxy for detecting user interaction) and perhaps also periodically polling the mouseLoc to see if within the rect of widget. This is really not ideal. I think the engine should be able to tell the widget is focus of user interaction. Will file as a feature request. It shouldn't be this hard for a developer to figure out what the user's interaction context is.

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: determining which widget is focused object

Post by Bernard » Thu Jul 01, 2021 10:58 am

There are multiple bug reports (going back some years) about the vagaries of standard messages not being registered for widgets. One of them links to a Forum discussion on the subject, but the Forum link is broken. I remember seeing some discussion on this but couldn't remember where. I suspect it wast on the Forum.

https://quality.livecode.com/show_bug.cgi?id=17424

https://quality.livecode.com/show_bug.cgi?id=21210
https://quality.livecode.com/show_bug.cgi?id=21480
https://quality.livecode.com/show_bug.cgi?id=22719

rodneyt wrote:
Thu Jul 01, 2021 2:18 am
Bernard wrote:
Wed Jun 30, 2021 2:51 pm
MouseMove and MouseEnter work but only when using the pointer tool, not the browse tool.

on mouseMove
put the long id of target()
end mouseMove

MouseDown etc. appear not to register with the widget.
Yeah - interesting, but that's really much help. When in point tool mode the widget is effectively not executing.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”