X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTText.java;h=e47a162c6f5fe7a38ca02381320d393bdace1a1e;hb=8f62f06e3ab03e24e23a1b7f369ae31d701e736b;hp=60f0e585c9d4faede83c681011a97d8a27a4bbf0;hpb=a69ed767c9c07cf35cf1c5f7821fc009cfe79cd2;p=fanfix.git diff --git a/src/jexer/TText.java b/src/jexer/TText.java index 60f0e58..e47a162 100644 --- a/src/jexer/TText.java +++ b/src/jexer/TText.java @@ -33,6 +33,7 @@ import java.util.LinkedList; import java.util.List; import jexer.bits.CellAttributes; +import jexer.bits.StringUtils; import jexer.event.TKeypressEvent; import jexer.event.TMouseEvent; import static jexer.TKeypress.kbDown; @@ -172,6 +173,31 @@ public class TText extends TScrollableWidget { // TScrollableWidget ------------------------------------------------------ // ------------------------------------------------------------------------ + /** + * Override TWidget's width: we need to set child widget widths. + * + * @param width new widget width + */ + @Override + public void setWidth(final int width) { + super.setWidth(width); + hScroller.setWidth(getWidth() - 1); + vScroller.setX(getWidth() - 1); + } + + /** + * Override TWidget's height: we need to set child widget heights. + * time. + * + * @param height new widget height + */ + @Override + public void setHeight(final int height) { + super.setHeight(height); + hScroller.setY(getHeight() - 1); + vScroller.setHeight(getHeight() - 1); + } + /** * Draw the text box. */ @@ -184,7 +210,7 @@ public class TText extends TScrollableWidget { int topY = 0; for (int i = begin; i < lines.size(); i++) { String line = lines.get(i); - if (hScroller.getValue() < line.length()) { + if (hScroller.getValue() < StringUtils.width(line)) { line = line.substring(hScroller.getValue()); } else { line = ""; @@ -323,7 +349,7 @@ public class TText extends TScrollableWidget { * @param line new line to add */ public void addLine(final String line) { - if (text.length() == 0) { + if (StringUtils.width(text) == 0) { text = line; } else { text += "\n\n"; @@ -338,8 +364,8 @@ public class TText extends TScrollableWidget { private void computeBounds() { maxLineWidth = 0; for (String line : lines) { - if (line.length() > maxLineWidth) { - maxLineWidth = line.length(); + if (StringUtils.width(line) > maxLineWidth) { + maxLineWidth = StringUtils.width(line); } }