mirror of
https://github.com/penpot/penpot.git
synced 2025-06-19 07:31:37 +02:00
🐛 Fix some problems with layouts
This commit is contained in:
parent
6cd2c712ab
commit
5d42b9793b
6 changed files with 30 additions and 7 deletions
|
@ -262,10 +262,10 @@
|
|||
|
||||
[x y width height]
|
||||
(if (features/active-feature? @st/state "render-wasm/v1")
|
||||
(let [{:keys [width height]} (wasm.api/text-dimensions shape-id)
|
||||
(let [{:keys [max-width height]} (wasm.api/text-dimensions shape-id)
|
||||
{:keys [x y]} (:selrect shape)]
|
||||
|
||||
[x y width height])
|
||||
[x y max-width height])
|
||||
|
||||
(let [bounds (gst/shape->rect shape)
|
||||
x (mth/min (dm/get-prop bounds :x)
|
||||
|
|
|
@ -620,9 +620,10 @@
|
|||
(let [offset (h/call wasm/internal-module "_get_text_dimensions")
|
||||
heapf32 (mem/get-heap-f32)
|
||||
width (aget heapf32 (mem/ptr8->ptr32 offset))
|
||||
height (aget heapf32 (mem/ptr8->ptr32 (+ offset 4)))]
|
||||
height (aget heapf32 (mem/ptr8->ptr32 (+ offset 4)))
|
||||
max-width (aget heapf32 (mem/ptr8->ptr32 (+ offset 8)))]
|
||||
(h/call wasm/internal-module "_free_bytes")
|
||||
{:width width :height height})))
|
||||
{:width width :height height :max-width max-width})))
|
||||
|
||||
(defn set-view-box
|
||||
[zoom vbox]
|
||||
|
|
|
@ -210,6 +210,10 @@ pub fn propagate_modifiers(
|
|||
shape_modif.post_concat(&transform);
|
||||
modifiers.insert(shape.id, shape_modif);
|
||||
|
||||
if shape.has_layout() {
|
||||
entries.push_back(Modifier::reflow(shape.id));
|
||||
}
|
||||
|
||||
if let Some(parent) = shape.parent_id.and_then(|id| shapes.get(&id)) {
|
||||
if parent.has_layout() || parent.is_group_like() {
|
||||
entries.push_back(Modifier::reflow(parent.id));
|
||||
|
|
|
@ -187,7 +187,7 @@ fn initialize_tracks(
|
|||
let mut children = modified_children_ids(shape, structure.get(&shape.id));
|
||||
let mut first = true;
|
||||
|
||||
if !flex_data.is_reverse() {
|
||||
if flex_data.is_reverse() {
|
||||
children.reverse();
|
||||
}
|
||||
|
||||
|
@ -497,6 +497,14 @@ fn next_anchor(
|
|||
prev_anchor: Point,
|
||||
total_shapes_size: f32,
|
||||
) -> Point {
|
||||
if layout_axis.is_auto_main {
|
||||
let delta = child_axis.margin_main_start
|
||||
+ child_axis.margin_main_end
|
||||
+ child_axis.main_size
|
||||
+ layout_axis.gap_main;
|
||||
return prev_anchor + layout_axis.main_v * delta;
|
||||
}
|
||||
|
||||
let delta = child_axis.margin_main_start
|
||||
+ child_axis.margin_main_end
|
||||
+ match layout_data.justify_content {
|
||||
|
|
|
@ -551,6 +551,13 @@ pub fn auto_width(paragraphs: &[Vec<skia::textlayout::Paragraph>]) -> f32 {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn max_width(paragraphs: &[Vec<skia::textlayout::Paragraph>]) -> f32 {
|
||||
paragraphs
|
||||
.iter()
|
||||
.flatten()
|
||||
.fold(0.0, |max_width, p| f32::max(p.max_width(), max_width))
|
||||
}
|
||||
|
||||
pub fn auto_height(paragraphs: &[Vec<skia::textlayout::Paragraph>]) -> f32 {
|
||||
paragraphs
|
||||
.iter()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::mem;
|
||||
use crate::shapes::{auto_height, auto_width, GrowType, RawTextData, Type};
|
||||
use crate::shapes::{auto_height, auto_width, max_width, GrowType, RawTextData, Type};
|
||||
|
||||
use crate::STATE;
|
||||
use crate::{with_current_shape, with_state};
|
||||
|
@ -42,6 +42,7 @@ pub extern "C" fn get_text_dimensions() -> *mut u8 {
|
|||
|
||||
let mut width = 0.01;
|
||||
let mut height = 0.01;
|
||||
let mut m_width = 0.01;
|
||||
with_current_shape!(state, |shape: &mut Shape| {
|
||||
width = shape.selrect.width();
|
||||
height = shape.selrect.height();
|
||||
|
@ -49,14 +50,16 @@ pub extern "C" fn get_text_dimensions() -> *mut u8 {
|
|||
if let Type::Text(content) = &shape.shape_type {
|
||||
let paragraphs = content.get_skia_paragraphs(font_col);
|
||||
height = auto_height(¶graphs).ceil();
|
||||
m_width = max_width(¶graphs);
|
||||
if content.grow_type() == GrowType::AutoWidth {
|
||||
width = auto_width(¶graphs).ceil();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let mut bytes = vec![0; 8];
|
||||
let mut bytes = vec![0; 12];
|
||||
bytes[0..4].clone_from_slice(&width.to_le_bytes());
|
||||
bytes[4..8].clone_from_slice(&height.to_le_bytes());
|
||||
bytes[8..12].clone_from_slice(&m_width.to_le_bytes());
|
||||
mem::write_bytes(bytes)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue