Adding a ClickHandler to the background of a FlowPanel in GWT - gwt

I'm new to GWT, and my search queries didn't turn up what I'm looking for, but I'm afraid I'm not phrasing them correctly, so I apologize if this is a simple/duplicate question.
I'm currently trying to figure out how to add a ClickHandler to the area of a FlowPanel that is not occupied by a specific Widget. I know that I can simply add a ClickHandler by wrapping the entire FlowPanel inside a FocusPanel, but that then triggers when any of the widgets inside the flow panel are clicked on. The widgets are typically composite widgets with complicated structures themselves.
My ultimate goal here is to process a click when a user clicks in empty space, but allow the individual widgets to have their own unique click handlers if the user clicks on a specific widget.
Any suggestions?
Thanks!

You have two options.
(A) Add the same click handler to all of your widgets, and then inside onClick perform different actions based on which widget was the source of a click.
(B) Get the mouse position (from ClickEvent), and then iterate through child widgets to see if this mouse position falls inside one of them.

Related

Flutter Draggable widget that can be clicked or dragged to move to DragTarget

I am trying to create a small test that allows a user to click or drag a Draggable or Container to move it to a DragTarget. The best example I can think of for this would be how Duolingo allows for their users to click a word and automatically move it to the first location of a sentence to a certain target, then the app checks if the sequence is correct.
For those who are unfamiliar with how Duolingo uses this, I'll explain what I would like to do here. I would like to have 3 Draggables (call them A, B, and C), and 3 DragTargets. When a letter is clicked it will move to the leftmost empty DragTarget, however, the letter could also be dragged to the location as well. If a Draggable is clicked while inside the DragTarget it will return to its original location, or it could be dragged to switch spots with another filled DragTarget.
I hope that explained my goal well. If not please ask for more details and I can try to edit and provide them.
Thanks
What could work is to use the onDragStarted: () {} voidCallback which will be similar to a button click. You could use A Stack() and wrap the Draggables with an AnimatedPositioned() widget. To which field to move can propably be determined using If statements.

Is it possible to drag ReorderableListView items to another ReorderableListView?

I'm trying to drag an item from one ReorderableListView into another ReorderableListView.
It seems it is only possible by using a regular ListView with Dragable and DragTarget widgets and without the look and feel of a ReorderableListView.
Am I right or is there a way?
This is a bit delayed but I'm leaving this answer for anyone else that landed here after searching:
Consider using this flutter package:
https://pub.dev/packages/drag_and_drop_lists
Features
Reorder elements between multiple lists
Reorder lists
Drag and drop new elements from outside of the lists
Vertical or horizontal layout
Use with drag handles, long presses, or short presses
Expandable lists
Can be used in slivers
Prevent individual lists/elements from being able to be dragged
Easy to extend with custom layouts

in GWT, How to loop Gui Widget inside a panel?

Let say, I got a VerticalPanel that have some widgets (label, button, ...) that were added into it. How can i loop that VerticalPanel & access the widgets in it?
Well you can use iterator,As i explained in the question How get all widgets of certain type?.
Iterator<Widget> widgets= vpanel.iterator();
Point to remember:
This method only gives the widgets added to the panel.
You have to iterate over child panels also(if its contains).
Or otherwise pick #Manolo's answer from same thread,If you are using GWT third party library GQuery.

why GWT Cell widgets are fater?

I wanted to know how cell widgets are faster compared normal (old) GWT widgets?
I have gone through the gwt article
Developer's Guide - Cell Widgets
It says
A cell widget renders its user interface as an HTML string, using innerHTML instead of traditional DOM manipulation
Can anyone please explain the above? and How?
In a normal GWT Grid you have to add each Widget separately, which means the browser can not optimize this in any way. Each widget you add also has its own event handler.
So you will create at least one DOM Element per Widget you add and append it into the grid.
CellWidgets first render all childs into a String which is then added to the DOM, by calling setInnerHTML (the browser can optimize this call and add all childs in a batch) and the event handling is only done once by the CellWidget.

How do you get GWT 2.0 to accept clicks on two different Widgets added to a LayoutPanel?

Using GWT 2.0 I have an entry point that adds two Widgets to a LayoutPanel which in turn is added to the RootLayoutPanel. The Widgets both handle click events and have click events registered to them. The problem is that only the last widget added to the LayoutPanel can actually be clicked. Switch the order in which the widgets are added switches the widget that works. Add mroe widgets and still the only you can click is the last one added to the LayoutPanel.
Any idea why this is? Is there any reasoning behind the behaviour, or have I missunderstood what is happening under the covers? How do I gat all widgets in the LayoutPanel to accept events? Should I be using another panel class?
I'm not too bothered if the LayoutPanel prevents anything below it from being clicked, but want all Widgets added to it to be clickable.
Stupid Boy! (said in the voice of Captain Mainwaring)
There is no problem having two Widgets on a LayoutPanel accepting clicks. But if you adjust the Widgets' size by manipulating their elements' styles directly then the containing element created by the LayoutPanel will still cover the whole screen. In effect the last Widget added always covered everything else.
GWT school: D- Must try harder. Easily distracted...