Refactor UI layout and add workspaces (including node editor workspace)
This commit is contained in:
parent
afb3dca4ce
commit
c43544cfdf
108
editor/src/ui.rs
108
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,7 +57,53 @@ impl UserInterface {
|
|||
objects: &mut [ObjectWidget],
|
||||
) {
|
||||
egui::TopBottomPanel::top("menu_bar").show(ctx, |ui| {
|
||||
egui::menu::bar(ui, |ui| {
|
||||
egui::menu::bar(ui, |ui| self.ui_menu_bar(ui));
|
||||
});
|
||||
|
||||
if self.show_profiler {
|
||||
self.show_profiler = puffin_egui::profiler_window(ctx);
|
||||
}
|
||||
|
||||
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");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
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() {
|
||||
|
@ -112,6 +168,7 @@ impl UserInterface {
|
|||
});
|
||||
|
||||
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() {
|
||||
|
@ -125,29 +182,23 @@ impl UserInterface {
|
|||
ui.close_menu();
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
egui::Window::new("example_window").show(ctx, |ui| {
|
||||
ui.heading("Hello world!");
|
||||
});
|
||||
ui.separator();
|
||||
|
||||
if self.show_profiler {
|
||||
self.show_profiler = puffin_egui::profiler_window(ctx);
|
||||
self.ui_select_workspace(ui);
|
||||
}
|
||||
|
||||
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");
|
||||
});
|
||||
});
|
||||
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