From 8afe8fa7d778da9682b82b6ac56f64d765f6a2d1 Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Thu, 22 Aug 2019 13:36:48 -0500 Subject: [PATCH] LayoutManager.resetSize() --- src/jexer/TRadioGroup.java | 4 ++++ src/jexer/TWidget.java | 5 +++-- src/jexer/layout/BoxLayoutManager.java | 9 +++++++++ src/jexer/layout/LayoutManager.java | 7 +++++++ src/jexer/layout/StretchLayoutManager.java | 10 ++++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/jexer/TRadioGroup.java b/src/jexer/TRadioGroup.java index 58c65e2..a82b074 100644 --- a/src/jexer/TRadioGroup.java +++ b/src/jexer/TRadioGroup.java @@ -190,6 +190,10 @@ public class TRadioGroup extends TWidget { TRadioButton button = new TRadioButton(this, buttonX, buttonY, label, getChildren().size() + 1); + if (getParent().getLayoutManager() != null) { + getParent().getLayoutManager().resetSize(this); + } + // Default to the first item on the list. activate(getChildren().get(0)); diff --git a/src/jexer/TWidget.java b/src/jexer/TWidget.java index 60bc3e4..e94fed2 100644 --- a/src/jexer/TWidget.java +++ b/src/jexer/TWidget.java @@ -935,8 +935,9 @@ public abstract class TWidget implements Comparable { this.x = x; this.y = y; - this.width = width; - this.height = height; + // Call the functions so that subclasses can choose how to handle it. + setWidth(width); + setHeight(height); if (layout != null) { layout.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, width, height)); diff --git a/src/jexer/layout/BoxLayoutManager.java b/src/jexer/layout/BoxLayoutManager.java index c3d1280..8e7a01e 100644 --- a/src/jexer/layout/BoxLayoutManager.java +++ b/src/jexer/layout/BoxLayoutManager.java @@ -120,6 +120,15 @@ public class BoxLayoutManager implements LayoutManager { layoutChildren(); } + /** + * Reset a child widget's original/preferred size. + * + * @param child the widget to manage + */ + public void resetSize(final TWidget child) { + // NOP + } + // ------------------------------------------------------------------------ // BoxLayoutManager ------------------------------------------------------- // ------------------------------------------------------------------------ diff --git a/src/jexer/layout/LayoutManager.java b/src/jexer/layout/LayoutManager.java index bfa64a0..5dbd1e8 100644 --- a/src/jexer/layout/LayoutManager.java +++ b/src/jexer/layout/LayoutManager.java @@ -59,4 +59,11 @@ public interface LayoutManager { */ public void remove(final TWidget child); + /** + * Reset a child widget's original/preferred size. + * + * @param child the widget to manage + */ + public void resetSize(final TWidget child); + } diff --git a/src/jexer/layout/StretchLayoutManager.java b/src/jexer/layout/StretchLayoutManager.java index 0ae7dff..3dea86a 100644 --- a/src/jexer/layout/StretchLayoutManager.java +++ b/src/jexer/layout/StretchLayoutManager.java @@ -126,6 +126,16 @@ public class StretchLayoutManager implements LayoutManager { layoutChildren(); } + /** + * Reset a child widget's original/preferred size. + * + * @param child the widget to manage + */ + public void resetSize(final TWidget child) { + // For this layout, adding is the same as replacing. + add(child); + } + // ------------------------------------------------------------------------ // StretchLayoutManager --------------------------------------------------- // ------------------------------------------------------------------------ -- 2.27.0