From 11b912f4ccd12cc10e58b7815708ae009ee193f7 Mon Sep 17 00:00:00 2001 From: Tom Schindl Date: Mon, 24 Jan 2022 10:30:21 +0100 Subject: [PATCH 1/2] adapted layout algorithm to force all items (beside the last one get their min size) --- .../org/eclipse/fx/ui/panes/SashPane.java | 74 +++++++++++++++++-- 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/modules/ui/org.eclipse.fx.ui.panes/src/main/java/org/eclipse/fx/ui/panes/SashPane.java b/modules/ui/org.eclipse.fx.ui.panes/src/main/java/org/eclipse/fx/ui/panes/SashPane.java index 5582b1e8b..9976e5c76 100644 --- a/modules/ui/org.eclipse.fx.ui.panes/src/main/java/org/eclipse/fx/ui/panes/SashPane.java +++ b/modules/ui/org.eclipse.fx.ui.panes/src/main/java/org/eclipse/fx/ui/panes/SashPane.java @@ -115,7 +115,13 @@ public StyleableProperty getStyleableProperty(SashPane node) { return getClassCssMetaData(); } + /** + * Optional interface implemented by Items so that I are layouted with their fixed size + */ public interface FixedSashItem { + /** + * @return property controlling if the item is fixed + */ public ObservableBooleanValue fixed(); } @@ -462,48 +468,100 @@ private void layoutSimple(int _x, int _y, int _w, int _h) { total += ratios[i]; } +// int spread = 0; +// boolean adjust = false; // int sashwidth = 10; //TODO sashes.length > 0 ? sashForm.SASH_WIDTH + // sashes [0].getBorderWidth() * 2 : sashForm.SASH_WIDTH; if (this.horizontal.get()) { int width = (int) (ratios[0] * (w - this.sashes.length * getSashWidth()) / total); - children.get(0).resizeRelocate(x, y, width, h); + Node node = children.get(0); + node.resizeRelocate(x, y, width, h); x += width; for (int i = 1; i < children.size() - 1; i++) { + node = children.get(i); this.sashes[i - 1].resizeRelocate(x, y, getSashWidth(), h); x += getSashWidth(); width = (int) (ratios[i] * (w - this.sashes.length * getSashWidth()) / total); - children.get(i).resizeRelocate(x, y, width, h); + node.resizeRelocate(x, y, width, h); x += width; } if (children.size() > 1) { + node = children.get(children.size() - 1); this.sashes[this.sashes.length - 1].resizeRelocate(x, y, getSashWidth(), h); x += getSashWidth(); width = w - x; - children.get(children.size() - 1).resizeRelocate(x, y, width, h); + node.resizeRelocate(x, y, width, h); } } else { + Node node = children.get(0); int height = (int) (ratios[0] * (h - this.sashes.length * getSashWidth()) / total); - children.get(0).resizeRelocate(x, y, w, height); + int delta = (int)node.minHeight(w) - height; + +// System.err.println("======> " + w + " =>" + delta); + + if( delta > 0 ) { +// adjust = true; +// spread += delta; + height += delta; + } + + node.resizeRelocate(x, y, w, height); + y += height; for (int i = 1; i < children.size() - 1; i++) { - SashChild c = (SashChild) children.get(i); + node = children.get(i); + height = (int) (ratios[i] * (h - this.sashes.length * getSashWidth()) / total); + delta = (int)node.minHeight(w) - height; + + if( delta > 0 ) { +// adjust = true; +// spread += delta; + height += delta; + } +// else { +// if( spread > 0 ) { +// System.err.println("SPREAD: " + spread); +// if( spread < Math.abs(delta) ) { +// System.err.println("ADJUST IT"); +// spread = 0; +// height -= spread; +// } else { +// spread = spread - Math.abs(delta); +// height -= Math.abs(delta); +// } +// } +// } this.sashes[i - 1].resizeRelocate(x, y, w, getSashWidth()); y += getSashWidth(); - height = (int) (ratios[i] * (h - this.sashes.length * getSashWidth()) / total); - c.resizeRelocate(x, y, w, height); + + node.resizeRelocate(x, y, w, height); y += height; } + if (children.size() > 1) { + node = children.get(children.size() - 1); this.sashes[this.sashes.length - 1].resizeRelocate(x, y, w, getSashWidth()); y += getSashWidth(); height = h - y; - children.get(children.size() - 1).resizeRelocate(x, y, w, height); + node.resizeRelocate(x, y, w, height); } + +// if( adjust ) { +// for( Node n : children ) { +// updateLayoutData(n, (int)n.getLayoutBounds().getHeight(), h); +// } +// } } } +// private void updateLayoutData(Node n, int size, int available) { +// Object data = n.getProperties().get(LAYOUT_KEY); +// ((SashFormData) data).weight = (((long) size << 16) + available - 1) / available; +// +// } + private void syncWeightProperty() { if( this.weights != null ) { try { From 3d5e2e7e59607837cd4fd1848fe0e47264bdc3a0 Mon Sep 17 00:00:00 2001 From: Tom Schindl Date: Mon, 24 Jan 2022 13:23:28 +0100 Subject: [PATCH 2/2] defer the update request slightly refs #446 --- .../org/eclipse/fx/ui/panes/SashPane.java | 55 ++++++------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/modules/ui/org.eclipse.fx.ui.panes/src/main/java/org/eclipse/fx/ui/panes/SashPane.java b/modules/ui/org.eclipse.fx.ui.panes/src/main/java/org/eclipse/fx/ui/panes/SashPane.java index 9976e5c76..55fc1e50c 100644 --- a/modules/ui/org.eclipse.fx.ui.panes/src/main/java/org/eclipse/fx/ui/panes/SashPane.java +++ b/modules/ui/org.eclipse.fx.ui.panes/src/main/java/org/eclipse/fx/ui/panes/SashPane.java @@ -18,6 +18,7 @@ import org.eclipse.jdt.annotation.NonNull; +import javafx.application.Platform; import javafx.beans.property.BooleanProperty; import javafx.beans.property.IntegerProperty; import javafx.beans.property.ObjectProperty; @@ -367,7 +368,7 @@ private void layoutWithFixedChildComplex(int _x, int _y, int _w, int _h, boolean } } - if( horizontal.get() ) { + if( this.horizontal.get() ) { w -= children.stream().filter(SashChild::isFixed).mapToDouble( s -> computeFixedWidth(s, _h)).sum(); double sashSize = getSashWidth(); @@ -412,6 +413,12 @@ private void layoutWithFixedChildComplex(int _x, int _y, int _w, int _h, boolean sashChild.resizeRelocate(x, y, w, targetHeight); y += targetHeight; } else { + + double minHeight = sashChild.minHeight(w); + if( minHeight > ratioHeight ) { + ratioHeight = (int)minHeight; + } + sashChild.resizeRelocate(x, y, w, ratioHeight); y += ratioHeight; } @@ -468,9 +475,6 @@ private void layoutSimple(int _x, int _y, int _w, int _h) { total += ratios[i]; } -// int spread = 0; -// boolean adjust = false; - // int sashwidth = 10; //TODO sashes.length > 0 ? sashForm.SASH_WIDTH + // sashes [0].getBorderWidth() * 2 : sashForm.SASH_WIDTH; if (this.horizontal.get()) { @@ -496,14 +500,10 @@ private void layoutSimple(int _x, int _y, int _w, int _h) { } else { Node node = children.get(0); int height = (int) (ratios[0] * (h - this.sashes.length * getSashWidth()) / total); - int delta = (int)node.minHeight(w) - height; - -// System.err.println("======> " + w + " =>" + delta); + int minHeight = (int)node.minHeight(w); - if( delta > 0 ) { -// adjust = true; -// spread += delta; - height += delta; + if( minHeight > height ) { + height = minHeight; } node.resizeRelocate(x, y, w, height); @@ -512,26 +512,11 @@ private void layoutSimple(int _x, int _y, int _w, int _h) { for (int i = 1; i < children.size() - 1; i++) { node = children.get(i); height = (int) (ratios[i] * (h - this.sashes.length * getSashWidth()) / total); - delta = (int)node.minHeight(w) - height; + minHeight = (int)node.minHeight(w); - if( delta > 0 ) { -// adjust = true; -// spread += delta; - height += delta; + if( minHeight > height ) { + height = minHeight; } -// else { -// if( spread > 0 ) { -// System.err.println("SPREAD: " + spread); -// if( spread < Math.abs(delta) ) { -// System.err.println("ADJUST IT"); -// spread = 0; -// height -= spread; -// } else { -// spread = spread - Math.abs(delta); -// height -= Math.abs(delta); -// } -// } -// } this.sashes[i - 1].resizeRelocate(x, y, w, getSashWidth()); y += getSashWidth(); @@ -547,12 +532,6 @@ private void layoutSimple(int _x, int _y, int _w, int _h) { height = h - y; node.resizeRelocate(x, y, w, height); } - -// if( adjust ) { -// for( Node n : children ) { -// updateLayoutData(n, (int)n.getLayoutBounds().getHeight(), h); -// } -// } } } @@ -1023,7 +1002,9 @@ public SashChild(Node c) { this.fixedSize.addListener( (ob,ol,ne) -> { Parent parent = getParent(); if( parent != null ) { - ((SashPane) parent).layoutChildren(true); + Platform.runLater( () -> { + ((SashPane) parent).layoutChildren(true); + }); } }); } @@ -1033,7 +1014,7 @@ public SashChild(Node c) { visibleProperty().addListener((ob, ol, ne) -> { Parent parent = getParent(); if( parent != null ) { - ((SashPane) parent).layoutChildren(true); + ((SashPane) parent).layoutChildren(true); } }); AnchorPane.setBottomAnchor(c, Double.valueOf(0.0));