@@ -520,8 +520,8 @@ enum BreakType { "none", "line", "column", "page", "region" };
520
520
521
521
A {{LayoutChild}} can produce multiple {{Fragment}} s. A {{LayoutChild}} may fragment in the block
522
522
direction if a {{ConstraintSpace/blockFragmentationType}} is not none. Additionally {{LayoutChild}}
523
- which represents <a>inline-level</a> content, may fragment line by line if the <a for="layout
524
- definition">child display</a> (set by <code> childDisplay</code> ) is <code> "normal"</code> .
523
+ which represents <a>inline-level</a> content, may fragment line by line if the <a for="document
524
+ layout definition">child display</a> (set by <code> childDisplay</code> ) is <code> "normal"</code> .
525
525
526
526
A subsequent {{Fragment}} is produced by using the previous {{Fragment}} 's {{Fragment/breakToken}} .
527
527
This tells the <a>child layout</a> to produce a {{Fragment}} starting at the point encoded in the
@@ -530,7 +530,8 @@ This tells the <a>child layout</a> to produce a {{Fragment}} starting at the poi
530
530
Issue: Explain resuming the author defined layout.
531
531
532
532
<div class="example">
533
- This example shows a simple inline layout which places child fragments in the inline direction.
533
+ This example shows a simple layout which places indents child fragments for a certain number of
534
+ lines.
534
535
535
536
This example also demonstrates using the previous {{Fragment/breakToken}} of a {{Fragment}} to
536
537
produce the next fragment for the {{LayoutChild}} .
@@ -541,8 +542,9 @@ It returns a {{FragmentResultOptions}} with a {{FragmentResultOptions/breakToken
541
542
resume the layout.
542
543
543
544
<pre class="lang-javascript">
544
- registerLayout('basic-inline ' , class {
545
+ registerLayout('indent-lines ' , class {
545
546
static childDisplay = 'normal' ;
547
+ static inputProperties = ['--indent', '--indent-lines'] ;
546
548
547
549
*layout(space, children, styleMap, edges, breakToken) {
548
550
// Resolve our inline size.
@@ -553,22 +555,11 @@ registerLayout('basic-inline', class {
553
555
const availableBlockSize =
554
556
resolveBlockSize(space, styleMap) - edges.all.block;
555
557
556
- const childFragments = [];
557
-
558
- let currentLine = [];
559
- let usedInlineSize = 0;
560
-
561
- let lineOffset = 0;
562
- let maxLineBlockSize = 0;
558
+ // Detrermine the number of lines to indent, and the indent amount.
559
+ const indent = resolveLength(space, styleMap.get('--indent' ));
560
+ let lines = styleMap.get('--indent-lines' ).value;
563
561
564
- // Just a small little function which will update the above variables.
565
- const nextLine = function() {
566
- currentLine = [];
567
- usedInlineSize = 0;
568
-
569
- lineOffset += maxLineBlockSize;
570
- maxLineBlockSize = 0;
571
- }
562
+ const childFragments = [];
572
563
573
564
let childBreakToken = null;
574
565
if (breakToken) {
@@ -578,51 +569,36 @@ registerLayout('basic-inline', class {
578
569
children.splice(0, children.indexOf(childBreakToken.child));
579
570
}
580
571
572
+ let blockOffset = edges.all.blockStart;
581
573
let child = children.shift();
582
574
while (child) {
583
- // Make sure we actually have space on the current line.
584
- if (usedInlineSize > availableInlineSize) {
585
- nextLine();
586
- }
575
+ const shouldIndent = lines-- > 0;
576
+
577
+ // Adjust the inline size for the indent.
578
+ const childAvailableInlineSize = shouldIndent ?
579
+ availableInlineSize - indent : availableInlineSize;
587
580
588
- // The constraint space here will have the inline size of the
589
- // remaining space on the line.
590
- const remainingInlineSize = availableInlineSize - usedInlineSize;
591
- const constraintSpace = new ConstraintSpace({
592
- inlineSize: availableInlineSize - usedInlineSize,
581
+ const childSpace = new ConstraintSpace({
582
+ inlineSize: childAvailableInlineSize,
593
583
blockSize: availableBlockSize,
594
584
percentageInlineSize: availableInlineSize,
585
+ blockFragmentationType: space.blockFragmentationType,
595
586
});
596
587
597
- const fragment = yield child.layoutNextFragment(constraintSpace ,
588
+ const fragment = yield child.layoutNextFragment(childSpace ,
598
589
childBreakToken);
599
590
childFragments.push(fragment);
600
591
601
- // Check if there is still space on the current line.
602
- if (fragment.inlineSize > remainingInlineSize) {
603
- nextLine();
604
-
605
- // Check if we have gone over the block fragmentation limit.
606
- if (constraintSpace.blockFragmentationType != 'none' &&
607
- lineOffset > constraintSpace.blockSize) {
608
- break;
609
- }
610
- }
611
-
612
- // Insert fragment on the current line.
613
- currentLine.push(fragment);
614
- fragment.inlineOffset = usedInlineSize;
615
-
616
- // Go through each of the fragments on the line and update their
617
- // block offsets.
618
- for (let fragmentOnLine of currentLine) {
619
- fragmentOnLine.blockOffset = lineOffset;
592
+ // Position the fragment.
593
+ fragment.inlineOffset = shouldIndent ?
594
+ edges.all.inlineStart + indent : edges.all.inlineStart;
595
+ fragment.blockOffset = blockOffset;
596
+ blockOffset += fragment.blockSize;
620
597
621
- const lineBlockSize =
622
- fragmentOnLine.blockOffset + fragmentOnLine.blockSize;
623
- if (maxLineBlockSize < lineBlockSize) {
624
- maxLineBlockSize = lineBlockSize;
625
- }
598
+ // Check if we have gone over the block fragmentation limit.
599
+ if (constraintSpace.blockFragmentationType != 'none' &&
600
+ blockOffset > constraintSpace.blockSize) {
601
+ break;
626
602
}
627
603
628
604
if (fragment.breakToken) {
@@ -635,9 +611,7 @@ registerLayout('basic-inline', class {
635
611
}
636
612
}
637
613
638
- // Determine our block size.
639
- nextLine();
640
- const contentSize = lineOffset + edges.all.block;
614
+ const contentSize = blockOffset + edges.all.blockEnd;
641
615
const blockSize = resolveBlockSize(space,
642
616
styleMap,
643
617
contentSize);
@@ -753,6 +727,8 @@ partial interface LayoutWorkletGlobalScope {
753
727
double resolveBlockSize(ConstraintSpace constraintSpace,
754
728
StylePropertyMapReadOnly styleMap,
755
729
optional double contentSize);
730
+
731
+ double resolveLength(ConstraintSpace constraintSpace, CSSStyleValue value);
756
732
};
757
733
</pre>
758
734
0 commit comments