Support multiple roll view windows at once
This commit is contained in:
parent
20a9799b2c
commit
298b7ac584
26
src/main.rs
26
src/main.rs
@ -83,17 +83,17 @@ struct AppState {
|
|||||||
|
|
||||||
struct MyApp {
|
struct MyApp {
|
||||||
state: AppState,
|
state: AppState,
|
||||||
view_roll_state: Option<ViewRollState>,
|
roll_views: Vec<RollViewState>,
|
||||||
new_roll_state: Option<NewRollState>,
|
new_roll_state: Option<NewRollState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ViewRollState {
|
struct RollViewState {
|
||||||
roll: usize,
|
roll: usize,
|
||||||
confirm_delete: bool,
|
confirm_delete: bool,
|
||||||
exp: u8,
|
exp: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ViewRollState {
|
impl RollViewState {
|
||||||
fn new(roll: usize) -> Self {
|
fn new(roll: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
roll,
|
roll,
|
||||||
@ -138,7 +138,7 @@ impl MyApp {
|
|||||||
});
|
});
|
||||||
Self {
|
Self {
|
||||||
state: AppState { rolls },
|
state: AppState { rolls },
|
||||||
view_roll_state: None,
|
roll_views: Vec::new(),
|
||||||
new_roll_state: None,
|
new_roll_state: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,18 +154,22 @@ impl eframe::App for MyApp {
|
|||||||
ui.heading("Film Manager");
|
ui.heading("Film Manager");
|
||||||
ui.label("Rolls:");
|
ui.label("Rolls:");
|
||||||
for (i, roll) in self.state.rolls.iter().enumerate() {
|
for (i, roll) in self.state.rolls.iter().enumerate() {
|
||||||
if ui.button(roll.short_str()).clicked() && self.view_roll_state.is_none() {
|
if ui.button(roll.short_str()).clicked() && self.roll_views.iter().find(|v| v.roll == i).is_none() {
|
||||||
self.view_roll_state = Some(ViewRollState::new(i));
|
self.roll_views.push(RollViewState::new(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ui.button("Add").clicked() && self.new_roll_state.is_none() {
|
if ui.button("Add").clicked() && self.new_roll_state.is_none() {
|
||||||
self.new_roll_state = Some(NewRollState::default());
|
self.new_roll_state = Some(NewRollState::default());
|
||||||
}
|
}
|
||||||
if let Some(view_roll_state) = self.view_roll_state.as_mut() {
|
let mut to_close = Vec::new();
|
||||||
if view_roll_window(ctx, view_roll_state, &mut self.state) {
|
for (i, roll_view_state) in self.roll_views.iter_mut().enumerate() {
|
||||||
self.view_roll_state = None;
|
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 let Some(new_roll_state) = self.new_roll_state.as_mut() {
|
||||||
if new_roll_window(ctx, new_roll_state, &mut self.state) {
|
if new_roll_window(ctx, new_roll_state, &mut self.state) {
|
||||||
self.new_roll_state = None;
|
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,
|
ctx: &egui::Context,
|
||||||
win_state: &mut ViewRollState,
|
win_state: &mut RollViewState,
|
||||||
app_state: &mut AppState,
|
app_state: &mut AppState,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let mut open = true;
|
let mut open = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user