From 0a4adfe9cd45e977f7ee6a917a4e46e0623abef6 Mon Sep 17 00:00:00 2001 From: syeyoung Date: Wed, 25 Jan 2023 17:54:09 +0900 Subject: - Text delegate to rich text Signed-off-by: syeyoung --- .../kr/syeyoung/dungeonsguide/mod/guiv2/elements/Text.java | 2 +- .../dungeonsguide/mod/guiv2/elements/richtext/RichText.java | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'mod/src/main/java') diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Text.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Text.java index bd04ab42..341a0282 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Text.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Text.java @@ -48,7 +48,7 @@ public class Text extends AnnotatedExportOnlyWidget { @Export(attributeName = "text") public final BindableAttribute text = new BindableAttribute<>(String.class, ""); - private final ParentDelegatingTextStyle textStyle = new ParentDelegatingTextStyle(); + private final ParentDelegatingTextStyle textStyle = ParentDelegatingTextStyle.ofDefault(); private final RichText richText = new RichText(new TextSpan(textStyle, ""), BreakWord.WORD, true,RichText.TextAlign.LEFT); @Override public List build(DomElement buildContext) { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/richtext/RichText.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/richtext/RichText.java index 614158fe..cc651a9d 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/richtext/RichText.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/richtext/RichText.java @@ -159,15 +159,19 @@ public class RichText extends Widget implements Layouter, Renderer { public double getMaxIntrinsicHeight(DomElement buildContext, double width) { LinkedList flatTextSpans = new LinkedList<>(); rootSpan.flattenTextSpan(flatTextSpans::add); - double remaining = width; + double remaining = width == 0 ? Double.POSITIVE_INFINITY : width; double maxHeight = 0; double sumHeight = 0; while (!flatTextSpans.isEmpty()) { FlatTextSpan first = flatTextSpans.pollFirst(); - BrokenWordData brokenWordData = first.breakWord(remaining, width, breakWord); + BrokenWordData brokenWordData = first.breakWord(remaining, width == 0 ? Double.POSITIVE_INFINITY : width, breakWord); remaining -= brokenWordData.getFirstWidth(); + if (brokenWordData.getFirst().value.length == 0 && first.value.length != 0 && remaining == width) { + return 0; + } + maxHeight = Math.max(maxHeight, first.getHeight()); if (brokenWordData.getSecond() != null) { @@ -175,7 +179,7 @@ public class RichText extends Widget implements Layouter, Renderer { } if (brokenWordData.isBroken()) { - remaining = width; + remaining = width == 0 ? Double.POSITIVE_INFINITY : width; sumHeight += maxHeight; maxHeight = 0; } -- cgit