Skip to main content

compute_grid_layout

Function compute_grid_layout 

Source
pub fn compute_grid_layout<Tree: LayoutGridContainer>(
    tree: &mut Tree,
    node: NodeId,
    inputs: LayoutInput,
) -> LayoutOutput
Available on crate feature grid only.
Expand description

Grid layout algorithm This consists of a few phases:

  • Resolving the explicit grid
  • Placing items (which also resolves the implicit grid)
  • Track (row/column) sizing
  • Alignment & Final item placement
Examples found in repository?
examples/custom_tree_owned_partial.rs (line 166)
159    fn compute_child_layout(&mut self, node_id: NodeId, inputs: gummy::tree::LayoutInput) -> gummy::tree::LayoutOutput {
160        compute_cached_layout(self, node_id, inputs, |parent, node_id, inputs| {
161            let node = parent.node_from_id_mut(node_id);
162            let font_metrics = FontMetrics { char_width: 10.0, char_height: 10.0 };
163
164            match node.kind {
165                NodeKind::Flexbox => compute_flexbox_layout(node, node_id, inputs),
166                NodeKind::Grid => compute_grid_layout(node, node_id, inputs),
167                NodeKind::Text => compute_leaf_layout(
168                    inputs,
169                    &node.style,
170                    |_val, _basis| 0.0,
171                    |known_dimensions, available_space| {
172                        text_measure_function(
173                            known_dimensions,
174                            available_space,
175                            node.text_data.as_ref().unwrap(),
176                            &font_metrics,
177                        )
178                    },
179                ),
180                NodeKind::Image => compute_leaf_layout(
181                    inputs,
182                    &node.style,
183                    |_val, _basis| 0.0,
184                    |known_dimensions, _available_space| {
185                        image_measure_function(known_dimensions, node.image_data.as_ref().unwrap())
186                    },
187                ),
188            }
189        })
190    }
More examples
Hide additional examples
examples/custom_tree_vec.rs (line 172)
165    fn compute_child_layout(&mut self, node_id: NodeId, inputs: gummy::tree::LayoutInput) -> gummy::tree::LayoutOutput {
166        compute_cached_layout(self, node_id, inputs, |tree, node_id, inputs| {
167            let node = &mut tree.nodes[usize::from(node_id)];
168            let font_metrics = FontMetrics { char_width: 10.0, char_height: 10.0 };
169
170            match node.kind {
171                NodeKind::Flexbox => compute_flexbox_layout(tree, node_id, inputs),
172                NodeKind::Grid => compute_grid_layout(tree, node_id, inputs),
173                NodeKind::Text => compute_leaf_layout(
174                    inputs,
175                    &node.style,
176                    |_val, _basis| 0.0,
177                    |known_dimensions, available_space| {
178                        text_measure_function(
179                            known_dimensions,
180                            available_space,
181                            node.text_data.as_ref().unwrap(),
182                            &font_metrics,
183                        )
184                    },
185                ),
186                NodeKind::Image => compute_leaf_layout(
187                    inputs,
188                    &node.style,
189                    |_val, _basis| 0.0,
190                    |known_dimensions, _available_space| {
191                        image_measure_function(known_dimensions, node.image_data.as_ref().unwrap())
192                    },
193                ),
194            }
195        })
196    }
examples/custom_tree_owned_unsafe.rs (line 166)
159    fn compute_child_layout(&mut self, node_id: NodeId, inputs: gummy::tree::LayoutInput) -> gummy::tree::LayoutOutput {
160        compute_cached_layout(self, node_id, inputs, |tree, node_id, inputs| {
161            let node = unsafe { node_from_id_mut(node_id) };
162            let font_metrics = FontMetrics { char_width: 10.0, char_height: 10.0 };
163
164            match node.kind {
165                NodeKind::Flexbox => compute_flexbox_layout(tree, node_id, inputs),
166                NodeKind::Grid => compute_grid_layout(tree, node_id, inputs),
167                NodeKind::Text => compute_leaf_layout(
168                    inputs,
169                    &node.style,
170                    |val, basis| tree.resolve_calc_value(val, basis),
171                    |known_dimensions, available_space| {
172                        text_measure_function(
173                            known_dimensions,
174                            available_space,
175                            node.text_data.as_ref().unwrap(),
176                            &font_metrics,
177                        )
178                    },
179                ),
180                NodeKind::Image => compute_leaf_layout(
181                    inputs,
182                    &node.style,
183                    |val, basis| tree.resolve_calc_value(val, basis),
184                    |known_dimensions, _available_space| {
185                        image_measure_function(known_dimensions, node.image_data.as_ref().unwrap())
186                    },
187                ),
188            }
189        })
190    }