Improve responsive layout and retained rendering

This commit is contained in:
SGavrl committed 2026-08-03 22:59:18 +00:00
1 parent ede14b7740
commit 50b2ea14ff
6 files changed
+1554 -103

No files matched your search

+25 -3
View File
@@ -80,11 +80,23 @@ impl std::error::Error for TaffyError {}
pub(crate) struct TaffyConfig {
/// Whether to round layout values
pub(crate) use_rounding: bool,
/// Resolves an opaque `calc()` handle against its percentage basis.
#[cfg(feature = "calc")]
pub(crate) calc_resolver: fn(*const (), f32) -> f32,
}
#[cfg(feature = "calc")]
fn default_calc_resolver(_value: *const (), _basis: f32) -> f32 {
0.0
}
impl Default for TaffyConfig {
fn default() -> Self {
Self { use_rounding: true }
Self {
use_rounding: true,
#[cfg(feature = "calc")]
calc_resolver: default_calc_resolver,
}
}
}
@@ -388,8 +400,8 @@ where
}
#[inline(always)]
fn resolve_calc_value(&self, _val: *const (), _basis: f32) -> f32 {
0.0
fn resolve_calc_value(&self, val: *const (), basis: f32) -> f32 {
(self.taffy.config.calc_resolver)(val, basis)
}
#[inline(always)]
@@ -566,6 +578,16 @@ impl<NodeContext> TaffyTree<NodeContext> {
self.config.use_rounding = false;
}
/// Installs the resolver used for opaque `calc()` handles.
///
/// Every calc handle stored in a node style must be understood by
/// `resolver` and remain alive for every layout computation performed by
/// this tree. Taffy treats handles as opaque and never dereferences them.
#[cfg(feature = "calc")]
pub fn set_calc_resolver(&mut self, resolver: fn(*const (), f32) -> f32) {
self.config.calc_resolver = resolver;
}
/// Creates and adds a new unattached leaf node to the tree, and returns the node of the new node
pub fn new_leaf(&mut self, layout: Style) -> TaffyResult<NodeId> {
let id = self.nodes.insert(NodeData::new(layout));