22
33import com .cleanroommc .modularui .api .layout .ILayoutWidget ;
44import com .cleanroommc .modularui .api .widget .IWidget ;
5+ import com .cleanroommc .modularui .utils .Alignment ;
56import com .cleanroommc .modularui .widget .ScrollWidget ;
67import com .cleanroommc .modularui .widget .scroll .HorizontalScrollData ;
78import com .cleanroommc .modularui .widget .scroll .ScrollData ;
@@ -25,6 +26,7 @@ public class Grid extends ScrollWidget<Grid> implements ILayoutWidget {
2526 private final List <List <IWidget >> matrix = new ArrayList <>();
2627 private final Box minElementMargin = new Box ();
2728 private int minRowHeight = 5 , minColWidth = 5 ;
29+ private Alignment alignment = Alignment .Center ;
2830 private boolean dirty = false ;
2931
3032 public Grid () {
@@ -83,8 +85,8 @@ public void layoutWidgets() {
8385 int width = colSizes .get (c );
8486 IWidget child = this .matrix .get (r ).get (c );
8587 if (child != null ) {
86- child .getArea ().rx = (int ) (x + width * 0.5 - child .getArea ().width * 0.5 );
87- child .getArea ().ry = (int ) (y + height * 0.5 - child .getArea ().height * 0.5 );
88+ child .getArea ().rx = (int ) (x + ( width - child .getArea ().width ) * alignment . x );
89+ child .getArea ().ry = (int ) (y + ( height - child .getArea ().height ) * alignment . y );
8890 child .resizer ().setPosResized (true , true );
8991 }
9092 x += width ;
@@ -215,6 +217,11 @@ public Grid minRowHeight(int minRowHeight) {
215217 return this ;
216218 }
217219
220+ public Grid alignment (Alignment alignment ) {
221+ this .alignment = alignment ;
222+ return this ;
223+ }
224+
218225 public Grid scrollable () {
219226 return scrollable (new VerticalScrollData (), new HorizontalScrollData ());
220227 }
0 commit comments