A high performance rust-powered UI layout library
OTHER License
Bot releases are visible (Hide)
Published by nicoburns 5 months ago
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.
style: &Style
parameter has been added to measure functions.MaybeMath
, MaybeResolve
, and ResolveOrZero
traits have been made public.Published by nicoburns 5 months ago
align-content
/justify-content
) behaviour was updated to match the latest spec (and Chrome 123+) (#635)Published by nicoburns 6 months ago
evenly_sized_tracks
style 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 an Into<f32>
parameter may still be affected by this issue, but they should be able to fix on their side by clarifying the type passed inPublished by nicoburns 6 months ago
evenly_sized_tracks
style 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 an Into<f32>
parameter may still be affected by this issue, but they should be able to fix on their side by clarifying the type passed inPublished by nicoburns 6 months ago
Published by nicoburns 7 months ago
Published by nicoburns 8 months ago
display: block
)overflow
property (+ scrollbar_width
for overflow: scroll
)padding
and border
are now output into the Layout
structSupport 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.
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.
Visible
and Clip
will produce layouts equivalent to the Taffy 0.3. Clip
will affect the new content_size
output by restricting it to the available space.Hidden
and Scroll
affect layout by changing the automatic minimum size of Flexbox and Grid childrenScroll
additionally reserves scrollbar_width
pixels for a scrollbar in the opposite axis to which scrolling is enabled. Scroll
with scrollbar_width
set to zero is equivalent to Hidden
.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!).
Taffy
tree is now a generic TaffyTree<T>
where T
is the "context" type.Size::ZERO
for leaf nodes whose context is None
.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:
Size
in the above example. This includes your own custom type (which can be an enum or a trait object).()
for the context typecompute_layout_with_measure
only needs to exist for the duration of a single layout run,LayoutTree
trait) refactorThe low-level API has been completely reworked:
LayoutTree
trait has been split into 5 smaller traits which live in the taffy::tree:traits
module (along with their associated documentation)LayoutTree
traits entirely: parent
, is_childless
, measure_node
, needs_measure
, and mark_dirty
.taffy::node::Node
has been replaced with taffy::NodeId
. This should make it much easier to implement the low-level traits as the underlying type backing the node id now a u64
rather than a slotmap::DefaultKey
.compute_flexbox_layout
compute_grid_layout
compute_block_layout
compute_leaf_layout
compute_root_layout
compute_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.
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:
math
module has been made privateaxis
module has been merged into the geometry
moduleprint_tree
function is now accessible under util
.node
, data
, layout
, error
and cache
modules have been moved to the the tree
module.layout_flexbox()
function has been removed from the prelude. Use taffy::compute_flexbox_layout
instead.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();
Taffy
type was renamed to TaffyTree
and made generic of a context parameterflexbox
feature. The flexbox
feature is enabled by default.justify_self
property has been moved behind the grid
feature.RunMode::PeformLayout
renamed into RunMode::PerformLayout
(added missing r
).serde
dependency has been made compatible with no_std
environmentsslotmap
dependency has been made compatible with no_std
environmentsinsert_child_at_index()
method to the TaffyTree
. This can be used to insert a child node at any position instead of just the end.total_node_count()
method to the TaffyTree
which returns the total number of nodes in the tree.get_disjoint_node_context_mut()
method to the TaffyTree
. This can be used to safely get multiple mutable borrows at the same time.Published by nicoburns 12 months ago
Published by nicoburns 12 months ago
total_node_count
method to the Taffy
struct. Returns the total number of nodes in the tree.Published by nicoburns about 1 year ago
Published by nicoburns about 1 year ago
Published by nicoburns about 1 year ago
Published by nicoburns about 1 year ago
Fix rounding accumulation bug (#521) (Fixes #501 and bevyengine/bevy#8911)
Flexbox: pass correct cross-axis available space when computing an item's intrinsic main size (#522)(Fixes bevyengine/bevy#9350)
Flexbox: Subtract child margin not parent margin when computing stretch-alignment known size
Grid: Make CSS Grid algorithm correctly apply max width/height and available space when it is the root node (#491)
Grid: Fix CSS Grid "auto track" / placement bugs #481
Leaf: Apply margins to leaf nodes when computing available space for measure functions
Leaf: Reserve space for padding/borders in nodes with measure functions (#497)
NOTE: This has the potential to break layouts relying on the old behaviour. However, such layouts would be relying on a style having no effect, so it is judged that such layouts are unlikely to exist in the wild. If this turns out not to be true then this fix will be reverted on the 0.3.x branch.
grid
to 0.10
. This eliminates the transitive dependency on no-std-compat
.Published by nicoburns over 1 year ago
display:none
on and offPublished by nicoburns over 1 year ago
Published by nicoburns over 1 year ago
Published by nicoburns over 1 year ago
Published by nicoburns over 1 year ago
flex-wrap: wrap
nodes in certain cases (bevyengine/bevy#8082)Published by nicoburns over 1 year ago
padding
and border
floor node sizes (#372)