Skip to content

Add derive macro to faciliate elements creation#13

Merged
nixonyh merged 14 commits intomainfrom
nixon/derive-elements
Apr 21, 2026
Merged

Add derive macro to faciliate elements creation#13
nixonyh merged 14 commits intomainfrom
nixon/derive-elements

Conversation

@nixonyh
Copy link
Copy Markdown
Member

@nixonyh nixonyh commented Apr 18, 2026

  • Splits the Element trait into ElementNew (construction), ElementChildren (child iteration), and ElementBuild (layout/render)
  • Adds #[derive(Element)] which generates the boilerplate for ElementSlot, ElementNew, and ElementChildren.
  • Adds #[derive(ElementSlot)] for type registration only

Example

#[derive(Element, Default, Clone)]
struct Vertical {
    #[children]
    children: Vec<ElementId>,
}

impl ElementBuild for Vertical {
    fn build(&self, ..) -> Size { .. }
}
  • #[children] works on anything that implements IntoIterator<&ElementId>
  • Struct-level overrides via #[element(new = fn, children = fn)] for custom construction or child iteration.

nixonyh added 6 commits April 18, 2026 16:36
Introduce ElementNew and ElementChildren as supertraits of Element.
#[derive(Element)] now generates both, along with ElementSlot.
build() remains a manual impl. Supports #[children] field attribute
and #[element(new = fn, children = fn)] overrides.
@nixonyh nixonyh marked this pull request as ready for review April 18, 2026 17:41
@nixonyh nixonyh requested a review from ian-hon April 18, 2026 17:42
Comment thread crates/fynix/src/lib.rs
/// instance. Safe to call more than once subsequent calls
/// instance. Safe to call more than once - subsequent calls
/// are no-ops.
pub fn init() {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Probs want to call this in Fynix::new() instead so users don't need to be concerned with this thing.

@nixonyh nixonyh merged commit 81fb017 into main Apr 21, 2026
7 checks passed
@nixonyh nixonyh deleted the nixon/derive-elements branch April 21, 2026 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants