-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor LayoutTree
, create PartialLayoutTree
, and add examples of custom trees
#564
Merged
nicoburns
merged 31 commits into
DioxusLabs:main
from
nicoburns:reinstate-layoutree-cache-mut
Oct 22, 2023
Merged
Refactor LayoutTree
, create PartialLayoutTree
, and add examples of custom trees
#564
nicoburns
merged 31 commits into
DioxusLabs:main
from
nicoburns:reinstate-layoutree-cache-mut
Oct 22, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nicoburns
added
documentation
Improvements or additions to documentation
usability
Make the library more comfortable to use
breaking-change
A change that breaks our public interface
controversial
This work requires a heightened standard of review due to implementation or design complexity
labels
Oct 15, 2023
nicoburns
force-pushed
the
reinstate-layoutree-cache-mut
branch
2 times, most recently
from
October 18, 2023 23:07
66aff50
to
fd61962
Compare
nicoburns
force-pushed
the
reinstate-layoutree-cache-mut
branch
from
October 18, 2023 23:17
fd61962
to
7fc640d
Compare
nicoburns
force-pushed
the
reinstate-layoutree-cache-mut
branch
from
October 19, 2023 00:47
dbb73f3
to
a0034cb
Compare
nicoburns
changed the title
WIP: Further LayoutTree tweaks + examples of custom trees
Refactor Oct 21, 2023
LayoutTree
+ add examples of custom trees
nicoburns
changed the title
Refactor
Refactor Oct 22, 2023
LayoutTree
+ add examples of custom treesLayoutTree
, create PartialLayoutTree
, and add examples of custom trees
Release notes to follow once an API design for Taffy 0.4 has been settled on. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
breaking-change
A change that breaks our public interface
controversial
This work requires a heightened standard of review due to implementation or design complexity
documentation
Improvements or additions to documentation
usability
Make the library more comfortable to use
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Enable algorithm-agnostic code such as caching and rounding logic to work with custom trees. And make such trees easier to implement.
Context
taffy::leaf::compute
is exported astaffy::compute::compute
#559Changes made:
compute_leaf_layout
function: instead of taking a context and a closure that accepts the context as a parameter, it now just takes a closure and expects the context to have already been closed over. This doesn't affect the high level API.LayoutTree
intoPartialLayoutTree
andLayoutTree: PartialLayoutTree
traits. The idea here is thatPartialLayoutTree
can be implemented by consumers of Taffy that only have access to one node and it's direct children at once. This gives access to Taffy's layout algorithms.LayoutTree
can be implemented in addition toPartialLayoutTree
if you have access to the full tree. This gives access to rounding and theprint_tree
function.cache_mut
method toPartialLayoutTree
, and create new publiccompute_cached_layout
function that handles caching logic.measure_child_size
andperform_child_layout
methods back into a singlecompute_child_layout
with aSizingMode
parameter (not entirely sure about this, but it means users of Taffy only have to implement one method).display
style and call appropriate algorithm) into the implementation ofPartialLayoutTree.compute_child_layout
for theTaffy
struct). This now uses the abovecompute_cached_layout
function.(Partial)LayoutTree
methods and parameters.round_layout
andcompute_layout
functions publicTaffyView
private (this is an implementation detail ofTaffy
)CacheEntry
private (the public API is nowCache
)Vec
, one where each node directly owns it's children.Feedback wanted
display: none
) both do.Hidden layout could be fixed by adding a new method to the trait. Or perhaps a new variant to theThis has now been implementedRunMode
enum.Old notes
I'm wondering if perhaps we ought to split theThis has also been implementedLayoutTree
into two traits (perhapsPartialLayoutTree
andLayoutTree
? WhereLayoutTree: PartialLayoutTree
, andLayoutTree
comes with an additional requirement that you can recurse down the tree just using IDs.LayoutTree
for "each node directly owns a Vec of children" trees as demonstrated in the example, but it's not very nice: it involves usingunsafe
to stuff a pointer into theNodeId
. I think this could be fixed by making theNodeId
type generic and adding a lifetime to it, but it still won't always be possible if for example the children are trait objects of a trait that doesn't have methods to access the relevant properties or it's own children (which aWidget
trait for a not-all-in-on-Taffy UI system likely wouldn't).This hasn't ended up as neat as I had hoped. I might split out some of the less controversial changes from this PR into separate PRs.I'm much happier with this after splitting out theLayoutTree
intoPartialLayoutTree
and (Full)LayoutTree
. This split gives us some type safety around which Taffy methods require infinite tree traversal and which ones only need to access direct children. So while users of Taffy will still need to read the docs carefully when implementingPartialLayoutTree
/LayoutTree
, which methods they can use will be enforced by the type system assuming that implementation is done correctly.Removing the (Full)
LayoutTree
requirement fromperform_hidden_layout
, along with splitting rounding into a separatecompute_layout_with_rounding
method, also allows it to be removed from the top-levelcompute_layout
method). So it's now only rounding and debug printing that requireFullLayoutTree
.