X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTWidget.java;h=ba18989bfc43d38ea0549e42f5f20dfb8358e1ab;hb=1e71bba21116ce83e76501c2e60f85ba6113e82d;hp=5d2612b3092e961d82ad8b6beea94ce93a20d15d;hpb=90d87fca1ee987e6650b90beafc7831cbca0a457;p=fanfix.git diff --git a/src/jexer/TWidget.java b/src/jexer/TWidget.java index 5d2612b..ba18989 100644 --- a/src/jexer/TWidget.java +++ b/src/jexer/TWidget.java @@ -1243,6 +1243,25 @@ public abstract class TWidget implements Comparable { return window.getApplication().getTheme(); } + /** + * See if this widget can be drawn onto a screen. + * + * @return true if this widget is part of the hierarchy that can draw to + * a screen + */ + public final boolean isDrawable() { + if ((window == null) + || (window.getScreen() == null) + || (parent == null) + ) { + return false; + } + if (parent == this) { + return true; + } + return (parent.isDrawable()); + } + /** * Draw my specific widget. When called, the screen rectangle I draw * into is already setup (offset and clipping). @@ -1255,7 +1274,7 @@ public abstract class TWidget implements Comparable { * Called by parent to render to TWindow. Note package private access. */ final void drawChildren() { - if (window == null) { + if (!isDrawable()) { return; } @@ -1310,6 +1329,12 @@ public abstract class TWidget implements Comparable { // Draw me draw(); + if (!isDrawable()) { + // An action taken by a draw method unhooked me from the UI. + // Bail out. + return; + } + assert (visible == true); // Continue down the chain. Draw the active child last so that it @@ -1317,6 +1342,11 @@ public abstract class TWidget implements Comparable { for (TWidget widget: children) { if (widget.isVisible() && (widget != activeChild)) { widget.drawChildren(); + if (!isDrawable()) { + // An action taken by a draw method unhooked me from the UI. + // Bail out. + return; + } } } if (activeChild != null) {