Skip to content

Commit

Permalink
Extracted render_dialog_contents method. Dynamic title.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmackdev committed Aug 6, 2023
1 parent 0e5d445 commit d121e8d
Showing 1 changed file with 50 additions and 44 deletions.
94 changes: 50 additions & 44 deletions pubsubman_gui/src/exit_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,58 +33,64 @@ impl ExitState {
return;
}

Modal::new("exit_modal", "Confirm Quit").show(ctx, |ui| {
match self.subscription_cleanup_state {
SubscriptionCleanupState::Idle => {
egui::Frame::none().inner_margin(MARGIN).show(ui, |ui| {
ui.allocate_ui_with_layout(
egui::vec2(350.0, 150.0),
egui::Layout::top_down(egui::Align::Center),
|ui| {
ui.label(
"Pubsubman created Subscriptions in order to receive messages. Do you want to delete these Subscriptions before you quit?",
);
let title = if self.subscription_cleanup_state == SubscriptionCleanupState::Waiting {
"Deleting Subscriptions..."
} else {
"Confirm Quit"
};

ui.add_space(20.0);
Modal::new("exit_modal", title).show(ctx, |ui| {
egui::Frame::none().inner_margin(MARGIN).show(ui, |ui| {
ui.allocate_ui_with_layout(
egui::vec2(350.0, 150.0),
egui::Layout::top_down(egui::Align::Center),
|ui| match self.subscription_cleanup_state {
SubscriptionCleanupState::Idle => {
self.render_dialog_contents(ui, cleanup_subscriptions, frame);
}
SubscriptionCleanupState::Waiting => {
ui.spinner();
}
SubscriptionCleanupState::Complete => {
self.can_exit = true;
frame.close();
}
},
)
});
});
}

ui.horizontal(|ui| {
ui.with_layout(
egui::Layout::left_to_right(egui::Align::Center),
|ui| {
if ui.button("Delete Subscriptions").clicked() {
cleanup_subscriptions();
self.subscription_cleanup_state =
SubscriptionCleanupState::Waiting;
}
fn render_dialog_contents(
&mut self,
ui: &mut egui::Ui,
cleanup_subscriptions: impl FnOnce(),
frame: &mut eframe::Frame,
) {
ui.label(
"Pubsubman created Subscriptions in order to receive messages. Do you want to delete these Subscriptions before you quit?",
);

if ui.button("Skip").clicked() {
self.can_exit = true;
frame.close();
}
ui.add_space(20.0);

ui.with_layout(
egui::Layout::right_to_left(egui::Align::Center),
|ui| {
if ui.button("Cancel").clicked() {
self.show_exit_dialogue = false;
}
},
);
},
);
});
},
);
});
}
SubscriptionCleanupState::Waiting => {
ui.label("Deleting Subscriptions...");
ui.horizontal(|ui| {
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
if ui.button("Delete Subscriptions").clicked() {
cleanup_subscriptions();
self.subscription_cleanup_state = SubscriptionCleanupState::Waiting;
}
SubscriptionCleanupState::Complete => {

if ui.button("Skip").clicked() {
self.can_exit = true;
frame.close();
}
}

ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui.button("Cancel").clicked() {
self.show_exit_dialogue = false;
}
});
});
});
}

Expand Down

0 comments on commit d121e8d

Please sign in to comment.