Skip to content

Commit

Permalink
Fixed wrapping text issue with Labeled and set content biais
Browse files Browse the repository at this point in the history
  • Loading branch information
salmonb committed Nov 3, 2023
1 parent cf54b5e commit df75d42
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package javafx.scene.control;

import dev.webfx.kit.mapper.peers.javafxgraphics.markers.*;
import dev.webfx.kit.util.properties.FXProperties;
import javafx.beans.property.*;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
Expand All @@ -10,8 +13,6 @@
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.TextAlignment;
import dev.webfx.kit.mapper.peers.javafxgraphics.markers.*;
import dev.webfx.kit.util.properties.FXProperties;
/**
* @author Bruno Salmon
*/
Expand Down Expand Up @@ -156,6 +157,14 @@ public final boolean isWrapText() {
return wrapText == null ? false : wrapText.getValue();
}

/**
* If wrapText is true, then contentBias will be HORIZONTAL, otherwise it is null.
* @return orientation of width/height dependency or null if there is none
*/
@Override public Orientation getContentBias() {
return isWrapText()? Orientation.HORIZONTAL : null;
}

/**
* Specifies the behavior to use if the text of the {@code Labeled}
* exceeds the available space for rendering the text.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public abstract class LabeledSkinBase<C extends Labeled, B extends BehaviorBase<
*/
LabeledText text;
final Text noWrappingText = new Text(); { noWrappingText.setVisible(false); } // WebFX addition (to remove if possible)
private double noWrappingTextWidth;

/**
* Indicates that the text content is invalid and needs to be updated.
Expand Down Expand Up @@ -538,7 +539,7 @@ private void removeMnemonic() {
private void updateWrappingWidth() {
final Labeled labeled = getSkinnable();
text.setWrappingWidth(0d);
if (labeled.isWrapText()) {
if (labeled.isWrapText() /* WebFX addition: */ && wrapWidth < noWrappingTextWidth) { // we don't set the wrapping width if not necessary due to lack of double precision in HTML (rounding to inferior pixel can cause an unwanted text wrap)
// Note that the wrapping width needs to be set to zero before
// getting the text's real preferred width.
double w = Math.min(text.prefWidth(-1), wrapWidth);
Expand Down Expand Up @@ -695,7 +696,10 @@ private double computeTextWidth(Font font, String text, double wrappingWidth) {
return 0;
/*if (wrappingWidth <= 0) // Commented because it doesn't include the extra space around the text like in the html node
return WebFxKitLauncher.measureText(text, font).getWidth();*/
return getTextToMeasure(font, text, wrappingWidth).prefWidth(-1);
double textWidth = getTextToMeasure(font, text, wrappingWidth).prefWidth(-1);
if (wrappingWidth == 0)
noWrappingTextWidth = textWidth;
return textWidth;
}

private double computeTextHeight(Font font, String text, double wrappingWidth, double lineSpacing, TextBoundsType boundsType) {
Expand Down

0 comments on commit df75d42

Please sign in to comment.