@@ -27,7 +27,7 @@ public class ListWidget<I extends IWidget, W extends ListWidget<I, W>> extends A
2727 private ScrollData scrollData ;
2828 private IIcon childSeparator ;
2929 private final IntList separatorPositions = new IntArrayList ();
30- private boolean collapseDisabledChild = false ;
30+ private boolean collapseDisabledChild = true ;
3131
3232 public ListWidget () {
3333 super (null , null );
@@ -85,6 +85,9 @@ public void layoutWidgets() {
8585 }
8686 this .separatorPositions .add (p );
8787 p += separatorSize ;
88+ if (isValid ()) {
89+ widget .flex ().applyPos (widget );
90+ }
8891 }
8992 getScrollData ().setScrollSize (p + getArea ().getPadding ().getEnd (axis ));
9093 }
@@ -94,6 +97,13 @@ public boolean shouldIgnoreChildSize(IWidget child) {
9497 return this .collapseDisabledChild && !child .isEnabled ();
9598 }
9699
100+ @ Override
101+ public void onChildChangeEnabled (IWidget child , boolean enabled ) {
102+ if (this .collapseDisabledChild ) {
103+ ILayoutWidget .super .onChildChangeEnabled (child , enabled );
104+ }
105+ }
106+
97107 @ Override
98108 public boolean addChild (I child , int index ) {
99109 return super .addChild (child , index );
@@ -167,10 +177,22 @@ public W children(int amount, IntFunction<I> widgetCreator) {
167177 }
168178
169179 /**
170- * Configures this widget to collapse disabled child widgets .
180+ * Sets if disabled children should be collapsed .
171181 */
172182 public W collapseDisabledChild () {
173- this .collapseDisabledChild = true ;
183+ return collapseDisabledChild (true );
184+ }
185+
186+ /**
187+ * Sets if disabled children should be collapsed. This means that if a child changes enabled state, this widget gets notified and
188+ * re-layouts its children. Children which are disabled will not be considered during layout, so that the list will not appear to have
189+ * empty spots. This is enabled by default on lists.
190+ *
191+ * @param doCollapse true if disabled children should be collapsed.
192+ * @return this
193+ */
194+ public W collapseDisabledChild (boolean doCollapse ) {
195+ this .collapseDisabledChild = doCollapse ;
174196 return getThis ();
175197 }
176198}
0 commit comments