|
6 | 6 | */ |
7 | 7 |
|
8 | 8 | #include <algorithm> |
| 9 | +#include <string> |
9 | 10 |
|
| 11 | +#include <yoga/YGGridTrackList.h> |
10 | 12 | #include <yoga/Yoga.h> |
11 | 13 |
|
12 | 14 | #include "./Config.h" |
@@ -124,6 +126,14 @@ void Node::setJustifyContent(int justifyContent) { |
124 | 126 | YGNodeStyleSetJustifyContent(m_node, static_cast<YGJustify>(justifyContent)); |
125 | 127 | } |
126 | 128 |
|
| 129 | +void Node::setJustifyItems(int justifyItems) { |
| 130 | + YGNodeStyleSetJustifyItems(m_node, static_cast<YGJustify>(justifyItems)); |
| 131 | +} |
| 132 | + |
| 133 | +void Node::setJustifySelf(int justifySelf) { |
| 134 | + YGNodeStyleSetJustifySelf(m_node, static_cast<YGJustify>(justifySelf)); |
| 135 | +} |
| 136 | + |
127 | 137 | void Node::setMargin(int edge, double margin) { |
128 | 138 | YGNodeStyleSetMargin(m_node, static_cast<YGEdge>(edge), margin); |
129 | 139 | } |
@@ -590,3 +600,102 @@ void Node::setAlwaysFormsContainingBlock(bool alwaysFormsContainingBlock) { |
590 | 600 | return YGNodeSetAlwaysFormsContainingBlock( |
591 | 601 | m_node, alwaysFormsContainingBlock); |
592 | 602 | } |
| 603 | + |
| 604 | +// Helper function to convert JS track value to YGGridTrackValueRef |
| 605 | +static YGGridTrackValueRef convertTrackValue(emscripten::val track) { |
| 606 | + int type = track["type"].as<int>(); |
| 607 | + |
| 608 | + switch (type) { |
| 609 | + case YGGridTrackTypeAuto: |
| 610 | + return YGAuto(); |
| 611 | + case YGGridTrackTypePoints: { |
| 612 | + float value = track["value"].as<float>(); |
| 613 | + return YGPoints(value); |
| 614 | + } |
| 615 | + case YGGridTrackTypePercent: { |
| 616 | + float value = track["value"].as<float>(); |
| 617 | + return YGPercent(value); |
| 618 | + } |
| 619 | + case YGGridTrackTypeFr: { |
| 620 | + float value = track["value"].as<float>(); |
| 621 | + return YGFr(value); |
| 622 | + } |
| 623 | + case YGGridTrackTypeMinmax: { |
| 624 | + YGGridTrackValueRef minVal = convertTrackValue(track["min"]); |
| 625 | + YGGridTrackValueRef maxVal = convertTrackValue(track["max"]); |
| 626 | + return YGMinMax(minVal, maxVal); |
| 627 | + } |
| 628 | + default: |
| 629 | + return YGAuto(); |
| 630 | + } |
| 631 | +} |
| 632 | + |
| 633 | +// Helper function to build grid track list from JS array |
| 634 | +static YGGridTrackListRef buildGridTrackList(emscripten::val tracks) { |
| 635 | + YGGridTrackListRef trackList = YGGridTrackListCreate(); |
| 636 | + |
| 637 | + unsigned length = tracks["length"].as<unsigned>(); |
| 638 | + for (unsigned i = 0; i < length; i++) { |
| 639 | + emscripten::val track = tracks[i]; |
| 640 | + YGGridTrackValueRef trackValue = convertTrackValue(track); |
| 641 | + YGGridTrackListAddTrack(trackList, trackValue); |
| 642 | + } |
| 643 | + |
| 644 | + return trackList; |
| 645 | +} |
| 646 | + |
| 647 | +void Node::setGridTemplateColumns(emscripten::val tracks) { |
| 648 | + YGGridTrackListRef trackList = buildGridTrackList(tracks); |
| 649 | + YGNodeStyleSetGridTemplateColumns(m_node, trackList); |
| 650 | + YGGridTrackListFree(trackList); |
| 651 | +} |
| 652 | + |
| 653 | +void Node::setGridTemplateRows(emscripten::val tracks) { |
| 654 | + YGGridTrackListRef trackList = buildGridTrackList(tracks); |
| 655 | + YGNodeStyleSetGridTemplateRows(m_node, trackList); |
| 656 | + YGGridTrackListFree(trackList); |
| 657 | +} |
| 658 | + |
| 659 | +void Node::setGridAutoColumns(emscripten::val tracks) { |
| 660 | + YGGridTrackListRef trackList = buildGridTrackList(tracks); |
| 661 | + YGNodeStyleSetGridAutoColumns(m_node, trackList); |
| 662 | + YGGridTrackListFree(trackList); |
| 663 | +} |
| 664 | + |
| 665 | +void Node::setGridAutoRows(emscripten::val tracks) { |
| 666 | + YGGridTrackListRef trackList = buildGridTrackList(tracks); |
| 667 | + YGNodeStyleSetGridAutoRows(m_node, trackList); |
| 668 | + YGGridTrackListFree(trackList); |
| 669 | +} |
| 670 | + |
| 671 | +void Node::setGridColumnStart(int value) { |
| 672 | + YGNodeStyleSetGridColumnStart(m_node, value); |
| 673 | +} |
| 674 | + |
| 675 | +void Node::setGridColumnStartSpan(int span) { |
| 676 | + YGNodeStyleSetGridColumnStartSpan(m_node, span); |
| 677 | +} |
| 678 | + |
| 679 | +void Node::setGridColumnEnd(int value) { |
| 680 | + YGNodeStyleSetGridColumnEnd(m_node, value); |
| 681 | +} |
| 682 | + |
| 683 | +void Node::setGridColumnEndSpan(int span) { |
| 684 | + YGNodeStyleSetGridColumnEndSpan(m_node, span); |
| 685 | +} |
| 686 | + |
| 687 | +void Node::setGridRowStart(int value) { |
| 688 | + YGNodeStyleSetGridRowStart(m_node, value); |
| 689 | +} |
| 690 | + |
| 691 | +void Node::setGridRowStartSpan(int span) { |
| 692 | + YGNodeStyleSetGridRowStartSpan(m_node, span); |
| 693 | +} |
| 694 | + |
| 695 | +void Node::setGridRowEnd(int value) { |
| 696 | + YGNodeStyleSetGridRowEnd(m_node, value); |
| 697 | +} |
| 698 | + |
| 699 | +void Node::setGridRowEndSpan(int span) { |
| 700 | + YGNodeStyleSetGridRowEndSpan(m_node, span); |
| 701 | +} |
0 commit comments