@@ -20,7 +20,6 @@ public class PanelRendering extends Panel {
2020 public Map <String , String > layersStatus = new HashMap <>();
2121 public String [] layers ;
2222 public int layerIdx = 0 ;
23- public SkijaLayer layer ;
2423
2524 // Layer status displayed on the right side from the layer name
2625 public static final String CHECKED = "+" ;
@@ -48,57 +47,40 @@ public void bumpCounter(String reason) {
4847 }
4948
5049 public void changeLayer () {
51- if (layer != null ) {
52- layer .close ();
53- layer = null ;
54- }
55-
5650 int attemptsCount = layers .length ;
5751
58- while (layer == null && attemptsCount > 0 ) {
52+ while (attemptsCount > 0 ) {
5953 attemptsCount -= 1 ;
6054 String layerName = layers [layerIdx ];
6155 String className = "io.github.humbleui.jwm.examples." + layerName ;
6256
6357 try {
64- layer = (SkijaLayer ) Example .class .forName (className ).getDeclaredConstructor ().newInstance ();
58+ SkijaLayer layer = (SkijaLayer ) Example .class .forName (className ).getDeclaredConstructor ().newInstance ();
6559 layer .attach (window );
60+ break ;
6661 } catch (Exception e ) {
6762 System .err .println ("Failed to create layer " + className );
6863 e .printStackTrace ();
69- layer = null ;
7064 layersStatus .put (layerName , FAILED ); // Update layer status
7165 nextLayerIdx ();
7266 }
7367 }
7468
75- if (layer == null )
69+ if (window . _layer == null )
7670 throw new RuntimeException ("No available layer to create" );
7771
7872 layersStatus .put (layers [layerIdx ], CHECKED ); // Mark layer as checked
79- layer .reconfigure ();
80- layer .resize (window .getContentRect ().getWidth (), window .getContentRect ().getHeight ());
8173 }
8274
8375 @ Override
8476 public void accept (Event e ) {
85- if (e instanceof EventWindowScreenChange ) {
86- layer .reconfigure ();
87- accept (new EventWindowResize (window .getWindowRect ().getWidth (),
88- window .getWindowRect ().getHeight (),
89- window .getContentRect ().getWidth (),
90- window .getContentRect ().getHeight ()));
91- } else if (e instanceof EventWindowResize ee ) {
92- layer .resize (ee .getContentWidth (), ee .getContentHeight ());
93- } else if (e instanceof EventKey ee && ee .isPressed ()) {
77+ if (e instanceof EventKey ee && ee .isPressed ()) {
9478 Key key = ee .getKey ();
9579 boolean modifier = ee .isModifierDown (Example .MODIFIER );
9680 if (Key .L == key && modifier ) {
9781 nextLayerIdx ();
9882 changeLayer ();
9983 }
100- } else if (e instanceof EventWindowCloseRequest ) {
101- layer .close ();
10284 }
10385 }
10486
0 commit comments