LayoutManager.resetSize()
authorKevin Lamonte <kevin.lamonte@gmail.com>
Thu, 22 Aug 2019 18:36:48 +0000 (13:36 -0500)
committerKevin Lamonte <kevin.lamonte@gmail.com>
Thu, 22 Aug 2019 18:36:48 +0000 (13:36 -0500)
src/jexer/TRadioGroup.java
src/jexer/TWidget.java
src/jexer/layout/BoxLayoutManager.java
src/jexer/layout/LayoutManager.java
src/jexer/layout/StretchLayoutManager.java

index 58c65e2b11eb679a4110802cde00ea90d06e3366..a82b074f8ce9a1c4fe6de462433b8d4124507b91 100644 (file)
@@ -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));
 
index 60bc3e4a618c0cce09d84cbdbedfdc200da39906..e94fed25077c68ca763b8dc90e76b98d36898469 100644 (file)
@@ -935,8 +935,9 @@ public abstract class TWidget implements Comparable<TWidget> {
 
         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));
index c3d12802b1e72d24346cd81f5353aa917ac075f6..8e7a01e39231913870469d3c8b26653a6e78690b 100644 (file)
@@ -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 -------------------------------------------------------
     // ------------------------------------------------------------------------
index bfa64a098463e6ffcc46ce5f831f1476b278a5a2..5dbd1e8432401df45f1a45ef34e42898c717d58b 100644 (file)
@@ -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);
+
 }
index 0ae7dff396be3ad685619f70d0a20dcea50cde31..3dea86ab990872544cf55d247d3ed6784707b302 100644 (file)
@@ -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 ---------------------------------------------------
     // ------------------------------------------------------------------------