mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 14:20:04 -04:00
Fix release build
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
// TODO(emilk): have separate types `PositionId` and `UniqueId`. ?
|
// TODO(emilk): have separate types `PositionId` and `UniqueId`. ?
|
||||||
|
|
||||||
use crate::CollapsingHeader;
|
|
||||||
use crate::id::id_source::IdSource;
|
|
||||||
use epaint::Color32;
|
use epaint::Color32;
|
||||||
use std::num::NonZeroU64;
|
use std::num::NonZeroU64;
|
||||||
|
|
||||||
@@ -39,6 +37,7 @@ pub struct Id(NonZeroU64);
|
|||||||
impl nohash_hasher::IsEnabled for Id {}
|
impl nohash_hasher::IsEnabled for Id {}
|
||||||
|
|
||||||
pub trait AsId: std::hash::Hash + std::fmt::Debug {}
|
pub trait AsId: std::hash::Hash + std::fmt::Debug {}
|
||||||
|
|
||||||
impl<T: std::hash::Hash + std::fmt::Debug> AsId for T {}
|
impl<T: std::hash::Hash + std::fmt::Debug> AsId for T {}
|
||||||
|
|
||||||
impl Id {
|
impl Id {
|
||||||
@@ -118,37 +117,6 @@ impl Id {
|
|||||||
Self(NonZeroU64::new(value).expect("Id must be non-zero."))
|
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) {
|
pub fn try_highlight(self, ctx: &crate::Context) {
|
||||||
let response = ctx.read_response(self);
|
let response = ctx.read_response(self);
|
||||||
if let Some(response) = response {
|
if let Some(response) = response {
|
||||||
@@ -166,13 +134,16 @@ impl Id {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn ui(self, ui: &mut crate::Ui) -> crate::Response {
|
pub fn ui(self, ui: &mut crate::Ui) -> crate::Response {
|
||||||
let data = self.info();
|
#[cfg(debug_assertions)]
|
||||||
let label = if let Some(data) = &data {
|
let debug_label = self
|
||||||
format!("{} ({})", self.short_debug_format(), data.source)
|
.info()
|
||||||
} else {
|
.map(|info| format!("{} ({})", self.short_debug_format(), info.source));
|
||||||
self.short_debug_format()
|
#[cfg(not(debug_assertions))]
|
||||||
};
|
let debug_label: Option<String> = None;
|
||||||
let response = ui.code(label).on_hover_ui(|ui| {
|
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);
|
Self::tree_ui(ui, self, "", 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -186,7 +157,7 @@ impl Id {
|
|||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
mod id_source {
|
mod id_source {
|
||||||
use crate::{AsId, Id};
|
use crate::{AsId, CollapsingHeader, Id};
|
||||||
use ahash::HashMap;
|
use ahash::HashMap;
|
||||||
use epaint::mutex::RwLock;
|
use epaint::mutex::RwLock;
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
@@ -197,6 +168,7 @@ mod id_source {
|
|||||||
pub struct IdInfo {
|
pub struct IdInfo {
|
||||||
/// What was this Id generated from?
|
/// What was this Id generated from?
|
||||||
pub source: IdSource,
|
pub source: IdSource,
|
||||||
|
|
||||||
/// If the Id was crated via [`Id::with`], what was the parent Id?
|
/// If the Id was crated via [`Id::with`], what was the parent Id?
|
||||||
pub parent: Option<Id>,
|
pub parent: Option<Id>,
|
||||||
}
|
}
|
||||||
@@ -303,9 +275,43 @@ mod id_source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Id {
|
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> {
|
pub fn info(&self) -> Option<IdInfo> {
|
||||||
ID_MAP.read().get(self).cloned()
|
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]
|
#[test]
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#![expect(rustdoc::missing_crate_level_docs)] // it's an example
|
#![expect(rustdoc::missing_crate_level_docs)] // it's an example
|
||||||
|
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use eframe::egui::{Id, Ui};
|
|
||||||
|
|
||||||
fn main() -> eframe::Result {
|
fn main() -> eframe::Result {
|
||||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||||
@@ -29,18 +28,6 @@ fn main() -> eframe::Result {
|
|||||||
age += 1;
|
age += 1;
|
||||||
}
|
}
|
||||||
ui.label(format!("Hello '{name}', age {age}"));
|
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);
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user