Skip to content

Commit

Permalink
Views window: Add button to create new view if there are no views
Browse files Browse the repository at this point in the history
  • Loading branch information
crumblingstatue committed Oct 16, 2024
1 parent c2ddacb commit 6e42ad5
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/gui/windows/views_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impl super::Window for ViewsWindow {
let mut removed_idx = None;
if app.meta_state.meta.views.is_empty() {
ui.label("No views");
new_from_perspective_button(ui, app);
return;
}
TableBuilder::new(ui)
Expand Down Expand Up @@ -144,17 +145,7 @@ impl super::Window for ViewsWindow {
});
});
ui.separator();
ui.menu_button("New from perspective", |ui| {
for (key, perspective) in app.meta_state.meta.low.perspectives.iter() {
if ui.button(&perspective.name).clicked() {
ui.close_menu();
app.cmd.push(Cmd::CreateView {
perspective_key: key,
name: perspective.name.to_owned(),
});
}
}
});
new_from_perspective_button(ui, app);
ui.separator();
if let Some(view) = app.meta_state.meta.views.get_mut(self.selected) {
ui.horizontal(|ui| {
Expand Down Expand Up @@ -282,6 +273,20 @@ impl super::Window for ViewsWindow {
}
}

fn new_from_perspective_button(ui: &mut egui::Ui, app: &mut App) {
ui.menu_button("New from perspective", |ui| {
for (key, perspective) in app.meta_state.meta.low.perspectives.iter() {
if ui.button(&perspective.name).clicked() {
ui.close_menu();
app.cmd.push(Cmd::CreateView {
perspective_key: key,
name: perspective.name.to_owned(),
});
}
}
});
}

/// Returns whether the value was changed
fn view_combo(
id: impl Hash,
Expand Down

0 comments on commit 6e42ad5

Please sign in to comment.