🐛 Fix wasm layout problems

This commit is contained in:
alonso.torres 2025-06-18 10:36:29 +02:00
parent b2647f30c2
commit 58e5748b4f
4 changed files with 36 additions and 25 deletions

View file

@ -412,7 +412,7 @@ pub fn resize_matrix(
parent_transform.post_translate(center);
parent_transform.pre_translate(-center);
let parent_transform_inv = &parent_transform.invert().unwrap();
let parent_transform_inv = &parent_transform.invert().unwrap_or_default();
let origin = parent_transform_inv.map_point(child_bounds.nw);
let mut scale = Matrix::scale((scale_width, scale_height));

View file

@ -115,23 +115,29 @@ fn set_pixel_precision(transform: &mut Matrix, bounds: &mut Bounds) {
let x = bounds.min_x().round();
let y = bounds.min_y().round();
let mut round_transform = Matrix::scale((
bounds.width().round() / bounds.width(),
bounds.height().round() / bounds.height(),
));
let scale_width = f32::max(0.01, bounds.width().round() / bounds.width());
let scale_height = f32::max(0.01, bounds.height().round() / bounds.height());
if f32::is_finite(scale_width)
&& f32::is_finite(scale_height)
&& (!math::is_close_to(scale_width, 1.0) || !math::is_close_to(scale_height, 1.0))
{
let mut round_transform = Matrix::scale((scale_width, scale_height));
round_transform.post_concat(&tr);
round_transform.pre_concat(&tr_inv);
transform.post_concat(&round_transform);
bounds.transform_mut(&round_transform);
}
let dx = x - bounds.min_x();
let dy = y - bounds.min_y();
if f32::is_finite(dx) && f32::is_finite(dy) {
let round_transform = Matrix::translate((dx, dy));
transform.post_concat(&round_transform);
bounds.transform_mut(&round_transform);
}
}
pub fn propagate_modifiers(
state: &State,

View file

@ -11,26 +11,26 @@ pub fn calculate_resize(
) -> Option<(f32, f32)> {
let scale_width = match constraint_h {
ConstraintH::Left | ConstraintH::Right | ConstraintH::Center => {
parent_before.width() / parent_after.width()
parent_before.width() / f32::max(0.01, parent_after.width())
}
ConstraintH::LeftRight => {
let left = parent_before.left(child_before.nw);
let right = parent_before.right(child_before.ne);
let target_width = parent_after.width() - left - right;
target_width / child_after.width()
target_width / f32::max(0.01, child_after.width())
}
_ => 1.0,
};
let scale_height = match constraint_v {
ConstraintV::Top | ConstraintV::Bottom | ConstraintV::Center => {
parent_before.height() / parent_after.height()
parent_before.height() / f32::max(0.01, parent_after.height())
}
ConstraintV::TopBottom => {
let top = parent_before.top(child_before.nw);
let bottom = parent_before.bottom(child_before.sw);
let target_height = parent_after.height() - top - bottom;
target_height / child_after.height()
target_height / f32::max(0.01, child_after.height())
}
_ => 1.0,
};

View file

@ -269,7 +269,11 @@ fn initialize_tracks(
// Resize main axis fill
fn distribute_fill_main_space(layout_axis: &LayoutAxis, tracks: &mut [TrackData]) {
for track in tracks.iter_mut() {
let mut left_space = layout_axis.main_space() - track.main_size;
let mut left_space = if layout_axis.is_auto_main {
0.0
} else {
layout_axis.main_space() - track.main_size
};
let mut to_resize_children: Vec<&mut ChildAxis> = Vec::new();
for child in track.shapes.iter_mut() {
@ -299,7 +303,13 @@ fn distribute_fill_main_space(layout_axis: &LayoutAxis, tracks: &mut [TrackData]
fn distribute_fill_across_space(layout_axis: &LayoutAxis, tracks: &mut [TrackData]) {
let total_across_size = tracks.iter().map(|t| t.across_size).sum::<f32>()
+ (tracks.len() - 1) as f32 * layout_axis.gap_across;
let mut left_space = layout_axis.across_space() - total_across_size;
let mut left_space = if layout_axis.is_auto_across {
0.0
} else {
layout_axis.across_space() - total_across_size
};
let mut to_resize_tracks: Vec<&mut TrackData> = Vec::new();
for track in tracks.iter_mut() {
@ -435,13 +445,8 @@ fn calculate_track_data(
structure,
);
if !layout_axis.is_auto_main {
distribute_fill_main_space(&layout_axis, &mut tracks);
}
if !layout_axis.is_auto_across {
distribute_fill_across_space(&layout_axis, &mut tracks);
}
let total_across_size = tracks.iter().map(|t| t.across_size).sum::<f32>();