Upgrade taffy (flexbox layout engine).

No observable behavioral changes. It's possible the widgetry Table
rendering can now be simplified with some of the new spacing added.
This commit is contained in:
Dustin Carlino 2022-11-25 11:40:46 +00:00
parent ede907e239
commit dfae1b54d5
4 changed files with 31 additions and 50 deletions

25
Cargo.lock generated
View File

@ -1798,17 +1798,6 @@ dependencies = [
"byteorder",
]
[[package]]
name = "hash32-derive"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59d2aba832b60be25c1b169146b27c64115470981b128ed84c8db18c1b03c6ff"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "hashbrown"
version = "0.9.1"
@ -4148,15 +4137,13 @@ dependencies = [
[[package]]
name = "taffy"
version = "0.1.0"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec27dea659b100d489dffa57cf0efc6d7bfefb119af817b92cc14006c0b214e3"
checksum = "776e2242305d6fc8a54f1571b76af293e1f1d2b6ee547ed5863d9638258bb58a"
dependencies = [
"arrayvec 0.7.2",
"hash32",
"hash32-derive",
"num-traits",
"typenum",
"slotmap",
]
[[package]]
@ -4425,12 +4412,6 @@ version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c74c96594835e10fa545e2a51e8709f30b173a092bfd6036ef2cec53376244f3"
[[package]]
name = "typenum"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06"
[[package]]
name = "ucd-trie"
version = "0.1.3"

View File

@ -34,7 +34,7 @@ lru = "0.7.1"
lyon = "1.0.0"
serde = { workspace = true }
serde_json = { workspace = true }
taffy = "0.1.0"
taffy = "0.2.0"
tokio = { version ="1.19.2", features=["full"], optional = true }
ttf-parser = "0.15.0"
usvg = { version = "0.22.0", default-features=false, features=["text"] }

View File

@ -1,8 +1,8 @@
use std::collections::HashSet;
use taffy::geometry::{Rect, Size};
use taffy::layout::AvailableSpace;
use taffy::node::{Node, Taffy};
use taffy::number::Number;
use taffy::style::{
AlignItems, Dimension, FlexDirection, FlexWrap, JustifyContent, PositionType, Style,
};
@ -304,7 +304,7 @@ impl Widget {
}
pub fn padding_left(mut self, pixels: usize) -> Widget {
self.layout.style.padding.start = Dimension::Points(pixels as f32);
self.layout.style.padding.left = Dimension::Points(pixels as f32);
self
}
@ -314,7 +314,7 @@ impl Widget {
}
pub fn padding_right(mut self, pixels: usize) -> Widget {
self.layout.style.padding.end = Dimension::Points(pixels as f32);
self.layout.style.padding.right = Dimension::Points(pixels as f32);
self
}
@ -333,16 +333,16 @@ impl Widget {
self
}
pub fn margin_left(mut self, pixels: usize) -> Widget {
self.layout.style.margin.start = Dimension::Points(pixels as f32);
self.layout.style.margin.left = Dimension::Points(pixels as f32);
self
}
pub fn margin_right(mut self, pixels: usize) -> Widget {
self.layout.style.margin.end = Dimension::Points(pixels as f32);
self.layout.style.margin.right = Dimension::Points(pixels as f32);
self
}
pub fn margin_horiz(mut self, pixels: usize) -> Widget {
self.layout.style.margin.start = Dimension::Points(pixels as f32);
self.layout.style.margin.end = Dimension::Points(pixels as f32);
self.layout.style.margin.left = Dimension::Points(pixels as f32);
self.layout.style.margin.right = Dimension::Points(pixels as f32);
self
}
pub fn margin_vert(mut self, pixels: usize) -> Widget {
@ -352,13 +352,13 @@ impl Widget {
}
pub fn align_left(mut self) -> Widget {
self.layout.style.margin.end = Dimension::Auto;
self.layout.style.margin.right = Dimension::Auto;
self
}
pub fn align_right(mut self) -> Widget {
self.layout.style.margin = Rect {
start: Dimension::Auto,
end: Dimension::Undefined,
left: Dimension::Auto,
right: Dimension::Undefined,
top: Dimension::Undefined,
bottom: Dimension::Undefined,
};
@ -366,8 +366,8 @@ impl Widget {
}
pub fn align_bottom(mut self) -> Widget {
self.layout.style.margin = Rect {
start: Dimension::Undefined,
end: Dimension::Undefined,
left: Dimension::Undefined,
right: Dimension::Undefined,
top: Dimension::Auto,
bottom: Dimension::Undefined,
};
@ -376,8 +376,8 @@ impl Widget {
/// This doesn't count against the entire container
pub fn align_vert_center(mut self) -> Widget {
self.layout.style.margin = Rect {
start: Dimension::Undefined,
end: Dimension::Undefined,
left: Dimension::Undefined,
right: Dimension::Undefined,
top: Dimension::Auto,
bottom: Dimension::Auto,
};
@ -387,8 +387,8 @@ impl Widget {
fn abs(mut self, x: f64, y: f64) -> Widget {
self.layout.style.position_type = PositionType::Absolute;
self.layout.style.position = Rect {
start: Dimension::Points(x as f32),
end: Dimension::Undefined,
left: Dimension::Points(x as f32),
right: Dimension::Undefined,
top: Dimension::Points(y as f32),
bottom: Dimension::Undefined,
};
@ -521,7 +521,7 @@ impl Widget {
{
let mut taffy = Taffy::new();
let root = taffy
.new_node(
.new_with_children(
Style {
..Default::default()
},
@ -534,8 +534,8 @@ impl Widget {
nodes.reverse();
let container_size = Size {
width: Number::Undefined,
height: Number::Undefined,
width: AvailableSpace::MaxContent,
height: AvailableSpace::MaxContent,
};
taffy.compute_layout(root, container_size).unwrap();
@ -609,7 +609,7 @@ impl Widget {
} else {
FlexDirection::Column
};
let node = taffy.new_node(style, &[]).unwrap();
let node = taffy.new_with_children(style, &[]).unwrap();
nodes.push(node);
for widget in &container.members {
widget.get_flexbox(node, taffy, nodes);
@ -620,7 +620,7 @@ impl Widget {
width: Dimension::Points(self.widget.get_dims().width as f32),
height: Dimension::Points(self.widget.get_dims().height as f32),
};
let node = taffy.new_node(style, &[]).unwrap();
let node = taffy.new_with_children(style, &[]).unwrap();
taffy.add_child(parent, node).unwrap();
nodes.push(node);
}
@ -878,8 +878,8 @@ impl From<f64> for EdgeInsets {
impl From<EdgeInsets> for Rect<Dimension> {
fn from(insets: EdgeInsets) -> Rect<Dimension> {
Rect {
start: Dimension::Points(insets.left as f32),
end: Dimension::Points(insets.right as f32),
left: Dimension::Points(insets.left as f32),
right: Dimension::Points(insets.right as f32),
top: Dimension::Points(insets.top as f32),
bottom: Dimension::Points(insets.bottom as f32),
}

View File

@ -3,8 +3,8 @@ use std::collections::HashSet;
use std::rc::Rc;
use taffy::geometry::Size;
use taffy::layout::AvailableSpace;
use taffy::node::{Node, Taffy};
use taffy::number::Number;
use taffy::style::{Dimension, Style};
use geom::Polygon;
@ -168,7 +168,7 @@ impl Panel {
fn compute_flexbox(&self) -> (Taffy, Vec<Node>, ScreenDims) {
let mut taffy = Taffy::new();
let root = taffy
.new_node(
.new_with_children(
Style {
..Default::default()
},
@ -182,8 +182,8 @@ impl Panel {
// TODO Express more simply. Constraining this seems useless.
let container_size = Size {
width: Number::Undefined,
height: Number::Undefined,
width: AvailableSpace::MaxContent,
height: AvailableSpace::MaxContent,
};
taffy.compute_layout(root, container_size).unwrap();