Refactor UI layout and add workspaces (including node editor workspace)
This commit is contained in:
parent
afb3dca4ce
commit
c43544cfdf
238
editor/src/ui.rs
238
editor/src/ui.rs
|
@ -15,13 +15,21 @@ pub enum ImportKind {
|
|||
Stl,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Workspace {
|
||||
Scene,
|
||||
NodeEditor,
|
||||
}
|
||||
|
||||
pub struct UserInterface {
|
||||
file_sender: Sender<FileEvent>,
|
||||
developer_mode: bool,
|
||||
show_profiler: bool,
|
||||
quit: bool,
|
||||
show_about: bool,
|
||||
show_log: bool,
|
||||
log_contents: String,
|
||||
workspace: Workspace,
|
||||
}
|
||||
|
||||
impl UserInterface {
|
||||
|
@ -30,9 +38,11 @@ impl UserInterface {
|
|||
file_sender,
|
||||
developer_mode: true,
|
||||
show_profiler: false,
|
||||
show_log: false,
|
||||
quit: false,
|
||||
show_about: false,
|
||||
log_contents: "Hello logging!\n".to_string(),
|
||||
workspace: Workspace::Scene,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,89 +57,7 @@ impl UserInterface {
|
|||
objects: &mut [ObjectWidget],
|
||||
) {
|
||||
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() {
|
||||
ui.close_menu();
|
||||
self.file_sender.send(FileEvent::Save).unwrap();
|
||||
}
|
||||
|
||||
if ui.button("Save as...").clicked() {
|
||||
ui.close_menu();
|
||||
|
||||
let file_sender = self.file_sender.to_owned();
|
||||
std::thread::spawn(move || {
|
||||
if let Some(path) = rfd::FileDialog::new().save_file() {
|
||||
file_sender.send(FileEvent::SaveAs(path)).unwrap();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ui.menu_button("Import...", |ui| {
|
||||
if ui.button("STL").clicked() {
|
||||
ui.close_menu();
|
||||
|
||||
let import_kind = ImportKind::Stl;
|
||||
let file_sender = self.file_sender.to_owned();
|
||||
std::thread::spawn(move || {
|
||||
let dialog = rfd::FileDialog::new().add_filter("STL", &["stl"]);
|
||||
if let Some(paths) = dialog.pick_files() {
|
||||
for path in paths.iter() {
|
||||
let event = FileEvent::Import(import_kind, path.into());
|
||||
file_sender.send(event).unwrap();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
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");
|
||||
|
||||
if ui.checkbox(&mut self.show_profiler, "Profiler").changed() {
|
||||
puffin_egui::puffin::set_scopes_on(self.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!");
|
||||
egui::menu::bar(ui, |ui| self.ui_menu_bar(ui));
|
||||
});
|
||||
|
||||
if self.show_profiler {
|
||||
|
@ -148,6 +76,129 @@ impl UserInterface {
|
|||
});
|
||||
}
|
||||
|
||||
if self.show_log {
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
match self.workspace {
|
||||
Workspace::Scene => self.ui_scene(ctx, viewport, objects),
|
||||
Workspace::NodeEditor => {
|
||||
egui::CentralPanel::default().show(ctx, |ui| self.ui_node_editor(ui));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ui_menu_bar(&mut self, ui: &mut egui::Ui) {
|
||||
ui.menu_button("File", |ui| {
|
||||
if self.developer_mode {
|
||||
if ui.button("fuck").clicked() {
|
||||
println!("fuck");
|
||||
}
|
||||
}
|
||||
|
||||
if ui.button("Save").clicked() {
|
||||
ui.close_menu();
|
||||
self.file_sender.send(FileEvent::Save).unwrap();
|
||||
}
|
||||
|
||||
if ui.button("Save as...").clicked() {
|
||||
ui.close_menu();
|
||||
|
||||
let file_sender = self.file_sender.to_owned();
|
||||
std::thread::spawn(move || {
|
||||
if let Some(path) = rfd::FileDialog::new().save_file() {
|
||||
file_sender.send(FileEvent::SaveAs(path)).unwrap();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ui.menu_button("Import...", |ui| {
|
||||
if ui.button("STL").clicked() {
|
||||
ui.close_menu();
|
||||
|
||||
let import_kind = ImportKind::Stl;
|
||||
let file_sender = self.file_sender.to_owned();
|
||||
std::thread::spawn(move || {
|
||||
let dialog = rfd::FileDialog::new().add_filter("STL", &["stl"]);
|
||||
if let Some(paths) = dialog.pick_files() {
|
||||
for path in paths.iter() {
|
||||
let event = FileEvent::Import(import_kind, path.into());
|
||||
file_sender.send(event).unwrap();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
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.show_log, "Log");
|
||||
ui.checkbox(&mut self.developer_mode, "Developer mode");
|
||||
|
||||
if ui.checkbox(&mut self.show_profiler, "Profiler").changed() {
|
||||
puffin_egui::puffin::set_scopes_on(self.show_profiler);
|
||||
}
|
||||
});
|
||||
|
||||
ui.menu_button("Help", |ui| {
|
||||
if ui.button("About").clicked() {
|
||||
self.show_about = true;
|
||||
ui.close_menu();
|
||||
}
|
||||
});
|
||||
|
||||
ui.separator();
|
||||
|
||||
self.ui_select_workspace(ui);
|
||||
}
|
||||
|
||||
pub fn ui_select_workspace(&mut self, ui: &mut egui::Ui) {
|
||||
ui.selectable_value(&mut self.workspace, Workspace::Scene, "Scene");
|
||||
ui.selectable_value(&mut self.workspace, Workspace::NodeEditor, "Node Editor");
|
||||
}
|
||||
|
||||
pub fn ui_scene(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
viewport: &mut ViewportWidget,
|
||||
objects: &mut [ObjectWidget],
|
||||
) {
|
||||
egui::SidePanel::left("objects_panel")
|
||||
.resizable(true)
|
||||
.show(ctx, |ui| {
|
||||
|
@ -156,28 +207,15 @@ impl UserInterface {
|
|||
}
|
||||
});
|
||||
|
||||
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| {
|
||||
ui.add(viewport);
|
||||
ui.heading("Viewport");
|
||||
});
|
||||
}
|
||||
|
||||
pub fn ui_node_editor(&mut self, ui: &mut egui::Ui) {
|
||||
ui.label("Node editor goes here!");
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ViewportWidget {
|
||||
|
|
Loading…
Reference in New Issue