Skip to content

Commit

Permalink
chore: update taffy
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin271 committed Jan 8, 2024
1 parent 96db134 commit 93fb127
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
36 changes: 21 additions & 15 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.;
Expand Down Expand Up @@ -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),
Expand All @@ -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()
Expand All @@ -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)
})),
)?);
}
Expand All @@ -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)
})),
)?);
}
Expand Down
5 changes: 1 addition & 4 deletions src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Option<f32>>,
available_space: TaffySize<taffy::style::AvailableSpace>,
Expand Down

0 comments on commit 93fb127

Please sign in to comment.