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

Added none flag to modifiers.rs #2028

Closed
wants to merge 1 commit into from

Conversation

ua-kxie
Copy link
Contributor

@ua-kxie ua-kxie commented Aug 15, 2023

allows pattern matching against no modifiers

match event {
    Event::Keyboard(iced::keyboard::Event::KeyPressed {
        key_code: iced::keyboard::KeyCode::C,
        modifiers: Modifiers::NONE,
    }) => {
        ...
    }
    Event::Keyboard(iced::keyboard::Event::KeyPressed {
        key_code: iced::keyboard::KeyCode::C,
        modifiers: Modifiers::CTRL,
    }) => {
        ...
    }
    ...
}

I haven't read into it much but it seems to me that the bitflags lib has some acknowledged shortcomings, which are addressed in some newer crates, e.g. flagset

#1868 may also be convenient to address in a modifiers rework

added NONE flag to help with pattern matching
@ua-kxie
Copy link
Contributor Author

ua-kxie commented Aug 16, 2023

so I was shown a way to match against no modifiers:

const NO_MODIFIER: Modifiers = Modifiers::empty();
match event {
    Event::Keyboard(iced::keyboard::Event::KeyPressed {
        key_code: iced::keyboard::KeyCode::C,
        modifiers: NO_MODIFIER,
    }) => {
        ...
    }
    Event::Keyboard(iced::keyboard::Event::KeyPressed {
        key_code: iced::keyboard::KeyCode::C,
        modifiers: Modifiers::CTRL,
    }) => {
        ...
    }
    ...
}

I will open a topic under discussions

@ua-kxie ua-kxie closed this Aug 16, 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

Successfully merging this pull request may close these issues.

1 participant