I've switched to use Elemental2 for a few things. The rest of my app still uses the standard GWT widgets.
I can bind directly to the Elemental2 elements from the GWT UI Binder, however, if I programatically want to add an Elemental2 element to a GWT Widget, there doesn't seem to be a direct way to do this.
Eg: How would you add the Elemental2 HTMLCanvasElement, to a GWT SimplePanel using its setWidget method?
To work around this, I created an "Elemental2Widget":
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.Widget;
import jsinterop.base.Js;
public class Elemental2Widget<T> extends Widget {
public Elemental2Widget(T elemental2Widget) {
Element element = Js.cast(elemental2Widget);
setElement(element);
}
public T getElemental2Widget() {
return Js.cast(getElement());
}
}
Now I can call it like this:
simplePanel.setWidget(new Elemental2Widget<>(htmlCanvasElement));
Is this how people mix Elemental2 with GWT widgets? Or is there a better way?