Skip to content

Commit f5dc467

Browse files
grid column start/end, auto rows gentest
1 parent 8aeef1f commit f5dc467

File tree

11 files changed

+619
-82
lines changed

11 files changed

+619
-82
lines changed

gentest/fixtures/YGGridTest.html

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
<div
2-
id="grid_template_rows_columns"
2+
id="grid_template_all_properties_2"
33
style="
44
display: grid;
55
grid-template-rows: 100px 100px 100px;
66
grid-template-columns: 100px 100px 100px;
7+
grid-auto-rows: 100px 200px;
8+
grid-auto-columns: 100px 200px;
79
">
8-
<div style="width: 100px; height: 100px"></div>
9-
<div></div>
10+
<div
11+
style="
12+
width: 100px;
13+
height: 100px;
14+
grid-column-start: 1;
15+
grid-column-end: 5;
16+
grid-row-start: 1;
17+
grid-row-end: 3;
18+
"></div>
19+
<div
20+
style="
21+
width: 100px;
22+
height: 100px;
23+
grid-row-start: 2;
24+
grid-row-end: 4;
25+
"></div>
1026
<div></div>
1127
</div>

gentest/gentest-cpp.js

Lines changed: 110 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,12 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
513513
},
514514

515515
YGNodeStyleSetGridTemplateRows: {
516-
value: function (nodeName, tracks) {
516+
value: function (nodeName, value) {
517+
if (!value) {
518+
return;
519+
}
520+
521+
const tracks = parseGridTrackList(this, value);
517522
if (!tracks || tracks.length === 0) {
518523
return;
519524
}
@@ -545,7 +550,12 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
545550
},
546551

547552
YGNodeStyleSetGridTemplateColumns: {
548-
value: function (nodeName, tracks) {
553+
value: function (nodeName, value) {
554+
if (!value) {
555+
return;
556+
}
557+
558+
const tracks = parseGridTrackList(this, value);
549559
if (!tracks || tracks.length === 0) {
550560
return;
551561
}
@@ -576,6 +586,104 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
576586
},
577587
},
578588

589+
YGNodeStyleSetGridColumnStart: {
590+
value: function (nodeName, value) {
591+
this.push(`YGNodeStyleSetGridColumnStart(${nodeName}, ${value});`);
592+
},
593+
},
594+
595+
YGNodeStyleSetGridColumnEnd: {
596+
value: function (nodeName, value) {
597+
this.push(`YGNodeStyleSetGridColumnEnd(${nodeName}, ${value});`);
598+
},
599+
},
600+
601+
YGNodeStyleSetGridRowStart: {
602+
value: function (nodeName, value) {
603+
this.push(`YGNodeStyleSetGridRowStart(${nodeName}, ${value});`);
604+
},
605+
},
606+
607+
YGNodeStyleSetGridRowEnd: {
608+
value: function (nodeName, value) {
609+
this.push(`YGNodeStyleSetGridRowEnd(${nodeName}, ${value});`);
610+
},
611+
},
612+
613+
YGNodeStyleSetGridAutoColumns: {
614+
value: function (nodeName, value) {
615+
if (!value) {
616+
return;
617+
}
618+
619+
const tracks = parseGridTrackList(this, value);
620+
if (!tracks || tracks.length === 0) {
621+
return;
622+
}
623+
624+
this.push(`auto ${nodeName}_gridAutoColumns = YGGridTrackListCreate();`);
625+
626+
for (const track of tracks) {
627+
if (track.type === 'minmax') {
628+
const minVal = this.formatGridTrackValue(track.min);
629+
const maxVal = this.formatGridTrackValue(track.max);
630+
this.push(
631+
`YGGridTrackListAddTrack(${nodeName}_gridAutoColumns, YGMinMax(${minVal}, ${maxVal}));`,
632+
);
633+
} else {
634+
const val = this.formatGridTrackValue(track);
635+
this.push(
636+
`YGGridTrackListAddTrack(${nodeName}_gridAutoColumns, ${val});`,
637+
);
638+
}
639+
}
640+
641+
this.push(
642+
`YGNodeStyleSetGridAutoColumns(${nodeName}, ${nodeName}_gridAutoColumns);`,
643+
);
644+
this.push(
645+
`YGGridTrackListFree(${nodeName}_gridAutoColumns);`,
646+
);
647+
},
648+
},
649+
650+
YGNodeStyleSetGridAutoRows: {
651+
value: function (nodeName, value) {
652+
if (!value) {
653+
return;
654+
}
655+
656+
const tracks = parseGridTrackList(this, value);
657+
if (!tracks || tracks.length === 0) {
658+
return;
659+
}
660+
661+
this.push(`auto ${nodeName}_gridAutoRows = YGGridTrackListCreate();`);
662+
663+
for (const track of tracks) {
664+
if (track.type === 'minmax') {
665+
const minVal = this.formatGridTrackValue(track.min);
666+
const maxVal = this.formatGridTrackValue(track.max);
667+
this.push(
668+
`YGGridTrackListAddTrack(${nodeName}_gridAutoRows, YGMinMax(${minVal}, ${maxVal}));`,
669+
);
670+
} else {
671+
const val = this.formatGridTrackValue(track);
672+
this.push(
673+
`YGGridTrackListAddTrack(${nodeName}_gridAutoRows, ${val});`,
674+
);
675+
}
676+
}
677+
678+
this.push(
679+
`YGNodeStyleSetGridAutoRows(${nodeName}, ${nodeName}_gridAutoRows);`,
680+
);
681+
this.push(
682+
`YGGridTrackListFree(${nodeName}_gridAutoRows);`,
683+
);
684+
},
685+
},
686+
579687
formatGridTrackValue: {
580688
value: function (track) {
581689
switch (track.type) {

gentest/gentest-driver.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,16 @@ for (const fileName of fixtures) {
7676
// TODO: replace this with something more robust than just blindly replacing
7777
// start/end in the entire fixture
7878
const ltrFixture = fixture
79-
.replaceAll('start', 'left')
80-
.replaceAll('end', 'right')
79+
// prevent replacing grid-column-start and grid-row-start
80+
.replaceAll(/(?<!grid-column-)(?<!grid-row-)start/g, 'left')
81+
.replaceAll(/(?<!grid-column-)(?<!grid-row-)end/g, 'right')
8182
.replaceAll('flex-left', 'flex-start')
8283
.replaceAll('flex-right', 'flex-end');
8384

8485
const rtlFixture = fixture
85-
.replaceAll('start', 'right')
86-
.replaceAll('end', 'left')
86+
// prevent replacing grid-column-start and grid-row-start
87+
.replaceAll(/(?<!grid-column-)(?<!grid-row-)start/g, 'right')
88+
.replaceAll(/(?<!grid-column-)(?<!grid-row-)end/g, 'left')
8789
.replaceAll('flex-right', 'flex-start')
8890
.replaceAll('flex-left', 'flex-end');
8991

gentest/gentest-java.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,104 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
535535
},
536536
},
537537

538+
YGNodeStyleSetGridColumnStart: {
539+
value: function (nodeName, gridLine) {
540+
if (gridLine.type === 'auto') {
541+
this.push(`${nodeName}.setGridColumnStartAuto();`);
542+
} else if (gridLine.type === 'integer') {
543+
this.push(`${nodeName}.setGridColumnStart(${gridLine.value});`);
544+
}
545+
},
546+
},
547+
548+
YGNodeStyleSetGridColumnEnd: {
549+
value: function (nodeName, gridLine) {
550+
if (gridLine.type === 'auto') {
551+
this.push(`${nodeName}.setGridColumnEndAuto();`);
552+
} else if (gridLine.type === 'integer') {
553+
this.push(`${nodeName}.setGridColumnEnd(${gridLine.value});`);
554+
}
555+
},
556+
},
557+
558+
YGNodeStyleSetGridRowStart: {
559+
value: function (nodeName, gridLine) {
560+
if (gridLine.type === 'auto') {
561+
this.push(`${nodeName}.setGridRowStartAuto();`);
562+
} else if (gridLine.type === 'integer') {
563+
this.push(`${nodeName}.setGridRowStart(${gridLine.value});`);
564+
}
565+
},
566+
},
567+
568+
YGNodeStyleSetGridRowEnd: {
569+
value: function (nodeName, gridLine) {
570+
if (gridLine.type === 'auto') {
571+
this.push(`${nodeName}.setGridRowEndAuto();`);
572+
} else if (gridLine.type === 'integer') {
573+
this.push(`${nodeName}.setGridRowEnd(${gridLine.value});`);
574+
}
575+
},
576+
},
577+
578+
YGNodeStyleSetGridAutoColumns: {
579+
value: function (nodeName, tracks) {
580+
if (!tracks || tracks.length === 0) {
581+
return;
582+
}
583+
584+
this.push(
585+
`YogaGridTrackList ${nodeName}GridAutoColumns = new YogaGridTrackList();`,
586+
);
587+
588+
for (const track of tracks) {
589+
if (track.type === 'minmax') {
590+
const minVal = this.formatGridTrackValueJava(track.min);
591+
const maxVal = this.formatGridTrackValueJava(track.max);
592+
this.push(
593+
`${nodeName}GridAutoColumns.addTrack(YogaGridTrackValue.minMax(${minVal}, ${maxVal}));`,
594+
);
595+
} else {
596+
const val = this.formatGridTrackValueJava(track);
597+
this.push(`${nodeName}GridAutoColumns.addTrack(${val});`);
598+
}
599+
}
600+
601+
this.push(
602+
`${nodeName}.setGridAutoColumns(${nodeName}GridAutoColumns);`,
603+
);
604+
},
605+
},
606+
607+
YGNodeStyleSetGridAutoRows: {
608+
value: function (nodeName, tracks) {
609+
if (!tracks || tracks.length === 0) {
610+
return;
611+
}
612+
613+
this.push(
614+
`YogaGridTrackList ${nodeName}GridAutoRows = new YogaGridTrackList();`,
615+
);
616+
617+
for (const track of tracks) {
618+
if (track.type === 'minmax') {
619+
const minVal = this.formatGridTrackValueJava(track.min);
620+
const maxVal = this.formatGridTrackValueJava(track.max);
621+
this.push(
622+
`${nodeName}GridAutoRows.addTrack(YogaGridTrackValue.minMax(${minVal}, ${maxVal}));`,
623+
);
624+
} else {
625+
const val = this.formatGridTrackValueJava(track);
626+
this.push(`${nodeName}GridAutoRows.addTrack(${val});`);
627+
}
628+
}
629+
630+
this.push(
631+
`${nodeName}.setGridAutoRows(${nodeName}GridAutoRows);`,
632+
);
633+
},
634+
},
635+
538636
formatGridTrackValueJava: {
539637
value: function (track) {
540638
switch (track.type) {

gentest/gentest-javascript.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,100 @@ JavascriptEmitter.prototype = Object.create(Emitter.prototype, {
494494
},
495495
},
496496

497+
YGNodeStyleSetGridColumnStart: {
498+
value: function (nodeName, gridLine) {
499+
if (gridLine.type === 'auto') {
500+
this.push(`${nodeName}.setGridColumnStartAuto();`);
501+
} else if (gridLine.type === 'integer') {
502+
this.push(`${nodeName}.setGridColumnStart(${gridLine.value});`);
503+
}
504+
},
505+
},
506+
507+
YGNodeStyleSetGridColumnEnd: {
508+
value: function (nodeName, gridLine) {
509+
if (gridLine.type === 'auto') {
510+
this.push(`${nodeName}.setGridColumnEndAuto();`);
511+
} else if (gridLine.type === 'integer') {
512+
this.push(`${nodeName}.setGridColumnEnd(${gridLine.value});`);
513+
}
514+
},
515+
},
516+
517+
YGNodeStyleSetGridRowStart: {
518+
value: function (nodeName, gridLine) {
519+
if (gridLine.type === 'auto') {
520+
this.push(`${nodeName}.setGridRowStartAuto();`);
521+
} else if (gridLine.type === 'integer') {
522+
this.push(`${nodeName}.setGridRowStart(${gridLine.value});`);
523+
}
524+
},
525+
},
526+
527+
YGNodeStyleSetGridRowEnd: {
528+
value: function (nodeName, gridLine) {
529+
if (gridLine.type === 'auto') {
530+
this.push(`${nodeName}.setGridRowEndAuto();`);
531+
} else if (gridLine.type === 'integer') {
532+
this.push(`${nodeName}.setGridRowEnd(${gridLine.value});`);
533+
}
534+
},
535+
},
536+
537+
YGNodeStyleSetGridAutoColumns: {
538+
value: function (nodeName, tracks) {
539+
if (!tracks || tracks.length === 0) {
540+
return;
541+
}
542+
543+
this.push(`const ${nodeName}GridAutoColumns = [];`);
544+
545+
for (const track of tracks) {
546+
if (track.type === 'minmax') {
547+
const minVal = this.formatGridTrackValueJS(track.min);
548+
const maxVal = this.formatGridTrackValueJS(track.max);
549+
this.push(
550+
`${nodeName}GridAutoColumns.push({type: 'minmax', min: ${minVal}, max: ${maxVal}});`,
551+
);
552+
} else {
553+
const val = this.formatGridTrackValueJS(track);
554+
this.push(`${nodeName}GridAutoColumns.push(${val});`);
555+
}
556+
}
557+
558+
this.push(
559+
`${nodeName}.setGridAutoColumns(${nodeName}GridAutoColumns);`,
560+
);
561+
},
562+
},
563+
564+
YGNodeStyleSetGridAutoRows: {
565+
value: function (nodeName, tracks) {
566+
if (!tracks || tracks.length === 0) {
567+
return;
568+
}
569+
570+
this.push(`const ${nodeName}GridAutoRows = [];`);
571+
572+
for (const track of tracks) {
573+
if (track.type === 'minmax') {
574+
const minVal = this.formatGridTrackValueJS(track.min);
575+
const maxVal = this.formatGridTrackValueJS(track.max);
576+
this.push(
577+
`${nodeName}GridAutoRows.push({type: 'minmax', min: ${minVal}, max: ${maxVal}});`,
578+
);
579+
} else {
580+
const val = this.formatGridTrackValueJS(track);
581+
this.push(`${nodeName}GridAutoRows.push(${val});`);
582+
}
583+
}
584+
585+
this.push(
586+
`${nodeName}.setGridAutoRows(${nodeName}GridAutoRows);`,
587+
);
588+
},
589+
},
590+
497591
formatGridTrackValueJS: {
498592
value: function (track) {
499593
switch (track.type) {

0 commit comments

Comments
 (0)