mirror of
https://github.com/penpot/penpot.git
synced 2025-07-26 20:27:22 +02:00
🐛 Fix wasm layout problems
This commit is contained in:
parent
b2647f30c2
commit
58e5748b4f
4 changed files with 36 additions and 25 deletions
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
distribute_fill_main_space(&layout_axis, &mut tracks);
|
||||
distribute_fill_across_space(&layout_axis, &mut tracks);
|
||||
|
||||
let total_across_size = tracks.iter().map(|t| t.across_size).sum::<f32>();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue