From ac3564a2ee8ce59c5134c108f3314295ebc145c8 Mon Sep 17 00:00:00 2001 From: lucasmerlin Date: Thu, 19 Mar 2026 13:01:33 +0100 Subject: [PATCH] Fix release build --- crates/egui/src/id.rs | 88 +++++++++++++------------ examples/hello_world_simple/src/main.rs | 13 ---- 2 files changed, 47 insertions(+), 54 deletions(-) diff --git a/crates/egui/src/id.rs b/crates/egui/src/id.rs index 0d2f53cb0..a02052fba 100644 --- a/crates/egui/src/id.rs +++ b/crates/egui/src/id.rs @@ -1,7 +1,5 @@ // TODO(emilk): have separate types `PositionId` and `UniqueId`. ? -use crate::CollapsingHeader; -use crate::id::id_source::IdSource; use epaint::Color32; use std::num::NonZeroU64; @@ -39,6 +37,7 @@ pub struct Id(NonZeroU64); impl nohash_hasher::IsEnabled for Id {} pub trait AsId: std::hash::Hash + std::fmt::Debug {} + impl AsId for T {} impl Id { @@ -118,37 +117,6 @@ impl Id { Self(NonZeroU64::new(value).expect("Id must be non-zero.")) } - fn tree_ui(ui: &mut crate::Ui, id: Self, prefix: &str, depth: usize) { - let info = id.info(); - if let Some(info) = info { - let response = - CollapsingHeader::new(format!("{}Id({})", prefix, id.short_debug_format())) - .default_open(depth < 4) - .show(ui, |ui| { - match info.source { - IdSource::Id(id_source) => { - Self::tree_ui(ui, id_source, "Source: ", depth + 1); - } - IdSource::Other(other) => { - ui.horizontal(|ui| { - ui.add_space(ui.spacing().indent); - ui.label("Source:"); - ui.code(other); - }); - } - } - - if let Some(parent) = info.parent { - Self::tree_ui(ui, parent, "Parent: ", depth + 1); - } - }); - - if response.header_response.hovered() { - id.try_highlight(ui.ctx()); - } - } - } - pub fn try_highlight(self, ctx: &crate::Context) { let response = ctx.read_response(self); if let Some(response) = response { @@ -166,13 +134,16 @@ impl Id { } pub fn ui(self, ui: &mut crate::Ui) -> crate::Response { - let data = self.info(); - let label = if let Some(data) = &data { - format!("{} ({})", self.short_debug_format(), data.source) - } else { - self.short_debug_format() - }; - let response = ui.code(label).on_hover_ui(|ui| { + #[cfg(debug_assertions)] + let debug_label = self + .info() + .map(|info| format!("{} ({})", self.short_debug_format(), info.source)); + #[cfg(not(debug_assertions))] + let debug_label: Option = None; + let response = ui.code(debug_label.unwrap_or_else(|| self.short_debug_format())); + + #[cfg(debug_assertions)] + let response = response.on_hover_ui(|ui| { Self::tree_ui(ui, self, "", 0); }); @@ -186,7 +157,7 @@ impl Id { #[cfg(debug_assertions)] mod id_source { - use crate::{AsId, Id}; + use crate::{AsId, CollapsingHeader, Id}; use ahash::HashMap; use epaint::mutex::RwLock; use std::fmt::{Display, Formatter}; @@ -197,6 +168,7 @@ mod id_source { pub struct IdInfo { /// What was this Id generated from? pub source: IdSource, + /// If the Id was crated via [`Id::with`], what was the parent Id? pub parent: Option, } @@ -303,9 +275,43 @@ mod id_source { } impl Id { + /// Get info about this id (what source was it generated from, what parent does it have)? + /// + /// Only available with `#[cfg(debug_assertions)]`. pub fn info(&self) -> Option { ID_MAP.read().get(self).cloned() } + + pub(super) fn tree_ui(ui: &mut crate::Ui, id: Self, prefix: &str, depth: usize) { + let info = id.info(); + if let Some(info) = info { + let response = + CollapsingHeader::new(format!("{}Id({})", prefix, id.short_debug_format())) + .default_open(depth < 4) + .show(ui, |ui| { + match info.source { + IdSource::Id(id_source) => { + Self::tree_ui(ui, id_source, "Source: ", depth + 1); + } + IdSource::Other(other) => { + ui.horizontal(|ui| { + ui.add_space(ui.spacing().indent); + ui.label("Source:"); + ui.code(other); + }); + } + } + + if let Some(parent) = info.parent { + Self::tree_ui(ui, parent, "Parent: ", depth + 1); + } + }); + + if response.header_response.hovered() { + id.try_highlight(ui.ctx()); + } + } + } } #[test] diff --git a/examples/hello_world_simple/src/main.rs b/examples/hello_world_simple/src/main.rs index 959c67484..cbdfcf1f1 100644 --- a/examples/hello_world_simple/src/main.rs +++ b/examples/hello_world_simple/src/main.rs @@ -2,7 +2,6 @@ #![expect(rustdoc::missing_crate_level_docs)] // it's an example use eframe::egui; -use eframe::egui::{Id, Ui}; fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). @@ -29,18 +28,6 @@ fn main() -> eframe::Result { age += 1; } ui.label(format!("Hello '{name}', age {age}")); - - Id::new(Id::new("Hi").with((123, "456"))) - .with(Id::new("lol")) - .ui(ui); - - ui.id().ui(ui); - Id::ui(Ui::id(ui), ui); - - ui.unique_id().ui(ui); - - let some_button = ui.button("Some button"); - some_button.id.ui(ui); }); }) }