2018-12-26 22:08:50 +00:00
|
|
|
use crate::{layout, math::*, style, types::*};
|
|
|
|
|
|
|
|
/// Encapsulates input, layout and painting for ease of use.
|
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
|
pub struct Emgui {
|
|
|
|
pub last_input: RawInput,
|
|
|
|
pub layout: layout::Layout,
|
|
|
|
pub style: style::Style,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Emgui {
|
|
|
|
pub fn new_frame(&mut self, new_input: RawInput) {
|
|
|
|
let gui_input = GuiInput::from_last_and_new(&self.last_input, &new_input);
|
|
|
|
self.last_input = new_input;
|
|
|
|
|
|
|
|
// TODO: this should be nicer
|
|
|
|
self.layout.commands.clear();
|
2018-12-27 22:26:05 +00:00
|
|
|
self.layout.cursor = vec2(0.0, 0.0);
|
2018-12-26 22:08:50 +00:00
|
|
|
self.layout.input = gui_input;
|
|
|
|
if !gui_input.mouse_down {
|
2018-12-27 22:26:05 +00:00
|
|
|
self.layout.memory.active_id = None;
|
2018-12-26 22:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn paint(&mut self) -> Vec<PaintCmd> {
|
|
|
|
style::into_paint_commands(self.layout.gui_commands(), &self.style)
|
|
|
|
}
|
|
|
|
}
|