Skip to content

Wrapping views in tuple structs #866

@HarrisonMc555

Description

@HarrisonMc555

Is your feature request related to a problem? Please describe.
I would like to use the wrap_impl! macro with a tuple struct.

Describe the solution you'd like
The wrap_impl! macro currently only has a single branch that matches on (self.$v:ident: $t:ty). If we added another branch that matches on (self.$v:literal: $t:ty) (possibly with some post-processing to ensure it is a non-negative integer literal).

Describe alternatives you've considered
I can use a standard struct with named fields.

Additional context
If you want to alter a small amount of behavior and don't require any additional data/configuration/etc. to do so, then you really only need to store the View that is being "wrapped".

For example, I wanted to make an Unfocusable wrapper that prevented the wrapped view from receiving focus. I was hoping to do something like this:

struct Unfocusable<V: View>(V);

impl<V: View> ViewWrapper for Unfocusable<V> {
    wrap_impl!(self.0: V);

    fn wrap_take_focus(&mut self, source: Direction) -> Result<EventResult, CannotFocus> {
        Err(CannotFocus)
    }
}

I'm willing to create a PR for this. Before I start working on it, though, I wanted to see if this is something you would be interested in. Maybe there's a reason to avoid this pattern that I'm missing.


P.S. I am open to any suggestions on my concrete idea of an Unfocusable wrapper, although this issue is specifically for wrapping tuple-style structs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions