Populate basic UI
This commit is contained in:
parent
e8fdd82119
commit
10dfe4f22c
|
@ -1,13 +1,15 @@
|
||||||
use egui_wgpu_backend::RenderPass as EguiRenderPass;
|
|
||||||
use std::sync::Arc;
|
|
||||||
use egui_wgpu_backend::wgpu;
|
use egui_wgpu_backend::wgpu;
|
||||||
|
use egui_wgpu_backend::RenderPass as EguiRenderPass;
|
||||||
use egui_winit::winit::{
|
use egui_winit::winit::{
|
||||||
self,
|
self,
|
||||||
|
dpi::PhysicalSize,
|
||||||
event::{Event, WindowEvent},
|
event::{Event, WindowEvent},
|
||||||
event_loop::{ControlFlow, EventLoop},
|
event_loop::{ControlFlow, EventLoop},
|
||||||
window::WindowBuilder,
|
window::WindowBuilder,
|
||||||
dpi::PhysicalSize,
|
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
mod ui;
|
||||||
|
|
||||||
struct Application {
|
struct Application {
|
||||||
window: winit::window::Window,
|
window: winit::window::Window,
|
||||||
|
@ -19,6 +21,7 @@ struct Application {
|
||||||
egui_state: egui_winit::State,
|
egui_state: egui_winit::State,
|
||||||
egui_ctx: egui::Context,
|
egui_ctx: egui::Context,
|
||||||
egui_rp: EguiRenderPass,
|
egui_rp: EguiRenderPass,
|
||||||
|
ui: ui::UserInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application {
|
impl Application {
|
||||||
|
@ -61,7 +64,18 @@ impl Application {
|
||||||
let egui_ctx = egui::Context::default();
|
let egui_ctx = egui::Context::default();
|
||||||
let egui_rp = egui_wgpu_backend::RenderPass::new(&device, config.format, 1);
|
let egui_rp = egui_wgpu_backend::RenderPass::new(&device, config.format, 1);
|
||||||
|
|
||||||
Self { window, device, queue, size, surface, config, egui_state, egui_ctx, egui_rp }
|
Self {
|
||||||
|
window,
|
||||||
|
device,
|
||||||
|
queue,
|
||||||
|
size,
|
||||||
|
surface,
|
||||||
|
config,
|
||||||
|
egui_state,
|
||||||
|
egui_ctx,
|
||||||
|
egui_rp,
|
||||||
|
ui: ui::UserInterface::new(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self) {
|
pub fn update(&mut self) {
|
||||||
|
@ -84,11 +98,7 @@ impl Application {
|
||||||
Ok(surface_texture) => {
|
Ok(surface_texture) => {
|
||||||
let raw_input = self.egui_state.take_egui_input(&self.window);
|
let raw_input = self.egui_state.take_egui_input(&self.window);
|
||||||
let output = self.egui_ctx.run(raw_input, |ctx| {
|
let output = self.egui_ctx.run(raw_input, |ctx| {
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
self.ui.run(ctx);
|
||||||
egui::Window::new("example_window").show(ctx, |ui| {
|
|
||||||
ui.heading("Hello world!");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
self.egui_state.handle_platform_output(
|
self.egui_state.handle_platform_output(
|
||||||
|
@ -105,7 +115,8 @@ impl Application {
|
||||||
scale_factor: 1.0, // TODO ???
|
scale_factor: 1.0, // TODO ???
|
||||||
};
|
};
|
||||||
|
|
||||||
self.egui_rp.update_buffers(&self.device, &self.queue, &meshes, &screen_desc);
|
self.egui_rp
|
||||||
|
.update_buffers(&self.device, &self.queue, &meshes, &screen_desc);
|
||||||
self.egui_rp
|
self.egui_rp
|
||||||
.add_textures(&self.device, &self.queue, &output.textures_delta)
|
.add_textures(&self.device, &self.queue, &output.textures_delta)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -135,7 +146,7 @@ fn main() {
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
*control_flow = ControlFlow::Wait;
|
*control_flow = ControlFlow::Wait;
|
||||||
println!("{:?}", event);
|
// println!("{:?}", event);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::RedrawRequested(window_id) if window_id == app.window.id() => {
|
Event::RedrawRequested(window_id) if window_id == app.window.id() => {
|
||||||
|
@ -143,6 +154,10 @@ fn main() {
|
||||||
}
|
}
|
||||||
Event::MainEventsCleared => {
|
Event::MainEventsCleared => {
|
||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
|
if app.ui.should_quit() {
|
||||||
|
*control_flow = ControlFlow::Exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Event::WindowEvent { event, window_id } if window_id == app.window.id() => {
|
Event::WindowEvent { event, window_id } if window_id == app.window.id() => {
|
||||||
match &event {
|
match &event {
|
||||||
|
@ -157,7 +172,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
app.egui_state.on_event(&app.egui_ctx, &event);
|
app.egui_state.on_event(&app.egui_ctx, &event);
|
||||||
},
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,115 @@
|
||||||
|
pub struct UserInterface {
|
||||||
|
developer_mode: bool,
|
||||||
|
show_profiler: bool,
|
||||||
|
quit: bool,
|
||||||
|
show_about: bool,
|
||||||
|
log_contents: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UserInterface {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
developer_mode: true,
|
||||||
|
show_profiler: false,
|
||||||
|
quit: false,
|
||||||
|
show_about: false,
|
||||||
|
log_contents: "Hello logging!\n".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn should_quit(&self) -> bool {
|
||||||
|
self.quit
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(&mut self, ctx: &egui::Context) {
|
||||||
|
egui::TopBottomPanel::top("menu_bar").show(ctx, |ui| {
|
||||||
|
egui::menu::bar(ui, |ui| {
|
||||||
|
ui.menu_button("File", |ui| {
|
||||||
|
if self.developer_mode {
|
||||||
|
if ui.button("fuck").clicked() {
|
||||||
|
println!("fuck");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ui.button("Save").clicked() {
|
||||||
|
println!("Saving!");
|
||||||
|
ui.close_menu();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ui.button("Save as...").clicked() {
|
||||||
|
println!("Saving as!");
|
||||||
|
ui.close_menu();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ui.button("Open...").clicked() {
|
||||||
|
println!("Opening!");
|
||||||
|
ui.close_menu();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ui.button("Quit").clicked() {
|
||||||
|
println!("Quitting!");
|
||||||
|
ui.close_menu();
|
||||||
|
self.quit = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.menu_button("Edit", |ui| {
|
||||||
|
if ui.button("Undo").clicked() {
|
||||||
|
println!("Undoing!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ui.button("Redo").clicked() {
|
||||||
|
println!("Redoing!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.menu_button("View", |ui| {
|
||||||
|
ui.checkbox(&mut self.developer_mode, "Developer mode");
|
||||||
|
ui.checkbox(&mut self.show_profiler, "Show profiler");
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.menu_button("Help", |ui| {
|
||||||
|
if ui.button("About").clicked() {
|
||||||
|
self.show_about = true;
|
||||||
|
ui.close_menu();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
egui::Window::new("example_window").show(ctx, |ui| {
|
||||||
|
ui.heading("Hello world!");
|
||||||
|
});
|
||||||
|
|
||||||
|
if self.show_about {
|
||||||
|
egui::Window::new("About")
|
||||||
|
.open(&mut self.show_about)
|
||||||
|
.resizable(false)
|
||||||
|
.collapsible(false)
|
||||||
|
.show(ctx, |ui| {
|
||||||
|
ui.vertical_centered(|ui| {
|
||||||
|
ui.heading("Cyborg Editor");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
egui::TopBottomPanel::bottom("info_panel")
|
||||||
|
.resizable(true)
|
||||||
|
.show(ctx, |ui| {
|
||||||
|
ui.heading("Log Output");
|
||||||
|
|
||||||
|
egui::containers::ScrollArea::vertical()
|
||||||
|
.auto_shrink([false, false])
|
||||||
|
.max_width(f32::INFINITY)
|
||||||
|
.max_height(f32::INFINITY)
|
||||||
|
.show(ui, |ui| {
|
||||||
|
let text_edit = egui::TextEdit::multiline(&mut self.log_contents)
|
||||||
|
.desired_width(f32::INFINITY)
|
||||||
|
.frame(false);
|
||||||
|
ui.add(text_edit);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue