You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Available space on compute_layout_with_measure() to be fixed 512x512.
Changed image size to be 600x720, so that aspect ratio could cause overflow of the layout.
Added flex_shrink: 1 to children Styles in hopes it would fix calculation.
Root node size fills available space with percent(1.0).
Modified measure.rs follows:
mod common {pubmod image;pubmod text;}use common::image::{image_measure_function,ImageContext};use common::text::{text_measure_function,FontMetrics,TextContext,WritingMode,LOREM_IPSUM};use taffy::prelude::*;enumNodeContext{Text(TextContext),Image(ImageContext),}fnmeasure_function(known_dimensions: taffy::geometry::Size<Option<f32>>,available_space: taffy::geometry::Size<taffy::style::AvailableSpace>,node_context:Option<&mutNodeContext>,font_metrics:&FontMetrics,) -> Size<f32>{ifletSize{width:Some(width),height:Some(height)} = known_dimensions {returnSize{ width, height };}match node_context {None => Size::ZERO,Some(NodeContext::Text(text_context)) => {text_measure_function(known_dimensions, available_space,&*text_context, font_metrics)}Some(NodeContext::Image(image_context)) => image_measure_function(known_dimensions, image_context),}}fnmain() -> Result<(), taffy::TaffyError>{letmut taffy:TaffyTree<NodeContext> = TaffyTree::new();let font_metrics = FontMetrics{char_width:10.0,char_height:10.0};let text_node = taffy.new_leaf_with_context(Style{flex_shrink:1.0,
..Default::default()},NodeContext::Text(TextContext{text_content:LOREM_IPSUM.into(),writing_mode:WritingMode::Horizontal}),)?;let image_node = taffy
.new_leaf_with_context(Style{flex_shrink:1.0,
..Default::default()},NodeContext::Image(ImageContext{width:600.0,height:720.0}))?;let root = taffy.new_with_children(Style{display:Display::Flex,flex_direction:FlexDirection::Column,size:percent(1.0),
..Default::default()},&[text_node, image_node],)?;// Compute layout and print result
taffy.compute_layout_with_measure(
root,Size{width: taffy::AvailableSpace::Definite(512.0),height: taffy::AvailableSpace::Definite(512.0)},// Note: this closure is a FnMut closure and can be used to borrow external context for the duration of layout// For example, you may wish to borrow a global font registry and pass it into your text measuring function
|known_dimensions, available_space, _node_id, node_context, _style| {measure_function(known_dimensions, available_space, node_context,&font_metrics)},)?;
taffy.print_tree(root);Ok(())}
what were you expecting?
Leaf children should fit into available space.
what actually happened?
Second leaf overflows layout.
Additional information
I've tried different style configurations, including flex-basis, but all seems to come down to a measure_function which does not receive full information from a parent to properly size image content that would fit the layout.
This seems like a legitimate bug. I think the root of the problem here is that we need to treat "replaced" content such as images specially (how exactly, I'm not quite sure). You might be able to work around it by returning a zero size when the MinContent size is requested.
I tried returning Size::ZERO when AvailableSpace::MIN_CONTENT, it now fits perfectly but the whole point of keeping aspect ratio of an image with measure_function is sadly gone (layout bounds are now stretched).
taffy
version02453b2 and fae17c2 (v0.6.1)
Platform
Rust
What you did
I took
examples/measure.rs
and changed:compute_layout_with_measure()
to be fixed 512x512.flex_shrink: 1
to childrenStyle
s in hopes it would fix calculation.size
fills available space withpercent(1.0)
.Modified
measure.rs
follows:Result is:
Second leaf height overflows available space.
What went wrong
what were you expecting?
Leaf children should fit into available space.
what actually happened?
Second leaf overflows layout.
Additional information
I've tried different style configurations, including
flex-basis
, but all seems to come down to ameasure_function
which does not receive full information from a parent to properly size image content that would fit the layout.The text was updated successfully, but these errors were encountered: