Skip to content

Commit 1ba2909

Browse files
committed
[css-layout-api] Remove old examples, fix explainer.
1 parent 001f980 commit 1ba2909

File tree

2 files changed

+7
-185
lines changed

2 files changed

+7
-185
lines changed

css-layout-api/EXPLAINER.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ registerLayout('centering', class extends Layout {
9797
let maxChildInlineSize = 0;
9898
let maxChildBlockSize = 0;
9999
for (let child of children) {
100-
const childFragment = yield child.layout(childConstraintSpace);
100+
const childFragment = yield child.doLayout(childConstraintSpace);
101101

102102
maxChildInlineSize = Math.max(maxChildInlineSize, childFragments.inlineSize);
103103
maxChildBlockSize = Math.max(maxChildBlockSize, childFragments.blockSize);
@@ -196,7 +196,7 @@ child constraint space just sets the size available to the children.
196196
We now loop through all of our children and perform layout. This is done by:
197197

198198
```js
199-
const childFragment = yield child.layout(childConstraintSpace);
199+
const childFragment = yield child.doLayout(childConstraintSpace);
200200
```
201201

202202
`child` has a very simple API. You can query the style of a child and perform layout - e.g.
@@ -205,7 +205,7 @@ const childFragment = yield child.layout(childConstraintSpace);
205205
child instanceof LayoutChild; // true
206206
child.styleMap.get('--a-property');
207207

208-
const fragment = yield child.layout(childConstraintSpace);
208+
const fragment = yield child.doLayout(childConstraintSpace);
209209
```
210210

211211
The result of performing layout on a child is a `Fragment`. A fragment is read-only except for
@@ -319,8 +319,8 @@ The quick brown fox jumped over the lazy dog.
319319
```js
320320
child instanceof LayoutChild;
321321

322-
const fragment1 = yield child.layout(constraintSpace);
323-
const fragment2 = yield child.layout(constraintSpace, fragment1.breakToken);
322+
const fragment1 = yield child.doLayout(constraintSpace);
323+
const fragment2 = yield child.doLayout(constraintSpace, fragment1.breakToken);
324324

325325
fragment2.breakToken == null;
326326
```
@@ -398,7 +398,7 @@ registerLayout('basic-inline', class extends Layout {
398398
percentageInlineSize: availableInlineSize
399399
});
400400

401-
const fragment = yield child.layout(constraintSpace, breakToken);
401+
const fragment = yield child.doLayout(constraintSpace, breakToken);
402402
childFragments.push(fragment);
403403

404404
// Check if there is still space on the current line.
@@ -546,7 +546,7 @@ registerLayout('multi-col', class extends Layout {
546546
blockFragmentationType: 'column',
547547
});
548548

549-
const fragment = yield child.layout(childConstraintSpace);
549+
const fragment = yield child.doLayout(childConstraintSpace);
550550
}
551551

552552
// ...

css-layout-api/Overview.bs

Lines changed: 0 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,181 +1013,3 @@ context</a> for a given |box|, |constraintSpace|, |children| and an optional |br
10131013

10141014
15. Return |fragment|.
10151015

1016-
Examples {#examples}
1017-
====================
1018-
1019-
Example 1: A simple block layout {#example-1}
1020-
---------------------------------------------
1021-
1022-
<pre class='lang-javascript'>
1023-
// Inside LayoutWorkletGlobalScope
1024-
1025-
// Note this is meant to be similar (*not* the same) as a block layout.
1026-
// Everything is done in 'width' & 'height' for easy reading.
1027-
registerLayout('simple-flow', class {
1028-
static get inputProperties() { return ['width', 'height'] }
1029-
static get childrenInputProperties() { return ['x', 'y', 'position'] }
1030-
1031-
layout(children, constraintSpace, styleMap, breakToken) {
1032-
const absoluteChildren = [];
1033-
const fixedChildren = [];
1034-
const fragments = [];
1035-
1036-
// Resolve our width using the available width in 'constraintSpace', and
1037-
// our computed width property.
1038-
let width = resolveWidth(constraintSpace, styleMap.get('width'));
1039-
1040-
// Create a new constraint space for our children to consume.
1041-
let childConstraintSpace = new ConstraintSpace(constraintSpace);
1042-
childConstraintSpace.width = width;
1043-
1044-
// Track the used height, min and max content.
1045-
let height = 0;
1046-
let minContent = 0;
1047-
let maxContent = 0;
1048-
1049-
for (let child of children) {
1050-
// Check if the child is out of flow positioned.
1051-
const childPosition = child.styleMap.get('position');
1052-
1053-
if (childPosition == 'absolute') {
1054-
absoluteChildren.push(child);
1055-
continue;
1056-
}
1057-
1058-
if (childPosition == 'fixed') {
1059-
fixedChildren.push(child);
1060-
continue;
1061-
}
1062-
1063-
// Layout the in flow child.
1064-
const childFragment = child.doLayout(childConstraintSpace);
1065-
1066-
// Position the child.
1067-
childFragment.x = 0;
1068-
childFragment.y = height;
1069-
1070-
// Update our current height, min and max content.
1071-
height += childFragment.height;
1072-
minContent = Math.max(childFragment.minContent, minContent);
1073-
maxContent = Math.max(childFragment.maxContent, maxContent);
1074-
}
1075-
1076-
// Resolve the height.
1077-
height = resolveHeight(constraintSpace, styleMap.get('height'), height);
1078-
1079-
return {
1080-
minContent: minContent,
1081-
maxContent: maxContent,
1082-
width: width,
1083-
height: height,
1084-
fragments: fragments,
1085-
unPositionedChildren: absoluteChildren.concat(fixedChildren),
1086-
breakToken: null
1087-
};
1088-
}
1089-
});
1090-
</pre>
1091-
1092-
<pre class='lang-markup'>
1093-
&lt;div id="myElement"&gt;
1094-
&lt;div&gt;
1095-
CSS is awesome.
1096-
&lt;/div&gt;
1097-
&lt;/div&gt;
1098-
1099-
&lt;style&gt;
1100-
#myElement {
1101-
display: layout('simple-flow');
1102-
}
1103-
&lt;/style&gt;
1104-
</pre>
1105-
1106-
Example 2: A simple line layout {#example-2}
1107-
--------------------------------------------
1108-
1109-
<pre class='lang-javascript'>
1110-
// Inside LayoutWorkletGlobalScope
1111-
1112-
// Note this is meant to be similar (*not* the same) as a inline layout.
1113-
// Everything is done in 'width' & 'height' for easy reading.
1114-
registerLayout('simple-inline-flow', class {
1115-
static get inputProperties() { return ['width', 'height'] }
1116-
static get childrenInputProperties() { return [] }
1117-
1118-
layout(children, constraintSpace, styleMap, breakToken) {
1119-
// Resolve our width using the available width in 'constraintSpace', and
1120-
// our computed width property.
1121-
const width = resolveWidth(constraintSpace, styleMap.get('width'));
1122-
const fragments = [];
1123-
let height = 0;
1124-
1125-
// TODO compute these.
1126-
let minContent = 0;
1127-
let maxContent = 0;
1128-
1129-
let childFragment = null;
1130-
let lineFragments = [];
1131-
let lineHeight = 0;
1132-
let remainingLineWidth = width; // NOTE: should be helper on constraint space?
1133-
1134-
const childIter = chidlren.values();
1135-
let child = childIter.next().value;
1136-
let breakToken = null;
1137-
1138-
while (child) {
1139-
// Create a new constraint space for the child, with all the current
1140-
// positioned children.
1141-
const childConstraintSpace = new ConstraintSpace(constraintSpace);
1142-
childConstraintSpace.addExclusion(new ExclusionRect(width, height, 0, 0));
1143-
childConstraintSpace.addExclusions(lineFragments);
1144-
1145-
// Perform layout on the child.
1146-
childFragment = child.doLayout(childConstraintSpace, breakToken);
1147-
fragments.push(childFragment);
1148-
1149-
// Check if we need to position the fragment on the next line.
1150-
if (childFragment.width > remainingLineWidth) {
1151-
// Need to start a new line.
1152-
lineFragments = [];
1153-
height += lineHeight;
1154-
lineHeight = 0;
1155-
remainingLineWidth = width;
1156-
}
1157-
1158-
// Position the fragment horizontally.
1159-
childFragment.x = width - remainingLineWidth;
1160-
1161-
lineFragments.push(childFragment);
1162-
lineHeight = Math.max(lineHeight, childFragment.height);
1163-
remainingLineWidth -= childFragment.width;
1164-
1165-
// Update the line fragments positions, based on the new lineHeight.
1166-
for (let frag of lineFragments) {
1167-
frag.y = lineHeight - frag.height;
1168-
}
1169-
1170-
// Step to the next child if required.
1171-
if (childFragment.breakToken) {
1172-
breakToken = childFragment.breakToken;
1173-
} else {
1174-
child = childIter.next().value;
1175-
breakToken = null;
1176-
}
1177-
}
1178-
1179-
// Resolve the height.
1180-
height = resolveHeight(constraintSpace, styleMap.get('height'), height);
1181-
1182-
return {
1183-
minContent: minContent,
1184-
maxContent: maxContent,
1185-
width: width,
1186-
height: height,
1187-
fragments: fragments,
1188-
unpositionedFragments: [],
1189-
breakToken: null
1190-
};
1191-
}
1192-
});
1193-
</pre>

0 commit comments

Comments
 (0)