1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

Fix release build

This commit is contained in:
lucasmerlin
2026-03-19 13:01:33 +01:00
parent 3ac34b3efb
commit ac3564a2ee
2 changed files with 47 additions and 54 deletions

View File

@@ -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<T: std::hash::Hash + std::fmt::Debug> 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<String> = 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<Id>,
}
@@ -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<IdInfo> {
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]

View File

@@ -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);
});
})
}