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 {
|
impl NewRollWindow {
|
||||||
pub fn draw(&mut self, ctx: &egui::Context, app_state: &mut AppState) -> bool {
|
pub fn draw(&mut self, ctx: &egui::Context, app_state: &mut AppState) -> bool {
|
||||||
let mut open = true;
|
let mut close_unclicked = true;
|
||||||
let close_req = Window::new("New Roll")
|
let mut close_window = false;
|
||||||
.open(&mut open)
|
Window::new("New Roll")
|
||||||
|
.open(&mut close_unclicked)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let label = ui.label("ID: ");
|
let label = ui.label("ID: ");
|
||||||
@ -72,17 +73,13 @@ impl NewRollWindow {
|
|||||||
self.date,
|
self.date,
|
||||||
self.exps,
|
self.exps,
|
||||||
));
|
));
|
||||||
return true;
|
close_window = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.show_id_req_err {
|
if self.show_id_req_err {
|
||||||
ui.colored_label(Color32::DARK_RED, "Error: ID required");
|
ui.colored_label(Color32::DARK_RED, "Error: ID required");
|
||||||
}
|
}
|
||||||
false
|
});
|
||||||
})
|
!close_unclicked || close_window
|
||||||
.unwrap()
|
|
||||||
.inner
|
|
||||||
.unwrap_or(false);
|
|
||||||
!open || close_req
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,11 @@ impl RollViewWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(&mut self, ctx: &egui::Context, app_state: &mut AppState) -> bool {
|
pub fn draw(&mut self, ctx: &egui::Context, app_state: &mut AppState) -> bool {
|
||||||
let mut open = true;
|
let mut close_unclicked = true;
|
||||||
let window = Window::new(format!("Roll {}", app_state.rolls[self.roll].id)).open(&mut open);
|
let mut close_window = false;
|
||||||
let deleted = window
|
let window = Window::new(format!("Roll {}", app_state.rolls[self.roll].id))
|
||||||
.show(ctx, |ui| {
|
.open(&mut close_unclicked);
|
||||||
|
window.show(ctx, |ui| {
|
||||||
let roll = &mut app_state.rolls[self.roll];
|
let roll = &mut app_state.rolls[self.roll];
|
||||||
ui.label(format!("Name: {}", roll.name));
|
ui.label(format!("Name: {}", roll.name));
|
||||||
ui.label(format!("Description: {}", roll.desc));
|
ui.label(format!("Description: {}", roll.desc));
|
||||||
@ -65,33 +66,22 @@ impl RollViewWindow {
|
|||||||
self.confirm_delete = true;
|
self.confirm_delete = true;
|
||||||
}
|
}
|
||||||
if self.confirm_delete {
|
if self.confirm_delete {
|
||||||
Window::new("Confirm delete")
|
Window::new("Confirm delete").show(ctx, |ui| {
|
||||||
.show(ctx, |ui| {
|
|
||||||
ui.heading(format!(
|
ui.heading(format!(
|
||||||
"Really delete roll {}?",
|
"Really delete roll {}?",
|
||||||
app_state.rolls[self.roll].id
|
app_state.rolls[self.roll].id
|
||||||
));
|
));
|
||||||
if ui.button("No").clicked() {
|
if ui.button("No").clicked() {
|
||||||
self.confirm_delete = false;
|
self.confirm_delete = false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if ui.button("Yes").clicked() {
|
if ui.button("Yes").clicked() {
|
||||||
app_state.rolls.remove(self.roll);
|
app_state.rolls.remove(self.roll);
|
||||||
return true;
|
close_window = true;
|
||||||
}
|
}
|
||||||
false
|
});
|
||||||
})
|
|
||||||
.unwrap()
|
|
||||||
.inner
|
|
||||||
.unwrap_or(false)
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
.unwrap()
|
!close_unclicked || close_window
|
||||||
.inner
|
|
||||||
.unwrap_or(false);
|
|
||||||
!open || deleted
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn roll(&self) -> usize {
|
pub fn roll(&self) -> usize {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user