Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved placeholder implementation #900

Merged
merged 1 commit into from
Jan 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.function.IntSupplier;
import java.util.function.IntUnaryOperator;

import javafx.application.Platform;
import javafx.beans.NamedArg;
import javafx.beans.binding.Bindings;
import javafx.beans.property.BooleanProperty;
Expand Down Expand Up @@ -53,7 +54,6 @@
import javafx.scene.shape.PathElement;
import javafx.scene.text.TextFlow;

import javafx.application.Platform;
import org.fxmisc.flowless.Cell;
import org.fxmisc.flowless.VirtualFlow;
import org.fxmisc.flowless.VirtualFlowHit;
Expand Down Expand Up @@ -802,21 +802,29 @@ public GenericStyledArea(
() -> getLength() == 0 && ! isFocused(),
lengthProperty(), focusedProperty()
);

placeHolderProp.addListener( (ob,oldNode,newNode) -> {
if ( oldNode != null ) {
oldNode.visibleProperty().unbind();
oldNode.layoutXProperty().unbind();
oldNode.layoutYProperty().unbind();
getChildren().remove( oldNode );
setClip( null );
}
if ( newNode != null ) {
newNode.visibleProperty().bind( showPlaceholder );
configurePlaceholder( newNode );
getChildren().add( newNode );
}
});

placeHolderProp.addListener( (ob,ov,newNode) -> displayPlaceHolder( showPlaceholder.getValue(), newNode ) );
showPlaceholder.addListener( (ob,ov,show) -> displayPlaceHolder( show, getPlaceholder() ) );
}

private Node placeholder;

private void displayPlaceHolder( boolean show, Node newNode )
{
if ( placeholder != null && (! show || newNode != placeholder) )
{
placeholder.layoutXProperty().unbind();
placeholder.layoutYProperty().unbind();
getChildren().remove( placeholder );
placeholder = null;
setClip( null );
}
if ( newNode != null && show && newNode != placeholder )
{
configurePlaceholder( newNode );
getChildren().add( newNode );
placeholder = newNode;
}
}

protected void configurePlaceholder( Node placeholder )
Expand Down Expand Up @@ -1442,9 +1450,9 @@ protected void layoutChildren() {
paging = false;
});

Node node = getPlaceholder();
if (node != null && node.isResizable() && node.isManaged()) {
node.autosize();
Node holder = placeholder;
if (holder != null && holder.isResizable() && holder.isManaged()) {
holder.autosize();
}
}

Expand Down