Skip to content

Commit ff9d812

Browse files
dependabot[bot]echobtfactory-droid[bot]
authored
build(deps): bump taffy from 0.6.3 to 0.14.0 (#32)
* build(deps): bump taffy from 0.6.3 to 0.14.0 Bumps [taffy](https://github.com/DioxusLabs/taffy) from 0.6.3 to 0.14.0. - [Release notes](https://github.com/DioxusLabs/taffy/releases) - [Changelog](https://github.com/DioxusLabs/taffy/blob/main/CHANGELOG.md) - [Commits](DioxusLabs/taffy@v0.6.3...v0.14.0) --- updated-dependencies: - dependency-name: taffy dependency-version: 0.14.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * fix(deps): adapt layout conversions to taffy 0.14 Use compact dimension constructors, expanded values, alignment keywords, and the new min/max size type. Reject unsupported imported dimensions. Add conversion and narrow/wide headless buffer regression tests. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: echobt <154886644+echobt@users.noreply.github.com> Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
1 parent 7e791c0 commit ff9d812

6 files changed

Lines changed: 369 additions & 89 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ ts-rs = { version = "11", features = ["uuid-impl", "serde-json-impl", "no-serde-
357357

358358
# CLI - Additional utilities
359359
ahash = "0.8"
360-
taffy = "0.6"
360+
taffy = "0.14"
361361
bitflags = "2.6"
362362
slotmap = "1.0"
363363
parking_lot = "0.12"

cortex-tui-framework/crates/cortex-tui-layout/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ workspace = true
1212
[dependencies]
1313
taffy = { workspace = true }
1414
slotmap = { workspace = true }
15+
16+
[dev-dependencies]
17+
cortex-tui-buffer = { workspace = true }

cortex-tui-framework/crates/cortex-tui-layout/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@
6666
//! - **Align Items**: Alignment along the cross axis
6767
//! - **Flex Grow/Shrink**: How items grow or shrink to fill space
6868
//!
69+
//! # Taffy integration
70+
//!
71+
//! With Taffy 0.14, importing dimensions uses `TryFrom`: CSS sizing keywords and
72+
//! opaque `calc()` handles return [`UnsupportedDimension`] rather than silently
73+
//! changing the layout. Existing auto, point, and percentage values round-trip.
74+
//! Imported alignment modifiers and balanced wrapping normalize to the supported
75+
//! Cortex alignment and wrapping modes.
76+
//!
6977
//! # Performance
7078
//!
7179
//! The layout system uses dirty tracking to avoid unnecessary recomputation.
@@ -100,6 +108,7 @@ pub use node::{LayoutNode, LayoutNodeBuilder, LayoutStyle};
100108
pub use style::{
101109
AlignContent, AlignItems, AlignSelf, Dimension, Display, Edges, FlexDirection, FlexWrap,
102110
JustifyContent, LengthPercentage, LengthPercentageAuto, Overflow, Position, Size as StyleSize,
111+
UnsupportedDimension,
103112
};
104113
pub use tree::{LayoutError, LayoutNodeKey, LayoutResult, LayoutTree};
105114

cortex-tui-framework/crates/cortex-tui-layout/src/style.rs

Lines changed: 131 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ impl From<taffy_style::FlexWrap> for FlexWrap {
6666
fn from(value: taffy_style::FlexWrap) -> Self {
6767
match value {
6868
taffy_style::FlexWrap::NoWrap => Self::NoWrap,
69-
taffy_style::FlexWrap::Wrap => Self::Wrap,
70-
taffy_style::FlexWrap::WrapReverse => Self::WrapReverse,
69+
// Cortex does not expose balanced wrapping; preserve line direction.
70+
taffy_style::FlexWrap::Wrap | taffy_style::FlexWrap::Balance => Self::Wrap,
71+
taffy_style::FlexWrap::WrapReverse | taffy_style::FlexWrap::BalanceReverse => {
72+
Self::WrapReverse
73+
}
7174
}
7275
}
7376
}
@@ -93,28 +96,30 @@ pub enum JustifyContent {
9396
impl From<JustifyContent> for taffy_style::JustifyContent {
9497
fn from(value: JustifyContent) -> Self {
9598
match value {
96-
JustifyContent::Start => Self::Start,
97-
JustifyContent::End => Self::End,
98-
JustifyContent::Center => Self::Center,
99-
JustifyContent::SpaceBetween => Self::SpaceBetween,
100-
JustifyContent::SpaceAround => Self::SpaceAround,
101-
JustifyContent::SpaceEvenly => Self::SpaceEvenly,
99+
JustifyContent::Start => Self::START,
100+
JustifyContent::End => Self::END,
101+
JustifyContent::Center => Self::CENTER,
102+
JustifyContent::SpaceBetween => Self::SPACE_BETWEEN,
103+
JustifyContent::SpaceAround => Self::SPACE_AROUND,
104+
JustifyContent::SpaceEvenly => Self::SPACE_EVENLY,
102105
}
103106
}
104107
}
105108

106109
impl From<taffy_style::JustifyContent> for JustifyContent {
107110
fn from(value: taffy_style::JustifyContent) -> Self {
108-
match value {
109-
taffy_style::JustifyContent::Start => Self::Start,
110-
taffy_style::JustifyContent::End => Self::End,
111-
taffy_style::JustifyContent::Center => Self::Center,
112-
taffy_style::JustifyContent::SpaceBetween => Self::SpaceBetween,
113-
taffy_style::JustifyContent::SpaceAround => Self::SpaceAround,
114-
taffy_style::JustifyContent::SpaceEvenly => Self::SpaceEvenly,
115-
taffy_style::JustifyContent::Stretch => Self::Start,
116-
taffy_style::JustifyContent::FlexStart => Self::Start,
117-
taffy_style::JustifyContent::FlexEnd => Self::End,
111+
// The Cortex style subset has no overflow-safety modifier.
112+
match value.keyword() {
113+
taffy_style::AlignContentKeyword::Start
114+
| taffy_style::AlignContentKeyword::FlexStart
115+
| taffy_style::AlignContentKeyword::Stretch => Self::Start,
116+
taffy_style::AlignContentKeyword::End | taffy_style::AlignContentKeyword::FlexEnd => {
117+
Self::End
118+
}
119+
taffy_style::AlignContentKeyword::Center => Self::Center,
120+
taffy_style::AlignContentKeyword::SpaceBetween => Self::SpaceBetween,
121+
taffy_style::AlignContentKeyword::SpaceAround => Self::SpaceAround,
122+
taffy_style::AlignContentKeyword::SpaceEvenly => Self::SpaceEvenly,
118123
}
119124
}
120125
}
@@ -138,25 +143,28 @@ pub enum AlignItems {
138143
impl From<AlignItems> for taffy_style::AlignItems {
139144
fn from(value: AlignItems) -> Self {
140145
match value {
141-
AlignItems::Start => Self::Start,
142-
AlignItems::End => Self::End,
143-
AlignItems::Center => Self::Center,
144-
AlignItems::Baseline => Self::Baseline,
145-
AlignItems::Stretch => Self::Stretch,
146+
AlignItems::Start => Self::START,
147+
AlignItems::End => Self::END,
148+
AlignItems::Center => Self::CENTER,
149+
AlignItems::Baseline => Self::BASELINE,
150+
AlignItems::Stretch => Self::STRETCH,
146151
}
147152
}
148153
}
149154

150155
impl From<taffy_style::AlignItems> for AlignItems {
151156
fn from(value: taffy_style::AlignItems) -> Self {
152-
match value {
153-
taffy_style::AlignItems::Start => Self::Start,
154-
taffy_style::AlignItems::End => Self::End,
155-
taffy_style::AlignItems::Center => Self::Center,
156-
taffy_style::AlignItems::Baseline => Self::Baseline,
157-
taffy_style::AlignItems::Stretch => Self::Stretch,
158-
taffy_style::AlignItems::FlexStart => Self::Start,
159-
taffy_style::AlignItems::FlexEnd => Self::End,
157+
// Normalize safety and direction-relative keywords to the Cortex subset.
158+
match value.keyword() {
159+
taffy_style::AlignItemsKeyword::Start
160+
| taffy_style::AlignItemsKeyword::FlexStart
161+
| taffy_style::AlignItemsKeyword::SelfStart => Self::Start,
162+
taffy_style::AlignItemsKeyword::End
163+
| taffy_style::AlignItemsKeyword::FlexEnd
164+
| taffy_style::AlignItemsKeyword::SelfEnd => Self::End,
165+
taffy_style::AlignItemsKeyword::Center => Self::Center,
166+
taffy_style::AlignItemsKeyword::Baseline => Self::Baseline,
167+
taffy_style::AlignItemsKeyword::Stretch => Self::Stretch,
160168
}
161169
}
162170
}
@@ -184,29 +192,30 @@ pub enum AlignContent {
184192
impl From<AlignContent> for taffy_style::AlignContent {
185193
fn from(value: AlignContent) -> Self {
186194
match value {
187-
AlignContent::Start => Self::Start,
188-
AlignContent::End => Self::End,
189-
AlignContent::Center => Self::Center,
190-
AlignContent::SpaceBetween => Self::SpaceBetween,
191-
AlignContent::SpaceAround => Self::SpaceAround,
192-
AlignContent::SpaceEvenly => Self::SpaceEvenly,
193-
AlignContent::Stretch => Self::Stretch,
195+
AlignContent::Start => Self::START,
196+
AlignContent::End => Self::END,
197+
AlignContent::Center => Self::CENTER,
198+
AlignContent::SpaceBetween => Self::SPACE_BETWEEN,
199+
AlignContent::SpaceAround => Self::SPACE_AROUND,
200+
AlignContent::SpaceEvenly => Self::SPACE_EVENLY,
201+
AlignContent::Stretch => Self::STRETCH,
194202
}
195203
}
196204
}
197205

198206
impl From<taffy_style::AlignContent> for AlignContent {
199207
fn from(value: taffy_style::AlignContent) -> Self {
200-
match value {
201-
taffy_style::AlignContent::Start => Self::Start,
202-
taffy_style::AlignContent::End => Self::End,
203-
taffy_style::AlignContent::Center => Self::Center,
204-
taffy_style::AlignContent::SpaceBetween => Self::SpaceBetween,
205-
taffy_style::AlignContent::SpaceAround => Self::SpaceAround,
206-
taffy_style::AlignContent::SpaceEvenly => Self::SpaceEvenly,
207-
taffy_style::AlignContent::Stretch => Self::Stretch,
208-
taffy_style::AlignContent::FlexStart => Self::Start,
209-
taffy_style::AlignContent::FlexEnd => Self::End,
208+
match value.keyword() {
209+
taffy_style::AlignContentKeyword::Start
210+
| taffy_style::AlignContentKeyword::FlexStart => Self::Start,
211+
taffy_style::AlignContentKeyword::End | taffy_style::AlignContentKeyword::FlexEnd => {
212+
Self::End
213+
}
214+
taffy_style::AlignContentKeyword::Center => Self::Center,
215+
taffy_style::AlignContentKeyword::SpaceBetween => Self::SpaceBetween,
216+
taffy_style::AlignContentKeyword::SpaceAround => Self::SpaceAround,
217+
taffy_style::AlignContentKeyword::SpaceEvenly => Self::SpaceEvenly,
218+
taffy_style::AlignContentKeyword::Stretch => Self::Stretch,
210219
}
211220
}
212221
}
@@ -235,11 +244,11 @@ impl AlignSelf {
235244
pub fn to_taffy_option(&self) -> Option<taffy_style::AlignItems> {
236245
match *self {
237246
AlignSelf::Auto => None,
238-
AlignSelf::Start => Some(taffy_style::AlignItems::Start),
239-
AlignSelf::End => Some(taffy_style::AlignItems::End),
240-
AlignSelf::Center => Some(taffy_style::AlignItems::Center),
241-
AlignSelf::Baseline => Some(taffy_style::AlignItems::Baseline),
242-
AlignSelf::Stretch => Some(taffy_style::AlignItems::Stretch),
247+
AlignSelf::Start => Some(taffy_style::AlignItems::START),
248+
AlignSelf::End => Some(taffy_style::AlignItems::END),
249+
AlignSelf::Center => Some(taffy_style::AlignItems::CENTER),
250+
AlignSelf::Baseline => Some(taffy_style::AlignItems::BASELINE),
251+
AlignSelf::Stretch => Some(taffy_style::AlignItems::STRETCH),
243252
}
244253
}
245254
}
@@ -306,21 +315,50 @@ impl From<i32> for Dimension {
306315
}
307316

308317
impl From<Dimension> for taffy_style::Dimension {
318+
fn from(value: Dimension) -> Self {
319+
taffy_style::LengthPercentageAuto::from(value).into()
320+
}
321+
}
322+
323+
impl From<Dimension> for taffy_style::LengthPercentageAuto {
309324
fn from(value: Dimension) -> Self {
310325
match value {
311-
Dimension::Auto => Self::Auto,
312-
Dimension::Points(p) => Self::Length(p),
313-
Dimension::Percent(pct) => Self::Percent(pct / 100.0),
326+
Dimension::Auto => Self::auto(),
327+
Dimension::Points(p) => Self::length(p),
328+
Dimension::Percent(pct) => Self::percent(pct / 100.0),
314329
}
315330
}
316331
}
317332

318-
impl From<taffy_style::Dimension> for Dimension {
319-
fn from(value: taffy_style::Dimension) -> Self {
320-
match value {
321-
taffy_style::Dimension::Auto => Self::Auto,
322-
taffy_style::Dimension::Length(l) => Self::Points(l),
323-
taffy_style::Dimension::Percent(p) => Self::Percent(p * 100.0),
333+
/// A layout value cannot be represented by the Cortex style subset.
334+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
335+
pub struct UnsupportedDimension;
336+
337+
impl std::fmt::Display for UnsupportedDimension {
338+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
339+
f.write_str("The layout dimension is not supported")
340+
}
341+
}
342+
343+
impl std::error::Error for UnsupportedDimension {}
344+
345+
impl TryFrom<taffy_style::Dimension> for Dimension {
346+
type Error = UnsupportedDimension;
347+
348+
fn try_from(value: taffy_style::Dimension) -> Result<Self, Self::Error> {
349+
use taffy_style::ExpandedDimension;
350+
match value.expand() {
351+
ExpandedDimension::Length(l) => Ok(Self::Points(l)),
352+
ExpandedDimension::Percent(p) => Ok(Self::Percent(p * 100.0)),
353+
ExpandedDimension::Auto => Ok(Self::Auto),
354+
ExpandedDimension::MinContent
355+
| ExpandedDimension::MaxContent
356+
| ExpandedDimension::FitContent
357+
| ExpandedDimension::FitContentPx(_)
358+
| ExpandedDimension::FitContentPercent(_)
359+
| ExpandedDimension::Stretch
360+
| ExpandedDimension::Content
361+
| ExpandedDimension::Calc(_) => Err(UnsupportedDimension),
324362
}
325363
}
326364
}
@@ -378,17 +416,20 @@ impl From<f32> for LengthPercentage {
378416
impl From<LengthPercentage> for taffy_style::LengthPercentage {
379417
fn from(value: LengthPercentage) -> Self {
380418
match value {
381-
LengthPercentage::Points(p) => Self::Length(p),
382-
LengthPercentage::Percent(pct) => Self::Percent(pct / 100.0),
419+
LengthPercentage::Points(p) => Self::length(p),
420+
LengthPercentage::Percent(pct) => Self::percent(pct / 100.0),
383421
}
384422
}
385423
}
386424

387-
impl From<taffy_style::LengthPercentage> for LengthPercentage {
388-
fn from(value: taffy_style::LengthPercentage) -> Self {
389-
match value {
390-
taffy_style::LengthPercentage::Length(l) => Self::Points(l),
391-
taffy_style::LengthPercentage::Percent(p) => Self::Percent(p * 100.0),
425+
impl TryFrom<taffy_style::LengthPercentage> for LengthPercentage {
426+
type Error = UnsupportedDimension;
427+
428+
fn try_from(value: taffy_style::LengthPercentage) -> Result<Self, Self::Error> {
429+
match value.expand() {
430+
taffy_style::ExpandedLengthPercentage::Length(l) => Ok(Self::Points(l)),
431+
taffy_style::ExpandedLengthPercentage::Percent(p) => Ok(Self::Percent(p * 100.0)),
432+
taffy_style::ExpandedLengthPercentage::Calc(_) => Err(UnsupportedDimension),
392433
}
393434
}
394435
}
@@ -450,19 +491,22 @@ impl From<f32> for LengthPercentageAuto {
450491
impl From<LengthPercentageAuto> for taffy_style::LengthPercentageAuto {
451492
fn from(value: LengthPercentageAuto) -> Self {
452493
match value {
453-
LengthPercentageAuto::Auto => Self::Auto,
454-
LengthPercentageAuto::Points(p) => Self::Length(p),
455-
LengthPercentageAuto::Percent(pct) => Self::Percent(pct / 100.0),
494+
LengthPercentageAuto::Auto => Self::auto(),
495+
LengthPercentageAuto::Points(p) => Self::length(p),
496+
LengthPercentageAuto::Percent(pct) => Self::percent(pct / 100.0),
456497
}
457498
}
458499
}
459500

460-
impl From<taffy_style::LengthPercentageAuto> for LengthPercentageAuto {
461-
fn from(value: taffy_style::LengthPercentageAuto) -> Self {
462-
match value {
463-
taffy_style::LengthPercentageAuto::Auto => Self::Auto,
464-
taffy_style::LengthPercentageAuto::Length(l) => Self::Points(l),
465-
taffy_style::LengthPercentageAuto::Percent(p) => Self::Percent(p * 100.0),
501+
impl TryFrom<taffy_style::LengthPercentageAuto> for LengthPercentageAuto {
502+
type Error = UnsupportedDimension;
503+
504+
fn try_from(value: taffy_style::LengthPercentageAuto) -> Result<Self, Self::Error> {
505+
match value.expand() {
506+
taffy_style::ExpandedLengthPercentageAuto::Auto => Ok(Self::Auto),
507+
taffy_style::ExpandedLengthPercentageAuto::Length(l) => Ok(Self::Points(l)),
508+
taffy_style::ExpandedLengthPercentageAuto::Percent(p) => Ok(Self::Percent(p * 100.0)),
509+
taffy_style::ExpandedLengthPercentageAuto::Calc(_) => Err(UnsupportedDimension),
466510
}
467511
}
468512
}
@@ -721,6 +765,15 @@ impl From<Size<Dimension>> for taffy::Size<taffy_style::Dimension> {
721765
}
722766
}
723767

768+
impl From<Size<Dimension>> for taffy::Size<taffy_style::LengthPercentageAuto> {
769+
fn from(value: Size<Dimension>) -> Self {
770+
Self {
771+
width: value.width.into(),
772+
height: value.height.into(),
773+
}
774+
}
775+
}
776+
724777
impl From<Size<LengthPercentage>> for taffy::Size<taffy_style::LengthPercentage> {
725778
fn from(value: Size<LengthPercentage>) -> Self {
726779
Self {

0 commit comments

Comments
 (0)