🐛 Fix some problems with layouts

This commit is contained in:
alonso.torres 2025-05-21 10:41:42 +02:00
parent 6cd2c712ab
commit 5d42b9793b
6 changed files with 30 additions and 7 deletions

View file

@ -262,10 +262,10 @@
[x y width height] [x y width height]
(if (features/active-feature? @st/state "render-wasm/v1") (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)] {:keys [x y]} (:selrect shape)]
[x y width height]) [x y max-width height])
(let [bounds (gst/shape->rect shape) (let [bounds (gst/shape->rect shape)
x (mth/min (dm/get-prop bounds :x) x (mth/min (dm/get-prop bounds :x)

View file

@ -620,9 +620,10 @@
(let [offset (h/call wasm/internal-module "_get_text_dimensions") (let [offset (h/call wasm/internal-module "_get_text_dimensions")
heapf32 (mem/get-heap-f32) heapf32 (mem/get-heap-f32)
width (aget heapf32 (mem/ptr8->ptr32 offset)) 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") (h/call wasm/internal-module "_free_bytes")
{:width width :height height}))) {:width width :height height :max-width max-width})))
(defn set-view-box (defn set-view-box
[zoom vbox] [zoom vbox]

View file

@ -210,6 +210,10 @@ pub fn propagate_modifiers(
shape_modif.post_concat(&transform); shape_modif.post_concat(&transform);
modifiers.insert(shape.id, shape_modif); 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 let Some(parent) = shape.parent_id.and_then(|id| shapes.get(&id)) {
if parent.has_layout() || parent.is_group_like() { if parent.has_layout() || parent.is_group_like() {
entries.push_back(Modifier::reflow(parent.id)); entries.push_back(Modifier::reflow(parent.id));

View file

@ -187,7 +187,7 @@ fn initialize_tracks(
let mut children = modified_children_ids(shape, structure.get(&shape.id)); let mut children = modified_children_ids(shape, structure.get(&shape.id));
let mut first = true; let mut first = true;
if !flex_data.is_reverse() { if flex_data.is_reverse() {
children.reverse(); children.reverse();
} }
@ -497,6 +497,14 @@ fn next_anchor(
prev_anchor: Point, prev_anchor: Point,
total_shapes_size: f32, total_shapes_size: f32,
) -> Point { ) -> 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 let delta = child_axis.margin_main_start
+ child_axis.margin_main_end + child_axis.margin_main_end
+ match layout_data.justify_content { + match layout_data.justify_content {

View file

@ -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 { pub fn auto_height(paragraphs: &[Vec<skia::textlayout::Paragraph>]) -> f32 {
paragraphs paragraphs
.iter() .iter()

View file

@ -1,5 +1,5 @@
use crate::mem; 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::STATE;
use crate::{with_current_shape, with_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 width = 0.01;
let mut height = 0.01; let mut height = 0.01;
let mut m_width = 0.01;
with_current_shape!(state, |shape: &mut Shape| { with_current_shape!(state, |shape: &mut Shape| {
width = shape.selrect.width(); width = shape.selrect.width();
height = shape.selrect.height(); 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 { if let Type::Text(content) = &shape.shape_type {
let paragraphs = content.get_skia_paragraphs(font_col); let paragraphs = content.get_skia_paragraphs(font_col);
height = auto_height(&paragraphs).ceil(); height = auto_height(&paragraphs).ceil();
m_width = max_width(&paragraphs);
if content.grow_type() == GrowType::AutoWidth { if content.grow_type() == GrowType::AutoWidth {
width = auto_width(&paragraphs).ceil(); width = auto_width(&paragraphs).ceil();
} }
} }
}); });
let mut bytes = vec![0; 8]; let mut bytes = vec![0; 12];
bytes[0..4].clone_from_slice(&width.to_le_bytes()); bytes[0..4].clone_from_slice(&width.to_le_bytes());
bytes[4..8].clone_from_slice(&height.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) mem::write_bytes(bytes)
} }