match_focus

Macro match_focus 

Source
macro_rules! match_focus {
    ($($field:expr => $block:expr),* $(, else => $final:expr)?) => { ... };
}
Expand description

Does a match on several fields and can return a result. Does a widget_state.is_focused() for each field and returns the first that is true. There is an else branch too.

This requires that widget_state implements HasFocus, but that’s the basic requirement for this whole crate.

use rat_focus::match_focus;

let res = match_focus!(
    state.field1 => {
        // do this
        true
    },
    state.field2 => {
        // do that
        true
    },
    else => {
        false
    }
);

if res {
    // react
}