pub fn compute_oof_layout(
tree: &mut impl LayoutContainingBlock,
node_id: NodeId,
output: &mut LayoutOutput,
)Expand description
Run the out-of-flow positioning pass for node_id after its layout algorithm has produced
output: lay out the out-of-flow candidates in output.oof_candidates for which the node is
the containing block, record them as the node’s hoisted children, and replace
output.oof_candidates with the unclaimed remainder (which bubble further up the tree).
The scrollable overflow contributed by the claimed boxes is merged into
output.scrollable_overflow_rect.
This should be called once per RunMode::PerformLayout container layout, after the layout
algorithm (block/flexbox/grid) has run, and inside any layout caching wrapper (such as
compute_cached_layout) so that cache hits do not re-run the
pass. It is a no-op when output.oof_positioning_area is None (leaf and size-only outputs).
Which candidates the node claims is determined by the node’s style via
CoreStyle::is_containing_block. position: fixed boxes unclaimed by every ancestor are
claimed by the final root positioning pass in compute_root_layout.
Examples found in repository?
157 fn compute_child_layout(&mut self, node_id: NodeId, inputs: takia::tree::LayoutInput) -> takia::tree::LayoutOutput {
158 compute_cached_layout(self, node_id, inputs, |parent, node_id, inputs| {
159 let node = parent.node_from_id_mut(node_id);
160 let font_metrics = FontMetrics { char_width: 10.0, char_height: 10.0 };
161
162 let mut output = match node.kind {
163 NodeKind::Flexbox => compute_flexbox_layout(node, node_id, inputs),
164 NodeKind::Grid => compute_grid_layout(node, node_id, inputs),
165 NodeKind::Text => compute_leaf_layout(
166 inputs,
167 &node.style,
168 |_val, _basis| 0.0,
169 |known_dimensions, available_space| {
170 text_measure_function(
171 known_dimensions,
172 available_space,
173 node.text_data.as_ref().unwrap(),
174 &font_metrics,
175 )
176 },
177 ),
178 NodeKind::Image => compute_leaf_layout(
179 inputs,
180 &node.style,
181 |_val, _basis| 0.0,
182 |known_dimensions, _available_space| {
183 image_measure_function(known_dimensions, node.image_data.as_ref().unwrap())
184 },
185 ),
186 };
187
188 // Lay out any out-of-flow (absolute/fixed) boxes for which this node is the containing block
189 if inputs.run_mode == takia::RunMode::PerformLayout {
190 compute_oof_layout(node, node_id, &mut output);
191 }
192
193 output
194 })
195 }More examples
163 fn compute_child_layout(&mut self, node_id: NodeId, inputs: takia::tree::LayoutInput) -> takia::tree::LayoutOutput {
164 compute_cached_layout(self, node_id, inputs, |tree, node_id, inputs| {
165 let node = &mut tree.nodes[usize::from(node_id)];
166 let font_metrics = FontMetrics { char_width: 10.0, char_height: 10.0 };
167
168 let mut output = match node.kind {
169 NodeKind::Flexbox => compute_flexbox_layout(tree, node_id, inputs),
170 NodeKind::Grid => compute_grid_layout(tree, node_id, inputs),
171 NodeKind::Text => compute_leaf_layout(
172 inputs,
173 &node.style,
174 |_val, _basis| 0.0,
175 |known_dimensions, available_space| {
176 text_measure_function(
177 known_dimensions,
178 available_space,
179 node.text_data.as_ref().unwrap(),
180 &font_metrics,
181 )
182 },
183 ),
184 NodeKind::Image => compute_leaf_layout(
185 inputs,
186 &node.style,
187 |_val, _basis| 0.0,
188 |known_dimensions, _available_space| {
189 image_measure_function(known_dimensions, node.image_data.as_ref().unwrap())
190 },
191 ),
192 };
193
194 // Lay out any out-of-flow (absolute/fixed) boxes for which this node is the containing block
195 if inputs.run_mode == takia::RunMode::PerformLayout {
196 compute_oof_layout(tree, node_id, &mut output);
197 }
198
199 output
200 })
201 }155 fn compute_child_layout(&mut self, node_id: NodeId, inputs: takia::tree::LayoutInput) -> takia::tree::LayoutOutput {
156 compute_cached_layout(self, node_id, inputs, |tree, node_id, inputs| {
157 let node = unsafe { node_from_id_mut(node_id) };
158 let font_metrics = FontMetrics { char_width: 10.0, char_height: 10.0 };
159
160 let mut output = match node.kind {
161 NodeKind::Flexbox => compute_flexbox_layout(tree, node_id, inputs),
162 NodeKind::Grid => compute_grid_layout(tree, node_id, inputs),
163 NodeKind::Text => compute_leaf_layout(
164 inputs,
165 &node.style,
166 |val, basis| tree.resolve_calc_value(val, basis),
167 |known_dimensions, available_space| {
168 text_measure_function(
169 known_dimensions,
170 available_space,
171 node.text_data.as_ref().unwrap(),
172 &font_metrics,
173 )
174 },
175 ),
176 NodeKind::Image => compute_leaf_layout(
177 inputs,
178 &node.style,
179 |val, basis| tree.resolve_calc_value(val, basis),
180 |known_dimensions, _available_space| {
181 image_measure_function(known_dimensions, node.image_data.as_ref().unwrap())
182 },
183 ),
184 };
185
186 // Lay out any out-of-flow (absolute/fixed) boxes for which this node is the containing block
187 if inputs.run_mode == takia::RunMode::PerformLayout {
188 compute_oof_layout(tree, node_id, &mut output);
189 }
190
191 output
192 })
193 }