egui/emgui/src/emgui.rs

56 lines
1.6 KiB
Rust
Raw Normal View History

use std::sync::Arc;
2019-01-06 15:34:01 +00:00
use crate::{font::Font, layout, style, types::GuiInput, Frame, Painter, RawInput};
2018-12-26 22:08:50 +00:00
/// Encapsulates input, layout and painting for ease of use.
2019-01-05 14:28:07 +00:00
#[derive(Clone)]
2018-12-26 22:08:50 +00:00
pub struct Emgui {
pub last_input: RawInput,
2019-01-06 15:34:01 +00:00
pub data: layout::Data,
2018-12-26 22:08:50 +00:00
pub style: style::Style,
2019-01-06 15:34:01 +00:00
pub painter: Painter,
2018-12-26 22:08:50 +00:00
}
impl Emgui {
pub fn new(font: Arc<Font>) -> Emgui {
2019-01-05 14:28:07 +00:00
Emgui {
last_input: Default::default(),
2019-01-06 15:34:01 +00:00
data: layout::Data::new(font.clone()),
2019-01-05 14:28:07 +00:00
style: Default::default(),
2019-01-06 15:34:01 +00:00
painter: Painter::new(font),
2019-01-05 14:28:07 +00:00
}
}
2019-01-06 15:34:01 +00:00
pub fn texture(&self) -> (u16, u16, &[u8]) {
self.painter.texture()
}
2018-12-26 22:08:50 +00:00
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;
2019-01-06 15:34:01 +00:00
self.data.new_frame(gui_input);
}
pub fn whole_screen_region(&mut self) -> layout::Region {
let size = self.data.input.screen_size;
2019-01-06 15:34:01 +00:00
layout::Region {
data: &mut self.data,
id: Default::default(),
dir: layout::Direction::Vertical,
cursor: Default::default(),
bounding_size: Default::default(),
available_space: size,
2019-01-06 15:34:01 +00:00
}
}
pub fn set_options(&mut self, options: layout::LayoutOptions) {
self.data.options = options;
2018-12-26 22:08:50 +00:00
}
2019-01-06 15:34:01 +00:00
pub fn paint(&mut self) -> Frame {
let gui_commands = self.data.drain_gui_commands();
2019-01-06 15:34:01 +00:00
let paint_commands = style::into_paint_commands(gui_commands, &self.style);
self.painter.paint(&paint_commands)
2018-12-26 22:08:50 +00:00
}
}