<commit_before>// Copyright 2015 The Athena Developers.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

extern crate cgmath;
#[macro_use]
extern crate gfx;
extern crate gfx_text;
extern crate gfx_texture;

use gfx::traits::*;
use std::cell::RefCell;
use std::rc::Rc;

mod render;
pub mod widget;

pub enum Event {
    MouseMoved([i32; 2]),
    MouseClick,
    Placeholder
}

pub struct Gui<R: gfx::Resources, F: gfx::Factory<R>> {
    root: widget::Layout<R>,
    render_data: Rc<RefCell<render::RenderData<R, F>>>
}

impl<R: gfx::Resources, F: gfx::Factory<R>> Gui<R, F> {
    pub fn root(&self) -> &widget::Layout<R> { &self.root }
    pub fn root_mut(&mut self) -> &mut widget::Layout<R> { &mut self.root }

    pub fn new<D: gfx::Device, FactorySpawner>(device: &mut D, root: widget::Layout<R>, spawner: FactorySpawner) -> Gui<R, F>
        where FactorySpawner: Fn(&mut D) -> F
    {
        Gui {
            root: root,
            render_data: Rc::new(RefCell::new(render::RenderData::new(device, spawner)))
        }
    }

    pub fn raise_event<S: gfx::Stream<R>>(&mut self, stream: &S, event: Event) {
        let (x, y) = stream.get_output().get_size();
        let area = render::RenderArea {
            position: [0, 0],
            size: [x as i32, y as i32]
        };

        self.root.raise_event(&event, &area);
    }

    pub fn render<S: gfx::Stream<R>>(
        &mut self,
        factory: &mut F, stream: &mut S)
    {
        // Set up a layout area to the whole screen
        let (x, y) = stream.get_output().get_size();
        let area = render::RenderArea {
            position: [0, 0],
            size: [x as i32, y as i32]
        };
<commit_msg>Add an option to replace the root of Gui<commit_after>// Copyright 2015 The Athena Developers.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

extern crate cgmath;
#[macro_use]
extern crate gfx;
extern crate gfx_text;
extern crate gfx_texture;

use gfx::traits::*;
use std::cell::RefCell;
use std::rc::Rc;

mod render;
pub mod widget;

pub enum Event {
    MouseMoved([i32; 2]),
    MouseClick,
    Placeholder
}

pub struct Gui<R: gfx::Resources, F: gfx::Factory<R>> {
    root: widget::Layout<R>,
    render_data: Rc<RefCell<render::RenderData<R, F>>>
}

impl<R: gfx::Resources, F: gfx::Factory<R>> Gui<R, F> {
    pub fn root(&self) -> &widget::Layout<R> { &self.root }
    pub fn root_mut(&mut self) -> &mut widget::Layout<R> { &mut self.root }
    pub fn set_root(&mut self, root: widget::Layout<R>) { self.root = root; }

    pub fn new<D: gfx::Device, FactorySpawner>(device: &mut D, root: widget::Layout<R>, spawner: FactorySpawner) -> Gui<R, F>
        where FactorySpawner: Fn(&mut D) -> F
    {
        Gui {
            root: root,
            render_data: Rc::new(RefCell::new(render::RenderData::new(device, spawner)))
        }
    }

    pub fn raise_event<S: gfx::Stream<R>>(&mut self, stream: &S, event: Event) {
        let (x, y) = stream.get_output().get_size();
        let area = render::RenderArea {
            position: [0, 0],
            size: [x as i32, y as i32]
        };

        self.root.raise_event(&event, &area);
    }

    pub fn render<S: gfx::Stream<R>>(
        &mut self,
        factory: &mut F, stream: &mut S)
    {
        // Set up a layout area to the whole screen
        let (x, y) = stream.get_output().get_size();
        let area = render::RenderArea {
            position: [0, 0],
            size: [x as i32, y as i32]
        };

{'fraction_non_alphanumeric': 0.1398352260075707, 'fraction_numerical': 0.010242707637497217, 'mean_word_length': 2.822978723404255, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '442024', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1458, 'n_words': 486}