Clean up code to determine whether a window will close
This commit is contained in:
parent
4dc64031b4
commit
bea57e2110
@ -31,9 +31,10 @@ impl Default for NewRollWindow {
|
||||
|
||||
impl NewRollWindow {
|
||||
pub fn draw(&mut self, ctx: &egui::Context, app_state: &mut AppState) -> bool {
|
||||
let mut open = true;
|
||||
let close_req = Window::new("New Roll")
|
||||
.open(&mut open)
|
||||
let mut close_unclicked = true;
|
||||
let mut close_window = false;
|
||||
Window::new("New Roll")
|
||||
.open(&mut close_unclicked)
|
||||
.show(ctx, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let label = ui.label("ID: ");
|
||||
@ -72,17 +73,13 @@ impl NewRollWindow {
|
||||
self.date,
|
||||
self.exps,
|
||||
));
|
||||
return true;
|
||||
close_window = true;
|
||||
}
|
||||
}
|
||||
if self.show_id_req_err {
|
||||
ui.colored_label(Color32::DARK_RED, "Error: ID required");
|
||||
}
|
||||
false
|
||||
})
|
||||
.unwrap()
|
||||
.inner
|
||||
.unwrap_or(false);
|
||||
!open || close_req
|
||||
});
|
||||
!close_unclicked || close_window
|
||||
}
|
||||
}
|
||||
|
124
src/roll_view.rs
124
src/roll_view.rs
@ -22,76 +22,66 @@ impl RollViewWindow {
|
||||
}
|
||||
|
||||
pub fn draw(&mut self, ctx: &egui::Context, app_state: &mut AppState) -> bool {
|
||||
let mut open = true;
|
||||
let window = Window::new(format!("Roll {}", app_state.rolls[self.roll].id)).open(&mut open);
|
||||
let deleted = window
|
||||
.show(ctx, |ui| {
|
||||
let roll = &mut app_state.rolls[self.roll];
|
||||
ui.label(format!("Name: {}", roll.name));
|
||||
ui.label(format!("Description: {}", roll.desc));
|
||||
ui.label(format!("Date: {}", roll.date.format("%Y-%m-%d")));
|
||||
ui.label("Exposures:");
|
||||
ui.horizontal_top(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
for (i, chunk) in roll.exposures.iter().chunks(5).into_iter().enumerate() {
|
||||
ui.horizontal(|ui| {
|
||||
for (j, exp) in chunk.enumerate() {
|
||||
let num = i * 5 + j;
|
||||
let mut label = RichText::new(format!("{:02}", exp.num));
|
||||
if exp.printed {
|
||||
if exp.damaged {
|
||||
label = label.color(Color32::DARK_RED);
|
||||
} else {
|
||||
label = label.color(Color32::DARK_BLUE);
|
||||
}
|
||||
let mut close_unclicked = true;
|
||||
let mut close_window = false;
|
||||
let window = Window::new(format!("Roll {}", app_state.rolls[self.roll].id))
|
||||
.open(&mut close_unclicked);
|
||||
window.show(ctx, |ui| {
|
||||
let roll = &mut app_state.rolls[self.roll];
|
||||
ui.label(format!("Name: {}", roll.name));
|
||||
ui.label(format!("Description: {}", roll.desc));
|
||||
ui.label(format!("Date: {}", roll.date.format("%Y-%m-%d")));
|
||||
ui.label("Exposures:");
|
||||
ui.horizontal_top(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
for (i, chunk) in roll.exposures.iter().chunks(5).into_iter().enumerate() {
|
||||
ui.horizontal(|ui| {
|
||||
for (j, exp) in chunk.enumerate() {
|
||||
let num = i * 5 + j;
|
||||
let mut label = RichText::new(format!("{:02}", exp.num));
|
||||
if exp.printed {
|
||||
if exp.damaged {
|
||||
label = label.color(Color32::DARK_RED);
|
||||
} else {
|
||||
label = label.color(Color32::DARK_BLUE);
|
||||
}
|
||||
ui.selectable_value(&mut self.exp, num as u8, label);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
ui.vertical(|ui| {
|
||||
let exp = &mut roll.exposures[self.exp as usize];
|
||||
ui.checkbox(&mut exp.printed, "Printed");
|
||||
if !exp.printed {
|
||||
exp.damaged = false;
|
||||
}
|
||||
if exp.printed {
|
||||
ui.checkbox(&mut exp.damaged, "Damaged");
|
||||
}
|
||||
});
|
||||
ui.selectable_value(&mut self.exp, num as u8, label);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if ui.button("Delete").clicked() {
|
||||
self.confirm_delete = true;
|
||||
}
|
||||
if self.confirm_delete {
|
||||
Window::new("Confirm delete")
|
||||
.show(ctx, |ui| {
|
||||
ui.heading(format!(
|
||||
"Really delete roll {}?",
|
||||
app_state.rolls[self.roll].id
|
||||
));
|
||||
if ui.button("No").clicked() {
|
||||
self.confirm_delete = false;
|
||||
return false;
|
||||
}
|
||||
if ui.button("Yes").clicked() {
|
||||
app_state.rolls.remove(self.roll);
|
||||
return true;
|
||||
}
|
||||
false
|
||||
})
|
||||
.unwrap()
|
||||
.inner
|
||||
.unwrap_or(false)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
.unwrap()
|
||||
.inner
|
||||
.unwrap_or(false);
|
||||
!open || deleted
|
||||
ui.vertical(|ui| {
|
||||
let exp = &mut roll.exposures[self.exp as usize];
|
||||
ui.checkbox(&mut exp.printed, "Printed");
|
||||
if !exp.printed {
|
||||
exp.damaged = false;
|
||||
}
|
||||
if exp.printed {
|
||||
ui.checkbox(&mut exp.damaged, "Damaged");
|
||||
}
|
||||
});
|
||||
});
|
||||
if ui.button("Delete").clicked() {
|
||||
self.confirm_delete = true;
|
||||
}
|
||||
if self.confirm_delete {
|
||||
Window::new("Confirm delete").show(ctx, |ui| {
|
||||
ui.heading(format!(
|
||||
"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;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
!close_unclicked || close_window
|
||||
}
|
||||
|
||||
pub fn roll(&self) -> usize {
|
||||
|
Loading…
x
Reference in New Issue
Block a user