mirror of
https://github.com/penpot/penpot.git
synced 2025-07-14 08:27:16 +02:00
🐛 Fix some problems with modifiers
This commit is contained in:
parent
1a705cee24
commit
a85a42d367
10 changed files with 138 additions and 99 deletions
|
@ -362,36 +362,41 @@ pub extern "C" fn propagate_modifiers(pixel_precision: bool) -> *mut u8 {
|
|||
.collect();
|
||||
|
||||
with_state!(state, {
|
||||
let (result, _) = shapes::propagate_modifiers(state, &entries, pixel_precision);
|
||||
let result = shapes::propagate_modifiers(state, &entries, pixel_precision);
|
||||
mem::write_vec(result)
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn propagate_apply(pixel_precision: bool) -> *mut u8 {
|
||||
pub extern "C" fn get_selection_rect() -> *mut u8 {
|
||||
let bytes = mem::bytes();
|
||||
|
||||
let entries: Vec<_> = bytes
|
||||
.chunks(size_of::<<TransformEntry as SerializableResult>::BytesType>())
|
||||
.map(|data| TransformEntry::from_bytes(data.try_into().unwrap()))
|
||||
let entries: Vec<Uuid> = bytes
|
||||
.chunks(16)
|
||||
.map(|bytes| {
|
||||
uuid_from_u32_quartet(
|
||||
u32::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]),
|
||||
u32::from_le_bytes([bytes[4], bytes[5], bytes[6], bytes[7]]),
|
||||
u32::from_le_bytes([bytes[8], bytes[9], bytes[10], bytes[11]]),
|
||||
u32::from_le_bytes([bytes[12], bytes[13], bytes[14], bytes[15]]),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
with_state!(state, {
|
||||
let (result, bounds) = shapes::propagate_modifiers(state, &entries, pixel_precision);
|
||||
|
||||
for entry in result {
|
||||
state.modifiers.insert(entry.id, entry.transform);
|
||||
}
|
||||
state.rebuild_modifier_tiles();
|
||||
|
||||
mem::free_bytes();
|
||||
|
||||
let bbs: Vec<_> = entries.iter().flat_map(|e| bounds.get(&e.id)).collect();
|
||||
let bbs: Vec<_> = entries
|
||||
.iter()
|
||||
.flat_map(|id| {
|
||||
let default = Matrix::default();
|
||||
let modifier = state.modifiers.get(id).unwrap_or(&default);
|
||||
state.shapes.get(id).map(|b| b.bounds().transform(modifier))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let result_bound = if bbs.len() == 1 {
|
||||
bbs[0]
|
||||
} else {
|
||||
&Bounds::join_bounds(&bbs)
|
||||
Bounds::join_bounds(&bbs)
|
||||
};
|
||||
|
||||
let width = result_bound.width();
|
||||
|
@ -410,7 +415,6 @@ pub extern "C" fn propagate_apply(pixel_precision: bool) -> *mut u8 {
|
|||
bytes[28..32].clone_from_slice(&transform[4].to_le_bytes());
|
||||
bytes[32..36].clone_from_slice(&transform[2].to_le_bytes());
|
||||
bytes[36..40].clone_from_slice(&transform[5].to_le_bytes());
|
||||
|
||||
mem::write_bytes(bytes)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ impl Bounds {
|
|||
Self { nw, ne, se, sw }
|
||||
}
|
||||
|
||||
pub fn join_bounds(bounds: &[&Bounds]) -> Self {
|
||||
pub fn join_bounds(bounds: &[Bounds]) -> Self {
|
||||
let (min_x, min_y, max_x, max_y) =
|
||||
bounds
|
||||
.iter()
|
||||
|
|
|
@ -132,7 +132,7 @@ pub fn propagate_modifiers(
|
|||
state: &State,
|
||||
modifiers: &[TransformEntry],
|
||||
pixel_precision: bool,
|
||||
) -> (Vec<TransformEntry>, HashMap<Uuid, Bounds>) {
|
||||
) -> Vec<TransformEntry> {
|
||||
let shapes = &state.shapes;
|
||||
|
||||
let font_col = state.render_state.fonts.font_collection();
|
||||
|
@ -341,13 +341,10 @@ pub fn propagate_modifiers(
|
|||
layout_reflows = Vec::new();
|
||||
}
|
||||
|
||||
(
|
||||
modifiers
|
||||
.iter()
|
||||
.map(|(key, val)| TransformEntry::new(*key, *val))
|
||||
.collect(),
|
||||
bounds,
|
||||
)
|
||||
modifiers
|
||||
.iter()
|
||||
.map(|(key, val)| TransformEntry::new(*key, *val))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -64,7 +64,6 @@ fn calculate_tracks(
|
|||
set_fr_value(is_column, shape, layout_data, &mut tracks, layout_size);
|
||||
stretch_tracks(is_column, shape, layout_data, &mut tracks, layout_size);
|
||||
assign_anchors(is_column, layout_data, layout_bounds, &mut tracks);
|
||||
|
||||
tracks
|
||||
}
|
||||
|
||||
|
@ -386,9 +385,10 @@ fn stretch_tracks(
|
|||
tracks: &mut [TrackData],
|
||||
layout_size: f32,
|
||||
) {
|
||||
if (column
|
||||
&& (layout_data.justify_content != JustifyContent::Stretch
|
||||
|| shape.is_layout_horizontal_auto()))
|
||||
if (tracks.is_empty()
|
||||
|| column
|
||||
&& (layout_data.justify_content != JustifyContent::Stretch
|
||||
|| shape.is_layout_horizontal_auto()))
|
||||
|| (!column
|
||||
&& (layout_data.align_content != AlignContent::Stretch
|
||||
|| shape.is_layout_vertical_auto()))
|
||||
|
@ -462,7 +462,11 @@ fn assign_anchors(
|
|||
)
|
||||
};
|
||||
|
||||
let tot_gap = gap * (tracks.len() - 1) as f32;
|
||||
let tot_gap = if tracks.is_empty() {
|
||||
0.0
|
||||
} else {
|
||||
gap * (tracks.len() - 1) as f32
|
||||
};
|
||||
let tot_size = tot_track_length + tot_gap;
|
||||
let padding = padding_start + padding_end;
|
||||
let pad_size = size - padding;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue