Skip to content
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

"Traitify" the Style struct #568

Merged
merged 13 commits into from
Jul 16, 2024
Merged

Conversation

nicoburns
Copy link
Collaborator

@nicoburns nicoburns commented Oct 22, 2023

Objective

Allow users of Taffy to bring their own style representation(s).

Context

While we have support for custom node tree representations, we currently enforce usage of a concrete style representation. Additionally, that style representation is shared across all algorithms and thus must include the styles for Flexbox, CSS Grid and Block layout, making it quite large. A problem which will only get worse if non-css algorithms are supported in future.

Feedback wanted

  • Feedback on the trait hierarchy design

Todo

  • Figure out how to handle the Display style. Algorithms typically only need to know whether the Display is None or not. I am considering creating a new enum with just None and Normal (name tbd) variants for this purpose. This would need to be extended with Contents if we implement that, but would never need to know about individual algorithms. See also: style::Display is not according to specifications #115
  • Maybe: Blanket impl of the style traits for &T if they are implemented for T
  • Update the Flexbox algorithm to use the new traits
  • Update the CSS Grid algorithm to use the new traits
  • Update the Block algorithm to use the new traits
  • Update the Leaf algorithm to use the new traits
  • Remove the get_style method from the base PartialLayoutTree trait Turns out this is still required for root layout
  • Test implementing new traits for stylo types
  • Fix examples

@nicoburns nicoburns added enhancement New feature or request usability Make the library more comfortable to use code quality Make the code cleaner or prettier. labels Oct 22, 2023
@nicoburns
Copy link
Collaborator Author

@vkurchatkin-miro How does this design for traitifying Style look to you?

@nicoburns nicoburns marked this pull request as draft October 22, 2023 20:06
@nicoburns nicoburns force-pushed the traitify-style branch 4 times, most recently from 974929a to dd0c5dd Compare October 22, 2023 21:06
@nicoburns nicoburns added this to the 0.4 milestone Oct 22, 2023
@vkurchatkin-miro
Copy link

@nicoburns great stuff, even more flexible than what I thought of

/// The set of styles required for a Flexbox container
pub trait FlexboxContainerStyle: CoreStyle {
/// Which direction does the main axis flow in?
#[inline(always)]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, is it still worth doing considering rust-lang/rust#116505 exists? 👀

@nicoburns nicoburns changed the title WIP: "Traitify" the Style struct "Traitify" the Style struct Apr 21, 2024
@nicoburns nicoburns force-pushed the traitify-style branch 4 times, most recently from 21e44f2 to d486843 Compare July 3, 2024 05:22
@nicoburns nicoburns force-pushed the traitify-style branch 4 times, most recently from 514bbd4 to 6441efc Compare July 7, 2024 21:37
@nicoburns nicoburns marked this pull request as ready for review July 16, 2024 03:06
@nicoburns nicoburns merged commit f953fcb into DioxusLabs:main Jul 16, 2024
19 checks passed
@nicoburns nicoburns deleted the traitify-style branch July 16, 2024 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality Make the code cleaner or prettier. enhancement New feature or request usability Make the library more comfortable to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants