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

Hide/Disable widgets or buttons from state #1694

Closed
chrisheib opened this issue Apr 3, 2021 · 4 comments
Closed

Hide/Disable widgets or buttons from state #1694

chrisheib opened this issue Apr 3, 2021 · 4 comments
Labels
duplicate already exists

Comments

@chrisheib
Copy link

Hey, I have a widget for a song, which is:

grafik

On clicking on the 'x' I want some stuff to happen, and a function to set a field of the song 'x_pressed' to be set to true, and the x-button to disappear or get deactivated. Is there a widget with this functionality available? It would surprise me if I was the first one wanting to use this.

Code now:

    let skip = Button::new("✘")
        .on_click(|_: &mut EventCtx, song: &mut SongData, _: &Env| song.skip = true);

I want:

    let skip = Button::new("✘")
        .on_click(|_: &mut EventCtx, song: &mut SongData, _: &Env| {song.skip = true; song.x_pressed = true;})
        .enabled(|_: &mut EventCtx, song: &mut SongData, _: &Env| !song.x_pressed);
@HoNile
Copy link
Contributor

HoNile commented Apr 4, 2021

Hello, disable widgets are in progress see #1632, if you want to hide a button it should be possible with a ViewSwitcher on the Button and an SizedBox (cf. example view_switcher).

@chrisheib
Copy link
Author

@HoNile thanks alot, using the viewswitcher works nicely for the time being!

    let skip_panel = ViewSwitcher::new(
        |data: &SongData, _env| data.is_last,
        |selector, _data, _env| match selector {
            false => Box::new(
                Button::new("✘")
                    .on_click(|_: &mut EventCtx, song: &mut SongData, _: &Env| song.skip = true),
            ),
            true => Box::new(Flex::column()),
        },
    );

@SecondFlight
Copy link
Collaborator

Closing as a duplicate of #746.

@SecondFlight SecondFlight added the duplicate already exists label Apr 5, 2021
@xarvic
Copy link
Collaborator

xarvic commented Apr 11, 2021

@chrisheib the disabled state is merged, a disabled_if WidgetExt method is on the way (#1702).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate already exists
Projects
None yet
Development

No branches or pull requests

4 participants