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

Refactor modals #42

Merged
merged 3 commits into from
Feb 10, 2024
Merged

Refactor modals #42

merged 3 commits into from
Feb 10, 2024

Conversation

LeoRiether
Copy link
Owner

@LeoRiether LeoRiether commented Feb 10, 2024

Now modals receive a lambda that returns an Action. This makes modals infinitely more reusable than the previous ones. To illustrate, this is now possible:

let add_modal = Box::new(
    InputModal::new()
        .style(Style::default().fg(Color::BrightRed))
        .on_commit(|input| Action::AddSong(input))
);

let rename_modal = Box::new(
    InputModal::new()
        .style(Style::default().fg(Color::Blue))
        .on_commit(|input| Action::RenameSongTo(input))
);

No special case handling for each type of modal!

Also, modals now send Action::CloseModal when appropriate, which closes any open modal. Previously each modal had its own match case to close itself...

Now modals receive a lambda that returns an Action. This makes modals
infinitely more reusable than the previous ones. To illustrate, this is
now possible:

```rust
let add_modal = Box::new(
    InputModal::new()
        .style(Style::default().fg(Color::BrightRed))
        .on_commit(|input| Action::AddSong(input))
);

let rename_modal = Box::new(
    InputModal::new()
        .style(Style::default().fg(Color::Blue))
        .on_commit(|input| Action::RenameSongTo(input))
);
```

No special case handling for each type of modal!

Also, modals now send Action::CloseModal when appropriate, which closes
any open modal. Previously each modal had its own match case to close
itself...
@LeoRiether LeoRiether self-assigned this Feb 10, 2024
@LeoRiether LeoRiether merged commit a6b71f0 into feat/v1 Feb 10, 2024
5 checks passed
@LeoRiether LeoRiether deleted the modals branch February 10, 2024 18:54
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.

1 participant