Skip to content

Commit 258d40a

Browse files
authored
Fixed regression in table layout (#4390)
1 parent e74b11b commit 258d40a

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

CodenameOne/src/com/codename1/ui/table/TableLayout.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,12 @@ private void placeComponent(boolean rtl, Constraint con, int x, int y, int width
573573
con.parent.setY(y + d);
574574
con.parent.setHeight(height - d);
575575
break;
576-
default:
577-
// Component.CENTER:
576+
case Component.CENTER:
578577
con.parent.setY(y + d / 2);
579578
con.parent.setHeight(height - d);
580579
break;
580+
default:
581+
break;
581582
}
582583
}
583584
}

maven/core-unittests/src/test/java/com/codename1/ui/table/TableTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import com.codename1.junit.FormTest;
44
import com.codename1.junit.UITestBase;
5+
import com.codename1.ui.CN;
56
import com.codename1.ui.Component;
7+
import com.codename1.ui.Form;
8+
import com.codename1.ui.Label;
69
import com.codename1.ui.TextArea;
710

811
import java.util.Comparator;
9-
import java.util.Date;
1012
import java.lang.reflect.Method;
1113

1214
import static org.junit.jupiter.api.Assertions.*;
@@ -89,4 +91,29 @@ private Component findHeaderButton(Table table) {
8991
// Row 0 is header if includeHeader is true (default).
9092
return tl.getComponentAt(0, 0);
9193
}
94+
95+
/**
96+
* Test for a size regression bug in table layout discussed here: https://www.reddit.com/r/cn1/comments/1q6pmek/android_screen_out_of_ranges/
97+
*/
98+
@FormTest
99+
void testTableLayoutDefaultSizing() {
100+
Form f = CN.getCurrentForm();
101+
TableLayout tl = new TableLayout(3, 2);
102+
f.setLayout(tl);
103+
f.setScrollable(false);
104+
f.getContentPane().getAllStyles().setPadding(0, 0, 0, 0);
105+
for(int iter = 0 ; iter < 6 ; iter++) {
106+
Label l = new Label("T: " + iter);
107+
l.getAllStyles().setMargin(0, 0, 0, 0);
108+
f.addComponent(tl.createConstraint()
109+
.hp(33)
110+
.wp(50), l);
111+
}
112+
f.revalidate();
113+
114+
for(Component cmp : f.getContentPane()) {
115+
assertTrue(cmp.getHeight() >= f.getContentPane().getHeight() / 100 * 32, "Height should be close to 33 percent");
116+
assertTrue(cmp.getWidth() >= f.getContentPane().getWidth() / 2 - 1, "Width should be 50%");
117+
}
118+
}
92119
}

0 commit comments

Comments
 (0)