Skip to content

Commit

Permalink
Update Egui to 0.28 (#223)
Browse files Browse the repository at this point in the history
### Checklist

* [x] I have read the [Contributor Guide](../CONTRIBUTING.md)
* [x] I have read and agree to the [Code of
Conduct](../CODE_OF_CONDUCT.md)
* [x] I have added a description of my changes and why I'd like them
included in the section below

### Description of Changes

I have done my best to update to egui 0.28. The only thing I am unsure
about is the ParentId of the tooltips, but I have guestimated as best I
can.
  • Loading branch information
cwfitzgerald committed Jul 16, 2024
1 parent 88c8d16 commit b08bac5
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 141 deletions.
295 changes: 175 additions & 120 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions puffin_egui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "puffin_egui"
version = "0.27.1"
version = "0.28.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
description = "Show puffin profiler flamegraph in-game using egui"
edition = "2018"
Expand All @@ -21,7 +21,7 @@ include = [
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
egui = { version = "0.27.1", default-features = false }
egui = { version = "0.28.0", default-features = false }
indexmap = { version = "2.1.0", features = ["serde"] }
natord = "1.0.9"
once_cell = "1.7"
Expand All @@ -36,7 +36,7 @@ vec1 = "1.8"
web-time = "0.2"

[dev-dependencies]
eframe = { version = "0.27.1", default-features = false, features = [
eframe = { version = "0.28.0", default-features = false, features = [
"default_fonts",
"glow",
] }
Expand Down
2 changes: 1 addition & 1 deletion puffin_egui/examples/eframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() -> eframe::Result<()> {
eframe::run_native(
"puffin egui eframe",
native_options,
Box::new(|_cc| Box::<ExampleApp>::default()),
Box::new(|_cc| Ok(Box::<ExampleApp>::default())),
)
}

Expand Down
37 changes: 25 additions & 12 deletions puffin_egui/src/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ struct Info<'a> {
stop_ns: NanoSecond,
/// How many frames we are viewing
num_frames: usize,
/// LayerId to use as parent for tooltips
layer_id: LayerId,

font_id: FontId,

Expand Down Expand Up @@ -296,6 +298,7 @@ pub fn ui(
start_ns: min_ns,
stop_ns: max_ns,
num_frames: frames.frames.len(),
layer_id: ui.layer_id(),
font_id: TextStyle::Body.resolve(ui.style()),
scope_collection,
};
Expand Down Expand Up @@ -761,15 +764,20 @@ fn paint_scope(
let Some(scope_details) = info.scope_collection.fetch_by_id(&scope.id) else {
return Ok(PaintResult::Culled);
};
egui::show_tooltip_at_pointer(&info.ctx, Id::new("puffin_profiler_tooltip"), |ui| {
paint_scope_details(ui, scope.id, scope.record.data, scope_details);
add_space(ui);
ui.monospace(format!(
"duration: {:7.3} ms",
to_ms(scope.record.duration_ns)
));
ui.monospace(format!("children: {num_children:3}"));
});
egui::show_tooltip_at_pointer(
&info.ctx,
info.layer_id,
Id::new("puffin_profiler_tooltip"),
|ui| {
paint_scope_details(ui, scope.id, scope.record.data, scope_details);
add_space(ui);
ui.monospace(format!(
"duration: {:7.3} ms",
to_ms(scope.record.duration_ns)
));
ui.monospace(format!("children: {num_children:3}"));
},
);
}
}

Expand Down Expand Up @@ -821,9 +829,14 @@ fn paint_merge_scope(
}

if result == PaintResult::Hovered {
egui::show_tooltip_at_pointer(&info.ctx, Id::new("puffin_profiler_tooltip"), |ui| {
merge_scope_tooltip(ui, info.scope_collection, merge, info.num_frames);
});
egui::show_tooltip_at_pointer(
&info.ctx,
info.layer_id,
Id::new("puffin_profiler_tooltip"),
|ui| {
merge_scope_tooltip(ui, info.scope_collection, merge, info.num_frames);
},
);
}
}

Expand Down
3 changes: 2 additions & 1 deletion puffin_egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ impl ProfilerUi {
ui.end_row();

ui.vertical(|ui| {
ui.style_mut().wrap = Some(false);
ui.style_mut().wrap_mode = Some(TextWrapMode::Extend);
ui.add_space(16.0); // make it a bit more centered
ui.label("Slowest:");
if let Some(frame_view) = frame_view.as_mut() {
Expand Down Expand Up @@ -712,6 +712,7 @@ impl ProfilerUi {
*hovered_frame = Some(frame.clone());
egui::show_tooltip_at_pointer(
ui.ctx(),
ui.layer_id(),
Id::new("puffin_frame_tooltip"),
|ui| {
ui.label(format!("{:.1} ms", frame.duration_ns() as f64 * 1e-6));
Expand Down
4 changes: 2 additions & 2 deletions puffin_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ include = ["**/*.rs", "Cargo.toml", "README.md", "icon.png"]
crate-type = ["cdylib", "rlib"]

[dependencies]
puffin_egui = { version = "0.27.1", path = "../puffin_egui", features = [
puffin_egui = { version = "0.28.0", path = "../puffin_egui", features = [
"serde",
] }
puffin = { version = "0.19.0", path = "../puffin", features = [
Expand All @@ -28,7 +28,7 @@ puffin = { version = "0.19.0", path = "../puffin", features = [
puffin_http = { version = "0.16.0", path = "../puffin_http" }

argh = "0.1"
eframe = { version = "0.27.1", default-features = false, features = [
eframe = { version = "0.28.0", default-features = false, features = [
"default_fonts",
"glow",
"persistence",
Expand Down
2 changes: 1 addition & 1 deletion puffin_viewer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn main() -> Result<(), eframe::Error> {
eframe::run_native(
"puffin viewer",
native_options,
Box::new(|cc| Box::new(PuffinViewer::new(source, cc.storage))),
Box::new(|cc| Ok(Box::new(PuffinViewer::new(source, cc.storage)))),
)
}

Expand Down
7 changes: 6 additions & 1 deletion puffin_viewer/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ pub async fn start(canvas_id: &str) -> Result<(), eframe::wasm_bindgen::JsValue>
.start(
canvas_id,
web_options,
Box::new(|cc| Box::new(crate::PuffinViewer::new(crate::Source::None, cc.storage))),
Box::new(|cc| {
Ok(Box::new(crate::PuffinViewer::new(
crate::Source::None,
cc.storage,
)))
}),
)
.await?;

Expand Down

0 comments on commit b08bac5

Please sign in to comment.