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

passing a view into a state closure #44

Closed
wtholliday opened this issue Feb 11, 2023 · 0 comments
Closed

passing a view into a state closure #44

wtholliday opened this issue Feb 11, 2023 · 0 comments

Comments

@wtholliday
Copy link
Contributor

I'm trying to add state to button for hovering:

/// Calls a function when the button is tapped.
pub fn button<A: 'static, F: Fn(&mut Context) -> A + 'static>(view: impl View, f: F) -> impl View {
    state(
        || false,
        move |hover, _| {
            view.padding(Auto)
                .background(
                    rectangle()
                        .corner_radius(BUTTON_CORNER_RADIUS)
                        .color(BUTTON_BACKGROUND_COLOR),
                )
                .tap(move |cx| f(cx))
                .hover(|_, inside| {
                    println!("inside button: {}", inside);
                })
                .role(Role::Button)
        },
    )
}

The error here is that padding (or any other modifier) wants to move out of view, which is captured by the closure passed to state.

I'm not quite sure how to deal with this. I've tried making Views Clone, but it seems to cause a big ripple.

ruza-net pushed a commit to ruza-net/rui that referenced this issue Feb 12, 2023
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

No branches or pull requests

1 participant