Support multiple roll view windows at once

This commit is contained in:
pjht 2023-05-30 13:02:16 -05:00
parent 20a9799b2c
commit 298b7ac584
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A

View File

@ -83,17 +83,17 @@ struct AppState {
struct MyApp {
state: AppState,
view_roll_state: Option<ViewRollState>,
roll_views: Vec<RollViewState>,
new_roll_state: Option<NewRollState>,
}
struct ViewRollState {
struct RollViewState {
roll: usize,
confirm_delete: bool,
exp: u8,
}
impl ViewRollState {
impl RollViewState {
fn new(roll: usize) -> Self {
Self {
roll,
@ -138,7 +138,7 @@ impl MyApp {
});
Self {
state: AppState { rolls },
view_roll_state: None,
roll_views: Vec::new(),
new_roll_state: None,
}
}
@ -154,18 +154,22 @@ 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() && self.view_roll_state.is_none() {
self.view_roll_state = Some(ViewRollState::new(i));
if ui.button(roll.short_str()).clicked() && self.roll_views.iter().find(|v| v.roll == i).is_none() {
self.roll_views.push(RollViewState::new(i));
}
}
if ui.button("Add").clicked() && self.new_roll_state.is_none() {
self.new_roll_state = Some(NewRollState::default());
}
if let Some(view_roll_state) = self.view_roll_state.as_mut() {
if view_roll_window(ctx, view_roll_state, &mut self.state) {
self.view_roll_state = None;
let mut to_close = Vec::new();
for (i, roll_view_state) in self.roll_views.iter_mut().enumerate() {
if roll_view_window(ctx, roll_view_state, &mut self.state) {
to_close.push(i);
}
}
for i in to_close {
self.roll_views.remove(i);
}
if let Some(new_roll_state) = self.new_roll_state.as_mut() {
if new_roll_window(ctx, new_roll_state, &mut self.state) {
self.new_roll_state = None;
@ -175,9 +179,9 @@ impl eframe::App for MyApp {
}
}
fn view_roll_window(
fn roll_view_window(
ctx: &egui::Context,
win_state: &mut ViewRollState,
win_state: &mut RollViewState,
app_state: &mut AppState,
) -> bool {
let mut open = true;