add wrapper struct to simplify imgui init and usage
rather than forcing use of 3 separate structs
This commit is contained in:
parent
3befd786ca
commit
0f4ed2965c
|
@ -1,2 +1,52 @@
|
|||
use crate::platform::Platform;
|
||||
use crate::renderer::Renderer;
|
||||
use ggdt::graphics::bitmap::rgb::RgbaBitmap;
|
||||
use ggdt::system::event::{SystemEvent, SystemEventHandler};
|
||||
use ggdt::system::res::standard::Standard;
|
||||
use ggdt::system::System;
|
||||
|
||||
pub mod platform;
|
||||
pub mod renderer;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ImGui {
|
||||
context: imgui::Context,
|
||||
platform: Platform,
|
||||
renderer: Renderer,
|
||||
}
|
||||
|
||||
impl ImGui {
|
||||
pub fn new() -> Self {
|
||||
let mut context = imgui::Context::create();
|
||||
let platform = Platform::new(&mut context);
|
||||
let renderer = Renderer::new(&mut context);
|
||||
|
||||
ImGui { context, platform, renderer }
|
||||
}
|
||||
|
||||
pub fn new_frame(&mut self, system: &mut System<Standard>) -> &mut imgui::Ui {
|
||||
self.platform.prepare_frame(&mut self.context, system);
|
||||
self.context.new_frame()
|
||||
}
|
||||
|
||||
pub fn render(&mut self, dest: &mut RgbaBitmap) {
|
||||
let draw_data = self.context.render();
|
||||
self.renderer.render(draw_data, dest)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn context(&self) -> &imgui::Context {
|
||||
&self.context
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn context_mut(&mut self) -> &mut imgui::Context {
|
||||
&mut self.context
|
||||
}
|
||||
}
|
||||
|
||||
impl SystemEventHandler for ImGui {
|
||||
fn handle_event(&mut self, event: &SystemEvent) -> bool {
|
||||
self.platform.handle_event(&mut self.context, event)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,6 +136,7 @@ fn handle_mouse_button_event(io: &mut imgui::Io, button: MouseButton, down: bool
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Platform {
|
||||
last_frame: Instant,
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ use ggdt::math::rect::Rect;
|
|||
use ggdt::math::vector2::Vector2;
|
||||
use imgui::internal::RawWrapper;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Renderer {
|
||||
pub texture_map: imgui::Textures<RgbaBitmap>,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue