<commit_before>
use std::collections::HashMap;
use point::Point;
use widget::Widget;
use piston::{
    GameEvent,
    MouseMove,
    MousePress,
    MouseRelease,
};
use label::FontSize;
use mouse_state::{
    Up,
    Down,
    MouseState,
};
use glyph_cache::{
    GlyphCache,
    Character,
};

/// User Interface Identifier. Each unique `widget::draw` call
/// should pass it's own unique UIID so that UIContext can keep
/// track of it's state.
pub type UIID = u64;

/// UIContext retains the state of all widgets and
/// data relevant to the draw_widget functions.
pub struct UIContext {
    data: HashMap<UIID, Widget>,
    pub mouse: MouseState,
    glyph_cache: GlyphCache,
}

impl UIContext {

    /// Constructor for a UIContext.
    pub fn new(font_file: &str) -> UIContext {
        UIContext {
            data: HashMap::new(),
            mouse: MouseState::new(Point::new(0f64, 0f64, 0f64), Up, Up, Up),
            glyph_cache: GlyphCache::new(font_file),
        }
    }

    /// Handle game events and update the state.
    pub fn event(&mut self, event: &mut GameEvent) {
        match *event {
            MouseMove(args) => {
                self.mouse.pos = Point::new(args.x, args.y, 0f64);
            },
            MousePress(args) => {
                *match args.button {
                    /*Left*/ _ => &mut self.mouse.left,
                    //Right => &mut self.mouse.right,
                    //Middle => &mut self.mouse.middle,
                } = Down;
            },
            MouseRelease(args) => {
                *match args.button {
                    /*Left*/ _ => &mut self.mouse.left,
                    //Right => &mut self.mouse.right,
                    //Middle => &mut self.mouse.middle,
                } = Up;
            },
            _ => (),
        }
    }

    /// Return the current mouse state.
    pub fn get_mouse_state(&self) -> MouseState {
        self.mouse.clone()
    }

    /// Return a mutable reference to the widget that matches the given ui_id
    pub fn get_widget(&mut self, ui_id: UIID, default: Widget) -> &mut Widget {
        self.data.find_or_insert(ui_id, default)
    }

    /// Return a reference to a `Character` from the GlyphCache.
    pub fn get_character(&mut self, size: FontSize, ch: char) -> &Character {
        self.glyph_cache.get_character(size, ch)
    }

}
<commit_msg>Upgrade to latest Piston<commit_after>
use std::collections::HashMap;
use point::Point;
use widget::Widget;
use piston::{
    GameEvent,
    Input,
    input,
};
use label::FontSize;
use mouse_state::{
    Up,
    Down,
    MouseState,
};
use glyph_cache::{
    GlyphCache,
    Character,
};

/// User Interface Identifier. Each unique `widget::draw` call
/// should pass it's own unique UIID so that UIContext can keep
/// track of it's state.
pub type UIID = u64;

/// UIContext retains the state of all widgets and
/// data relevant to the draw_widget functions.
pub struct UIContext {
    data: HashMap<UIID, Widget>,
    pub mouse: MouseState,
    glyph_cache: GlyphCache,
}

impl UIContext {

    /// Constructor for a UIContext.
    pub fn new(font_file: &str) -> UIContext {
        UIContext {
            data: HashMap::new(),
            mouse: MouseState::new(Point::new(0f64, 0f64, 0f64), Up, Up, Up),
            glyph_cache: GlyphCache::new(font_file),
        }
    }

    /// Handle game events and update the state.
    pub fn event(&mut self, event: &mut GameEvent) {
        match *event {
            Input(input::MouseMove { x, y, .. }) => {
                self.mouse.pos = Point::new(x, y, 0f64);
            },
            Input(input::MousePress { button, .. }) => {
                *match button {
                    /*Left*/ _ => &mut self.mouse.left,
                    //Right => &mut self.mouse.right,
                    //Middle => &mut self.mouse.middle,
                } = Down;
            },
            Input(input::MouseRelease { button, .. }) => {
                *match button {
                    /*Left*/ _ => &mut self.mouse.left,
                    //Right => &mut self.mouse.right,
                    //Middle => &mut self.mouse.middle,
                } = Up;
            },
            _ => (),
        }
    }

    /// Return the current mouse state.
    pub fn get_mouse_state(&self) -> MouseState {
        self.mouse.clone()
    }

    /// Return a mutable reference to the widget that matches the given ui_id
    pub fn get_widget(&mut self, ui_id: UIID, default: Widget) -> &mut Widget {
        self.data.find_or_insert(ui_id, default)
    }

    /// Return a reference to a `Character` from the GlyphCache.
    pub fn get_character(&mut self, size: FontSize, ch: char) -> &Character {
        self.glyph_cache.get_character(size, ch)
    }

}

{'fraction_non_alphanumeric': 0.12743251726302574, 'fraction_numerical': 0.005858966310943712, 'mean_word_length': 1.8486293206197855, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2049920', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1406, 'n_words': 404}