pub trait LayoutPartialTree: TraversePartialTree {
type CoreContainerStyle<'a>: CoreStyle<CustomIdent = Self::CustomIdent>
where Self: 'a;
type CustomIdent: CheapCloneStr;
// Required methods
fn get_core_container_style(
&self,
node_id: NodeId,
) -> Self::CoreContainerStyle<'_>;
fn set_unrounded_layout(&mut self, node_id: NodeId, layout: &Layout);
fn compute_child_layout(
&mut self,
node_id: NodeId,
inputs: LayoutInput,
) -> LayoutOutput;
// Provided method
fn resolve_calc_value(&self, val: *const (), basis: f32) -> f32 { ... }
}Expand description
Any type that implements LayoutPartialTree can be laid out using Takia’s algorithms
Note that this trait extends TraversePartialTree (not TraverseTree). Takia’s algorithm implementations have been designed such that they can be used for a laying out a single
node that only has access to it’s immediate children.
Required Associated Types§
Sourcetype CoreContainerStyle<'a>: CoreStyle<CustomIdent = Self::CustomIdent>
where
Self: 'a
type CoreContainerStyle<'a>: CoreStyle<CustomIdent = Self::CustomIdent> where Self: 'a
The style type representing the core container styles that all containers should have Used when laying out the root node of a tree
Sourcetype CustomIdent: CheapCloneStr
type CustomIdent: CheapCloneStr
String type for representing “custom identifiers” (for example, named grid lines or areas)
If you are unsure what to use here then consider Arc<str>.
Required Methods§
Sourcefn get_core_container_style(
&self,
node_id: NodeId,
) -> Self::CoreContainerStyle<'_>
fn get_core_container_style( &self, node_id: NodeId, ) -> Self::CoreContainerStyle<'_>
Get core style
Only called for the node being laid out, never for its children (those go through the
get_*_child_style methods), so it may be expressed in the node’s own axes while child
styles are expressed in the axes of the node laying them out.
Sourcefn set_unrounded_layout(&mut self, node_id: NodeId, layout: &Layout)
fn set_unrounded_layout(&mut self, node_id: NodeId, layout: &Layout)
Set the node’s unrounded layout
Sourcefn compute_child_layout(
&mut self,
node_id: NodeId,
inputs: LayoutInput,
) -> LayoutOutput
fn compute_child_layout( &mut self, node_id: NodeId, inputs: LayoutInput, ) -> LayoutOutput
Compute the specified node’s size or full layout given the specified constraints
Provided Methods§
Sourcefn resolve_calc_value(&self, val: *const (), basis: f32) -> f32
fn resolve_calc_value(&self, val: *const (), basis: f32) -> f32
Resolve calc value
Examples found in repository?
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 }Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".