Skip to content

Commit 844f69f

Browse files
committed
Reset UI when loading a .puffin file
1 parent c2cc799 commit 844f69f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

puffin_egui/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ fn latest_frames() -> Frames {
324324
}
325325

326326
impl ProfilerUi {
327+
pub fn reset(&mut self) {
328+
let options = self.options;
329+
*self = Self {
330+
options,
331+
..Default::default()
332+
};
333+
}
334+
327335
/// Show an [`egui::Window`] with the profiler contents.
328336
///
329337
/// If you want to control the window yourself, use [`Self::ui`] instead.

puffin_viewer/src/main.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ fn main() {
110110
Ok(profiler) => {
111111
*GlobalProfiler::lock() = profiler;
112112
PuffinViewer {
113+
profiler_ui: Default::default(),
113114
source: Source::File(path),
114115
error: None,
115116
}
@@ -121,6 +122,7 @@ fn main() {
121122
}
122123
} else {
123124
PuffinViewer {
125+
profiler_ui: Default::default(),
124126
source: Source::Http(puffin_http::Client::new(opt.url)),
125127
error: None,
126128
}
@@ -153,6 +155,7 @@ impl Source {
153155
}
154156

155157
pub struct PuffinViewer {
158+
profiler_ui: puffin_egui::ProfilerUi,
156159
source: Source,
157160
error: Option<String>,
158161
}
@@ -166,14 +169,15 @@ impl epi::App for PuffinViewer {
166169
egui::TopBottomPanel::top("menu_bar").show(ctx, |ui| {
167170
egui::menu::bar(ui, |ui| {
168171
egui::menu::menu(ui, "File", |ui| {
169-
if ui.button("Load…").clicked() {
172+
if ui.button("Open…").clicked() {
170173
if let Some(path) = rfd::FileDialog::new()
171174
.add_filter("puffin", &["puffin"])
172175
.pick_file()
173176
{
174177
match GlobalProfiler::load_path(&path) {
175178
Ok(profiler) => {
176179
*GlobalProfiler::lock() = profiler;
180+
self.profiler_ui.reset();
177181
self.source = Source::File(path);
178182
self.error = None;
179183
}
@@ -185,7 +189,7 @@ impl epi::App for PuffinViewer {
185189
}
186190
}
187191

188-
if ui.button("Save…").clicked() {
192+
if ui.button("Save as…").clicked() {
189193
if let Some(path) = rfd::FileDialog::new()
190194
.add_filter("puffin", &["puffin"])
191195
.save_file()
@@ -214,6 +218,8 @@ impl epi::App for PuffinViewer {
214218
self.source.ui(ui);
215219
});
216220

217-
egui::CentralPanel::default().show(ctx, puffin_egui::profiler_ui);
221+
egui::CentralPanel::default().show(ctx, |ui| {
222+
self.profiler_ui.ui(ui);
223+
});
218224
}
219225
}

0 commit comments

Comments
 (0)