orbclient_window_shortcuts 0.1.5

Shortcut support for orbclient::Window
extern crate orbclient;
extern crate orbclient_window_shortcuts;

use orbclient::{Window, Renderer, EventOption, Color};
use orbclient_window_shortcuts::shortcut::{Shortcut, CommonId, ShortcutComparator};

fn window() -> orbclient::Window {
    let (width, height) = orbclient::get_display_size().unwrap();
    let mut window = Window::new_flags(0, 0, width / 2, height / 2, "Launcher",&[orbclient::WindowFlag::Resizable]).unwrap();
    window.sync();
    window
}

enum MyId {
    Increase, Decrease
}

fn main() {
    let mut window = window();
    //initial supported shortucut
    let mut keys: Vec<u8> = Vec::new();
    keys.push(orbclient::event::K_CTRL);
    keys.push(orbclient::event::K_Q);
    // make sure that you sort your vec if you do not use one of the provided new or with_custom fn
    keys.sort();

    let quit: Shortcut = Shortcut{id: CommonId::Quit, keys: keys};
    let mut supported: Vec<Shortcut> = Vec::new();
    supported.push(quit);

    let mut sceq: ShortcutComparator = ShortcutComparator{pressed: Vec::new(), supported: Some(supported), min_shortcut_len: 1};

    //Not implemented
    //let mut sceq: ShortcutComparator = ShortcutComparator::from_file("common.json");

/* TODO: Missing Generalization for the field id
    let mut decrease_k = Vec::new();
    decrease_k.push(orbclient::event::K_CTRL);
    decrease_k.push(orbclient::event::K_MINUS);
    decrease_k.sort();
    supported = Vec::new();
    supported.push(Shortcut{id: CommonId::Open, keys: decrease_k});
    sceq.enable(supported);
*/
    'events: loop {
        for event in window.events() {
            match event.to_option() {
                EventOption::Quit(qe) => break 'events,
                EventOption::Key(ke) => {
                    match sceq.update(ke) {
                        Some(scid) => {
                            match scid {
                                &CommonId::Quit => {break 'events },
                                &CommonId::Open => {println!("{:?} not implemented.", scid)},
                                _ => {println!("{:?} unknown shortcut.", scid)}
                            };
                        },
                        None => {println!("No match")},
                    };
                }, //orbclient_window_shortcuts implementation
                _ => break
            };
        }
    }
}