Disable window-opening buttons when their corresponding window is open

This commit is contained in:
pjht 2023-05-31 09:16:14 -05:00
parent 3e16dbd330
commit 1d2ff0f262
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E
2 changed files with 24 additions and 17 deletions

View File

@ -7,7 +7,7 @@ mod roll;
mod roll_view;
use edit_films::EditFilmsWindow;
use eframe::egui::{self, menu};
use eframe::egui::{self, menu, Button};
use film::{Film, FilmKey};
use new_roll::NewRollWindow;
use roll::Roll;
@ -68,10 +68,8 @@ impl eframe::App for MyApp {
egui::TopBottomPanel::top("menu_bar_panel").show(ctx, |ui| {
menu::bar(ui, |ui| {
ui.menu_button("View", |ui| {
if ui.button("Edit films").clicked() {
if self.edit_films_window.is_none() {
self.edit_films_window = Some(EditFilmsWindow::new());
}
if ui.add_enabled(self.edit_films_window.is_none(), Button::new("Edit films")).clicked() {
self.edit_films_window = Some(EditFilmsWindow::new());
}
})
})
@ -80,13 +78,17 @@ impl eframe::App for MyApp {
ui.heading("Film Manager");
ui.label("Rolls:");
for (i, roll) in self.state.rolls.iter().enumerate() {
if ui.button(roll.short_str()).clicked()
let has_view = self.roll_views.iter().find(|view| view.roll() == i).is_some();
if ui.add_enabled(!has_view, Button::new(roll.short_str())).clicked()
&& self.roll_views.iter().find(|v| v.roll() == i).is_none()
{
self.roll_views.push(RollViewWindow::new(i));
}
}
if ui.button("Add").clicked() && self.new_roll_window.is_none() {
if ui
.add_enabled(self.new_roll_window.is_none(), egui::Button::new("Add"))
.clicked()
{
self.new_roll_window = Some(NewRollWindow::new(&self.state));
}
self.roll_views

View File

@ -1,12 +1,12 @@
use chrono::NaiveDate;
use eframe::{
egui::{self, RichText, Window},
egui::{self, Button, RichText, Window},
epaint::Color32,
};
use egui_datepicker::DatePicker;
use itertools::Itertools;
use crate::{AppState, film::FilmKey};
use crate::{film::FilmKey, AppState};
pub struct RollViewWindow {
roll: usize,
@ -198,7 +198,10 @@ impl RollViewWindow {
}
});
});
if ui.button("Delete").clicked() {
if ui
.add_enabled(!self.confirm_delete, Button::new("Delete"))
.clicked()
{
self.confirm_delete = true;
}
if self.confirm_delete {
@ -207,13 +210,15 @@ impl RollViewWindow {
"Really delete roll {}?",
app_state.rolls[self.roll].id
));
if ui.button("No").clicked() {
self.confirm_delete = false;
}
if ui.button("Yes").clicked() {
app_state.rolls.remove(self.roll);
close_window = true;
}
ui.horizontal(|ui| {
if ui.button("No").clicked() {
self.confirm_delete = false;
}
if ui.button("Yes").clicked() {
app_state.rolls.remove(self.roll);
close_window = true;
}
});
});
}
});