diff --git a/Cargo.lock b/Cargo.lock index d7996460..d555dacb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3990,8 +3990,9 @@ dependencies = [ [[package]] name = "taffy" -version = "0.3.11" -source = "git+https://github.com/DioxusLabs/taffy?rev=d338f3731da519d182bbc074de46382984ab7c4a#d338f3731da519d182bbc074de46382984ab7c4a" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c2287b6d7f721ada4cddf61ade5e760b2c6207df041cac9bfaa192897362fd3" dependencies = [ "arrayvec", "grid", diff --git a/Cargo.toml b/Cargo.toml index 29a78f09..a44ff64c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,7 @@ indexmap = { version = "2.1.0", features = ["serde"] } html-escape = "0.2.13" fxhash = "0.2.1" twox-hash = "1.6.3" -taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "d338f3731da519d182bbc074de46382984ab7c4a" } +taffy = "0.3.18" syntect = "5.1.0" smart-debug = "0.0.3" two-face = "0.3.0" diff --git a/src/table.rs b/src/table.rs index d2abe4d6..a2466c6e 100644 --- a/src/table.rs +++ b/src/table.rs @@ -3,11 +3,11 @@ use std::sync::Arc; use crate::text::{Text, TextBox, TextBoxMeasure, TextSystem}; use crate::utils::{default, Point, Rect, Size}; +use taffy::node::MeasureFunc; use taffy::prelude::{ - auto, length, line, AvailableSpace, Display, Layout, Size as TaffySize, Style, Taffy, + auto, line, points, AvailableSpace, Display, Layout, Size as TaffySize, Style, Taffy, }; use taffy::style::JustifyContent; -use taffy::tree::MeasureFunc; pub const TABLE_ROW_GAP: f32 = 20.; pub const TABLE_COL_GAP: f32 = 20.; @@ -93,7 +93,7 @@ impl Table { let root_style = Style { display: Display::Flex, size: TaffySize { - width: length(bounds.0), + width: points(bounds.0), height: auto(), }, justify_content: Some(JustifyContent::Start), @@ -103,8 +103,8 @@ impl Table { let grid_style = Style { display: Display::Grid, gap: TaffySize { - width: length(TABLE_COL_GAP), - height: length(TABLE_ROW_GAP), + width: points(TABLE_COL_GAP), + height: points(TABLE_ROW_GAP), }, grid_template_columns: vec![auto(); max_columns], ..default() @@ -114,17 +114,20 @@ impl Table { let mut node_row = Vec::new(); // Define the child nodes for (x, header) in self.headers.iter().enumerate() { + let textbox_measure = TextBoxMeasure { + font_system: text_system.font_system.clone(), + text_cache: text_system.text_cache.clone(), + textbox: Arc::new(header.clone()), + zoom, + }; node_row.push(taffy.new_leaf_with_measure( Style { grid_row: line(1), grid_column: line(x as i16 + 1), ..default() }, - MeasureFunc::Boxed(Box::new(TextBoxMeasure { - font_system: text_system.font_system.clone(), - text_cache: text_system.text_cache.clone(), - textbox: Arc::new(header.clone()), - zoom, + MeasureFunc::Boxed(Box::new(move |known_dimensions, available_space| { + textbox_measure.measure(known_dimensions, available_space) })), )?); } @@ -134,17 +137,20 @@ impl Table { for (y, row) in self.rows.iter().enumerate() { for (x, item) in row.iter().enumerate() { let item = item.clone(); + let textbox_measure = TextBoxMeasure { + font_system: text_system.font_system.clone(), + text_cache: text_system.text_cache.clone(), + textbox: Arc::new(item.clone()), + zoom, + }; node_row.push(taffy.new_leaf_with_measure( Style { grid_row: line(1 + y as i16 + 1), grid_column: line(x as i16 + 1), ..default() }, - MeasureFunc::Boxed(Box::new(TextBoxMeasure { - font_system: text_system.font_system.clone(), - text_cache: text_system.text_cache.clone(), - textbox: Arc::new(item.clone()), - zoom, + MeasureFunc::Boxed(Box::new(move |known_dimensions, available_space| { + textbox_measure.measure(known_dimensions, available_space) })), )?); } diff --git a/src/text.rs b/src/text.rs index eabff96f..32e935e5 100644 --- a/src/text.rs +++ b/src/text.rs @@ -14,7 +14,6 @@ use glyphon::{ }; use smart_debug::SmartDebug; use taffy::prelude::{AvailableSpace, Size as TaffySize}; -use taffy::tree::Measurable; type KeyHash = u64; type HashBuilder = twox_hash::RandomXxHashBuilder64; @@ -31,10 +30,8 @@ impl TextBoxMeasure { self.textbox .size_without_system(&self.text_cache, &self.font_system, bounds, self.zoom) } -} -impl Measurable for TextBoxMeasure { - fn measure( + pub fn measure( &self, known_dimensions: TaffySize>, available_space: TaffySize,