From 8f62f06e3ab03e24e23a1b7f369ae31d701e736b Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Sat, 17 Aug 2019 10:28:00 -0500 Subject: [PATCH] resizing fixes --- src/jexer/TComboBox.java | 8 +++++--- src/jexer/TList.java | 25 +++++++++++++++++++++++++ src/jexer/TText.java | 25 +++++++++++++++++++++++++ src/jexer/ttree/TTreeViewWidget.java | 19 +++++++++++++++++++ 4 files changed, 74 insertions(+), 3 deletions(-) diff --git a/src/jexer/TComboBox.java b/src/jexer/TComboBox.java index 4abdd6f..fe1366d 100644 --- a/src/jexer/TComboBox.java +++ b/src/jexer/TComboBox.java @@ -216,13 +216,15 @@ public class TComboBox extends TWidget { // ------------------------------------------------------------------------ /** - * Override TWidget's width: we can only set width at construction time. + * Override TWidget's width: we need to set child widget widths. * - * @param width new widget width (ignored) + * @param width new widget width */ @Override public void setWidth(final int width) { - // Do nothing + field.setWidth(width - 3); + list.setWidth(width); + super.setWidth(width); } /** diff --git a/src/jexer/TList.java b/src/jexer/TList.java index a962f7c..253e409 100644 --- a/src/jexer/TList.java +++ b/src/jexer/TList.java @@ -327,6 +327,31 @@ public class TList 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); + } + /** * Resize for a new width/height. */ diff --git a/src/jexer/TText.java b/src/jexer/TText.java index 4791fdc..e47a162 100644 --- a/src/jexer/TText.java +++ b/src/jexer/TText.java @@ -173,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. */ diff --git a/src/jexer/ttree/TTreeViewWidget.java b/src/jexer/ttree/TTreeViewWidget.java index 9ffb724..080a200 100644 --- a/src/jexer/ttree/TTreeViewWidget.java +++ b/src/jexer/ttree/TTreeViewWidget.java @@ -37,6 +37,7 @@ import jexer.TWidget; import jexer.bits.StringUtils; import jexer.event.TKeypressEvent; import jexer.event.TMouseEvent; +import jexer.event.TResizeEvent; import static jexer.TKeypress.*; /** @@ -110,6 +111,24 @@ public class TTreeViewWidget extends TScrollableWidget { // Event handlers --------------------------------------------------------- // ------------------------------------------------------------------------ + /** + * Handle window/screen resize events. + * + * @param event resize event + */ + @Override + public void onResize(final TResizeEvent event) { + super.onResize(event); + + if (event.getType() == TResizeEvent.Type.WIDGET) { + treeView.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, + getWidth() - 1, getHeight() - 1)); + return; + } else { + super.onResize(event); + } + } + /** * Handle mouse press events. * -- 2.27.0