Wednesday, July 30, 2025

Re: Mixing Elemental2 with GWT Widgets

Craig! 
Don't worry - i am following your Elemtal2 Experience closely. It is on my to-do list for quite some time now. Thanks for sharing! 
Ralph 

Craig Mitchell <mail@craig-mitchell.com> schrieb am Do. 31. Juli 2025 um 02:37:
On the off chance someone reads the above post and thinks Elemental2 isn't very good.  Just to make it clear, Elemental2 is awesome.  Just now I needed a WeakHashMap.  GWT said no.  Elemental2 said sure can, with JsWeakMap.  Love it!

On Wednesday, 30 July 2025 at 2:34:49 pm UTC+10 Craig Mitchell wrote:
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?

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-web-toolkit/7a9446c7-32b5-4a1a-84ba-2c7200901122n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-web-toolkit/CACwwWxNVUEC0PKqWH2B1RzmuncB2Nan%3DYCbRTsnh_%2BEYqk%3Djwg%40mail.gmail.com.

No comments:

Post a Comment