Releases: DioxusLabs/taffy
v0.5.0
The changes in 0.5 are relatively small but the new measure function parameter is a breaking change so it requires a minor version bump.
- Added: A
style: &Styleparameter has been added to measure functions. - Added: The
MaybeMath,MaybeResolve, andResolveOrZerotraits have been made public. - Fix: use SizingMode::Inherent when sizing absolute children of flexbox nodes.
- Deps: Update grid requirement from 0.13.0 to 0.14.0
v0.4.4
v0.4.3
Fixes
- Fix compilation error in
evenly_sized_tracksstyle helper in recent versions of rustc caused by a change/regression in type inference (#643). Note that 3rd-party code that call style helpers that take anInto<f32>parameter may still be affected by this issue, but they should be able to fix on their side by clarifying the type passed in
v0.3.19
Fixes
- Fix compilation error in
evenly_sized_tracksstyle helper in recent versions of rustc caused by a change/regression in type inference (#643). Note that 3rd-party code that call style helpers that take anInto<f32>parameter may still be affected by this issue, but they should be able to fix on their side by clarifying the type passed in
v0.4.2
v0.4.1
v0.4.0
Highlights
- Support for CSS Block layout (
display: block) - Support for the
overflowproperty (+scrollbar_widthforoverflow: scroll) - Improved measure function API
- Completely refactored low-level API
- Simplified module hierarchy (+ most types/functions are now exported from the crate root)
- Expanded set of examples which better document integration with other layout systems (e.g. text layout)
- Computed values for
paddingandborderare now output into theLayoutstruct
Block layout
Support for CSS Block layout has been added. This can be used via the new Display::Block variant of the Display enum. Note that full flow layout: inline, inline-block and float layout have not been implemented. The use case supported is block container nodes which contain block-level children.
Overflow property
Support has been added for a new overflow style property with Visible, Clip, Hidden, and Scroll values (Auto is not currently implemented). Additionally a scrollbar_width property has been added to control the size of scrollbars for nodes with Overflow::Scroll set.
- Overflow is settable indpendently in each axis.
VisibleandClipwill produce layouts equivalent to the Taffy 0.3.Clipwill affect the newcontent_sizeoutput by restricting it to the available space.HiddenandScrollaffect layout by changing the automatic minimum size of Flexbox and Grid childrenScrolladditionally reservesscrollbar_widthpixels for a scrollbar in the opposite axis to which scrolling is enabled.Scrollwithscrollbar_widthset to zero is equivalent toHidden.
Measure function changes
The "measure function" API for integrating Taffy with other measurement systems (such as text layout) has been changed to be more flexible
and to interact better with borrow checking (you can now borrow external data in your measure function!).
- There are no longer per-node measure functions.
- There is now a single "global" measure function, and a per-node "context" of a user-defined type
- The
Taffytree is now a genericTaffyTree<T>whereTis the "context" type. - The measure function is now called for all leaf nodes (nodes without children). If you wish to maintain compatibility with the previous
behaviour then your measure function should returnSize::ZEROfor leaf nodes whose context isNone.
If you are not using measure functions, then the only change you will need to make is from:
let mut tree = Taffy::new();to
let mut tree : TaffyTree<()> = TaffyTree::new();And generally update any uses of Taffy in your codebase to TaffyTree<()>.
If you are using measure functions then you will need to make some bigger (but straightforward) changes. The following Taffy 0.3 code:
let mut tree = Taffy::new();
let leaf = tree.new_leaf_with_measure(
Style::DEFAULT,
|known_dimensions: Size<Option<f32>>, available_space: Size<AvailableSpace>| Size { width: 100.0, height: 200.0 }
);
tree.compute_layout(leaf, Size::MAX_CONTENT);Should become something like the following with Taffy 0.4:
let mut tree : TaffyTree<Size> = TaffyTree::new();
let leaf = tree.new_leaf_with_context(Style::DEFAULT, Size { width: 100.0, height: 200.0 });
tree.compute_layout_with_measure(
leaf,
Size::MAX_CONTENT,
|known_dimensions: Size<Option<f32>>, available_space: Size<AvailableSpace>, node_id: NodeId, node_context: Option<Size>| {
node_context.unwrap_or(Size::ZERO)
}
);Note that:
- You can choose any type instead of
Sizein the above example. This includes your own custom type (which can be an enum or a trait object). - If you don't need a context then you can use
()for the context type - As the single "global" measure function passed to
compute_layout_with_measureonly needs to exist for the duration of a single layout run,
it can (mutably) borrow data from it's environment
Low-level API (LayoutTree trait) refactor
The low-level API has been completely reworked:
- The
LayoutTreetrait has been split into 5 smaller traits which live in thetaffy::tree:traitsmodule (along with their associated documentation) - The following methods have been removed from split
LayoutTreetraits entirely:parent,is_childless,measure_node,needs_measure, andmark_dirty. taffy::node::Nodehas been replaced withtaffy::NodeId. This should make it much easier to implement the low-level traits as the underlying type backing the node id now au64rather than aslotmap::DefaultKey.- Support for running each layout algorithm individually on a single node via the following top-level functions:
compute_flexbox_layoutcompute_grid_layoutcompute_block_layoutcompute_leaf_layoutcompute_root_layoutcompute_hidden_layout
It is believed that nobody was previously using the low-level API so we are not providing a migration guide. However, along with the refactor we have greatly
improved both the documentation and have added examples using the new API, both of which are linked to from the main documentation page.
Module hierarchy changes
The specific changes are detailed below. However for most users the most significant change will be that almost all types are now re-exported from the root module. This means that module specific imports like use taffy::layout::Layout can now in almost all cases be replaced with the simpler use taffy::Layout.
Specific changes:
- The
mathmodule has been made private - The
axismodule has been merged into thegeometrymodule - The debug module is no longer public. The
print_treefunction is now accessible underutil. - All types from the
node,data,layout,errorandcachemodules have been moved to the thetreemodule. - The
layout_flexbox()function has been removed from the prelude. Usetaffy::compute_flexbox_layoutinstead.
Many APIs have been renamed to replace points or Points with length or Length
This new name better describes one-dimensional measure of space in some unspecified unit
which is often unrelated to the PostScript point or the CSS pt unit.
This also removes a misleading similarity with the 2D Point,
whose components can have any unit and are not even necessarily absolute lengths.
Example usage change:
use taffy::prelude::*;
// …
let header_node = taffy
.new_leaf(
Style {
- size: Size { width: points(800.0), height: points(100.0) },
+ size: Size { width: length(800.0), height: length(100.0) },
..Default::default()
},
).unwrap();Other Changes
- The
Taffytype was renamed toTaffyTreeand made generic of a context parameter - The Flexbox algorithm has now been moved behind the
flexboxfeature. Theflexboxfeature is enabled by default. - The
justify_selfproperty has been moved behind thegridfeature. - Fixed misspelling:
RunMode::PeformLayoutrenamed intoRunMode::PerformLayout(added missingr). serdedependency has been made compatible withno_stdenvironmentsslotmapdependency has been made compatible withno_stdenvironments- Added
insert_child_at_index()method to theTaffyTree. This can be used to insert a child node at any position instead of just the end. - Added
total_node_count()method to theTaffyTreewhich returns the total number of nodes in the tree. - Added
get_disjoint_node_context_mut()method to theTaffyTree. This can be used to safely get multiple mutable borrows at the same time.