Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloamed committed Sep 19, 2024
1 parent 6985167 commit 3033d05
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions src/vaev-layout/flex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,34 @@ namespace Vaev::Layout {

struct FlexItem {
Frag &frag;
Flex &flexContainer;

FlexItem(Frag &f, Flex &flexContainer) : frag(f), flexContainer(flexContainer) {
}

Number getCrossSize() {
if (flexContainer.direction == FlexDirection::ROW or flexContainer.direction == FlexDirection::ROW_REVERSE) {
// return frag ... height
} else {
// return frag ... width
}
return 0;
}

Number getFlexBaseSize() {
if (frag.style->flex->basis.type == FlexBasis::WIDTH) {
if (frag.style->flex->basis.width == Width::VALUE)
return frag.style->flex->basis.width.value;
} else {
if (getCrossSize() and
// frag.style. .... aspect ratio
true) {
// flex base size is calculated from its inner cross size and the flex item’s intrinsic aspect ratio.
} else {
// ... other conditions which are complex
}
}
}
};

struct FlexLine {
Expand All @@ -16,12 +44,19 @@ Output flexLayout(Tree &t, Frag &f, Input input) {
// https://www.w3.org/TR/css-flexbox-1/#layout-algorithm

// 1. Generate anonymous flex items
Vec<FlexItem> flexItems;

// TODO: Implement this step
Vec<FlexItem> flexItems;
for (auto &c : f.children()) {
// How does this behave for anon children? Dont know how children() returns them yet
flexItems.pushBack(FlexItem(c, f.style->flex.cow()));
}

// 2. Determine the available main and cross space for the flex items.
// TODO: Implement this step
// CURRENT ASSUMPTIONS:
// - flow-direction: row
// - dimensions of containers are definite size
auto availableMainSpace = input.availableSpace.x;
auto availableCrossSpace = input.availableSpace.y;

// 3. Determine the flex base size and hypothetical main size of each item
// TODO: Implement this step
Expand All @@ -30,7 +65,8 @@ Output flexLayout(Tree &t, Frag &f, Input input) {
// TODO: Implement this step

// 5. Collect flex items into flex lines
Vec<FlexLine> flexLines;
Vec<FlexLine>
flexLines;

// TODO: Implement this step

Expand Down

0 comments on commit 3033d05

Please sign in to comment.