Skip to content

Commit

Permalink
defer the update request slightly
Browse files Browse the repository at this point in the history
refs #446
  • Loading branch information
tomsontom committed Jan 24, 2022
1 parent 11b912f commit 3d5e2e7
Showing 1 changed file with 18 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()) {
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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);
// }
// }
}
}

Expand Down Expand Up @@ -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);
});
}
});
}
Expand All @@ -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));
Expand Down

0 comments on commit 3d5e2e7

Please sign in to comment.