Placing a NewtCanvasJFX within other JavaFX layout elements

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Placing a NewtCanvasJFX within other JavaFX layout elements

leeca
The NewtCanvasJFX canvas all seem to want to render from the origin the underlying window region.  It does not seem to respect placements with a y-offset.  (I suspect x-offsets are also a problem, but that does not affect my use case.)

When a NewtCanvasJFX is placed as the only child of a Group, the OGL render appears correctly in the screen space.

If the NewtCanvasJFX is a second or third child of a VBOX, the canvas appears to ignore the offset.  It renders from the origin (0, 0) of the underlying region (e.g. Stage).   This over-writes the top elements in the VBox, and leaves a large gap between the bottom of the canvas and bottom element of the VBox.

The code to implement this is based on JavaFx et JOGL (https://gouessej.wordpress.com/2020/04/05/javafx-et-jogl-fonctionnent-ensemble-javafx-and-jogl-work-together/).  This demo refactors that example for Gradle and Java 17 modules in git repository (https://github.com/leeca/JavaFx_JOGL).  Branch [vbox-canvas] provides the variations for the demo code.

The code in block 1 sets up a simple VBox with three components in a vertical stack.  Running this example produces the output in image 1.

<code>
  @Override
  public void start(Stage stage) {
    Platform.setImplicitExit(true);
    final Group group = new Group();
    Scene scene = new Scene(group, 800, 600);
    stage.setScene(scene);
    stage.show();

    jogl = new JoglModule();
    group.getChildren().add(asVBox());
    jogl.demoDisplay();
    jogl.start();
  }

  private Node asVBox() {
    VBox result = new VBox();
    result.getChildren().add(new Label("Top"));
    result.getChildren().add(new Label("Middle"));
    Canvas canvas = jogl.prepareCanvas();
    // result.getChildren().add(canvas);
    result.getChildren().add(new Label("Bottom"));
    return result;
  }
</code>

VBox with 3 Labels


If we uncomment the addition of the canvas in asVbox(),  the rendering is completely different.  The Top and Middle elements of the VBox are being overwritten with the JOGL output, and the gap between the canvas frame and the Bottom element is larger than expected.  That gap is comparable to the ignored offset from the Top and Middle elements.

VBox with NewtCanvasJFX

I suspect the NEWT window is ignoring the offsets, and places itself at the origin of the “primary” window’s client space.  For this example, that happens to be a Scene.

In another use case, the NEWT window is placed in a Tabbed client area.  But other layout placement (e.g. BorderPane) within the tabbed window’s client area is ignored.  Even directly setting the layout Y in a custom wrapper Pane fails to modify the placement of the JOGL canvas.  But those are more complex examples.

Is there a kind of JOGL container that has hard-offsets that make a better wrapper for the NewtCanvasJFX?
Reply | Threaded
Open this post in threaded view
|

Re: Placing a NewtCanvasJFX within other JavaFX layout elements

gouessej
Administrator
Hello

I rarely use OpenJFX, sorry. What you describe at the beginning seems to be a bug or at least a limitation.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Placing a NewtCanvasJFX within other JavaFX layout elements

leeca
I'd be happy to investigate more, file a bug, even dig in and help debug.  There are a couple of places in the NEWT code that seem to have zero offsets, but some of them must be correct.

In order to file a bug, I'll need to have a Bugzilla account.

Some guidance with the NEWT code would help me debug.  Especially any insights into screen location handling.
Reply | Threaded
Open this post in threaded view
|

Re: Placing a NewtCanvasJFX within other JavaFX layout elements

gouessej
Administrator
Send me an email and I'll create a bugzilla account for you.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Placing a NewtCanvasJFX within other JavaFX layout elements

gouessej
Administrator
In reply to this post by leeca
I created your bugzilla account, I received your emails but you don't seem to receive mine :s I sent you your login and your password in separate messages.
Julien Gouesse | Personal blog | Website