Function taffy::compute_flexbox_layout

source ยท
pub fn compute_flexbox_layout(
    tree: &mut impl LayoutPartialTree,
    node: NodeId,
    inputs: LayoutInput,
) -> LayoutOutput
Available on crate feature flexbox only.
Expand description

Computes the layout of LayoutPartialTree according to the flexbox algorithm

Examples found in repository?
examples/custom_tree_vec.rs (line 160)
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
    fn compute_child_layout(&mut self, node_id: NodeId, inputs: taffy::tree::LayoutInput) -> taffy::tree::LayoutOutput {
        compute_cached_layout(self, node_id, inputs, |tree, node_id, inputs| {
            let node = tree.node_from_id_mut(node_id);
            let font_metrics = FontMetrics { char_width: 10.0, char_height: 10.0 };

            match node.kind {
                NodeKind::Flexbox => compute_flexbox_layout(tree, node_id, inputs),
                NodeKind::Grid => compute_grid_layout(tree, node_id, inputs),
                NodeKind::Text => compute_leaf_layout(inputs, &node.style, |known_dimensions, available_space| {
                    text_measure_function(
                        known_dimensions,
                        available_space,
                        node.text_data.as_ref().unwrap(),
                        &font_metrics,
                    )
                }),
                NodeKind::Image => compute_leaf_layout(inputs, &node.style, |known_dimensions, _available_space| {
                    image_measure_function(known_dimensions, node.image_data.as_ref().unwrap())
                }),
            }
        })
    }
More examples
Hide additional examples
examples/custom_tree_owned_partial.rs (line 147)
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
    fn compute_child_layout(&mut self, node_id: NodeId, inputs: taffy::tree::LayoutInput) -> taffy::tree::LayoutOutput {
        compute_cached_layout(self, node_id, inputs, |parent, node_id, inputs| {
            let node = parent.node_from_id_mut(node_id);
            let font_metrics = FontMetrics { char_width: 10.0, char_height: 10.0 };

            match node.kind {
                NodeKind::Flexbox => compute_flexbox_layout(node, node_id, inputs),
                NodeKind::Grid => compute_grid_layout(node, node_id, inputs),
                NodeKind::Text => compute_leaf_layout(inputs, &node.style, |known_dimensions, available_space| {
                    text_measure_function(
                        known_dimensions,
                        available_space,
                        node.text_data.as_ref().unwrap(),
                        &font_metrics,
                    )
                }),
                NodeKind::Image => compute_leaf_layout(inputs, &node.style, |known_dimensions, _available_space| {
                    image_measure_function(known_dimensions, node.image_data.as_ref().unwrap())
                }),
            }
        })
    }
examples/custom_tree_owned_unsafe.rs (line 151)
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
    fn compute_child_layout(&mut self, node_id: NodeId, inputs: taffy::tree::LayoutInput) -> taffy::tree::LayoutOutput {
        compute_cached_layout(self, node_id, inputs, |tree, node_id, inputs| {
            let node = unsafe { node_from_id_mut(node_id) };
            let font_metrics = FontMetrics { char_width: 10.0, char_height: 10.0 };

            match node.kind {
                NodeKind::Flexbox => compute_flexbox_layout(tree, node_id, inputs),
                NodeKind::Grid => compute_grid_layout(tree, node_id, inputs),
                NodeKind::Text => compute_leaf_layout(inputs, &node.style, |known_dimensions, available_space| {
                    text_measure_function(
                        known_dimensions,
                        available_space,
                        node.text_data.as_ref().unwrap(),
                        &font_metrics,
                    )
                }),
                NodeKind::Image => compute_leaf_layout(inputs, &node.style, |known_dimensions, _available_space| {
                    image_measure_function(known_dimensions, node.image_data.as_ref().unwrap())
                }),
            }
        })
    }