1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-03 07:10:04 -04:00
This commit is contained in:
lucasmerlin
2026-03-19 12:42:43 +01:00
parent 70435084a9
commit 3ac34b3efb
3 changed files with 18 additions and 83 deletions

View File

@@ -16,11 +16,11 @@ use epaint::{
use crate::{ use crate::{
Align2, CursorIcon, DeferredViewportUiCallback, FontDefinitions, Grid, Id, ImmediateViewport, Align2, CursorIcon, DeferredViewportUiCallback, FontDefinitions, Grid, Id, ImmediateViewport,
ImmediateViewportRendererCallback, Key, KeyboardShortcut, Label, LayerId, Memory, ImmediateViewportRendererCallback, Key, KeyboardShortcut, LayerId, Memory, ModifierNames,
ModifierNames, Modifiers, NumExt as _, Order, Painter, RawInput, Response, RichText, Modifiers, NumExt as _, Order, Painter, RawInput, Response, SafeAreaInsets, ScrollArea, Sense,
SafeAreaInsets, ScrollArea, Sense, Style, TextStyle, TextureHandle, TextureOptions, Ui, Style, TextStyle, TextureHandle, TextureOptions, Ui, UiBuilder, ViewportBuilder,
UiBuilder, ViewportBuilder, ViewportCommand, ViewportId, ViewportIdMap, ViewportIdPair, ViewportCommand, ViewportId, ViewportIdMap, ViewportIdPair, ViewportIdSet, ViewportOutput,
ViewportIdSet, ViewportOutput, Visuals, Widget as _, WidgetRect, WidgetText, Visuals, Widget as _, WidgetRect, WidgetText,
animation_manager::AnimationManager, animation_manager::AnimationManager,
containers::{self, area::AreaState}, containers::{self, area::AreaState},
data::output::PlatformOutput, data::output::PlatformOutput,

View File

@@ -1,7 +1,7 @@
// TODO(emilk): have separate types `PositionId` and `UniqueId`. ? // TODO(emilk): have separate types `PositionId` and `UniqueId`. ?
use crate::id::id_source::IdSource;
use crate::CollapsingHeader; use crate::CollapsingHeader;
use crate::id::id_source::IdSource;
use epaint::Color32; use epaint::Color32;
use std::num::NonZeroU64; use std::num::NonZeroU64;
@@ -73,7 +73,7 @@ impl Id {
use std::hash::{BuildHasher as _, Hasher as _}; use std::hash::{BuildHasher as _, Hasher as _};
let mut hasher = ahash::RandomState::with_seeds(1, 2, 3, 4).build_hasher(); let mut hasher = ahash::RandomState::with_seeds(1, 2, 3, 4).build_hasher();
hasher.write_u64(self.0.get()); hasher.write_u64(self.0.get());
(&child).hash(&mut hasher); child.hash(&mut hasher);
let id = Self::from_hash(hasher.finish()); let id = Self::from_hash(hasher.finish());
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
@@ -118,70 +118,7 @@ impl Id {
Self(NonZeroU64::new(value).expect("Id must be non-zero.")) Self(NonZeroU64::new(value).expect("Id must be non-zero."))
} }
fn source_ui(ui: &mut crate::Ui, source: IdSource) { fn tree_ui(ui: &mut crate::Ui, id: Self, prefix: &str, depth: usize) {
match source {
IdSource::Id(id) => {
Self::parent_ui(ui, id);
}
IdSource::Other(other) => {
ui.code(other);
}
}
}
fn parent_ui(ui: &mut crate::Ui, id: Id) {
let data = id.info();
if let Some(data) = data {
if let Some(parent) = data.parent {
Self::parent_ui(ui, parent);
ui.horizontal(|ui| {
ui.code(".with(");
Self::source_ui(ui, data.source);
ui.code(format!(" /* {} */", id.short_debug_format()));
ui.code(")");
});
} else {
ui.horizontal(|ui| {
ui.code("Id::new(");
Self::source_ui(ui, data.source);
ui.code(format!(" /* {} */", id.short_debug_format()));
ui.code(")");
});
}
} else {
ui.code(format!("Id::from_hash({})", id.short_debug_format()));
}
}
fn group_ui(ui: &mut crate::Ui, id: Id) {
ui.group(|ui| {
let info = id.info();
if let Some(info) = info {
ui.horizontal(|ui| {
ui.label("Id(");
ui.code(format!("{:04X}", id.value() as u16));
ui.label(")");
ui.label("Source:");
match info.source {
IdSource::Id(id) => {
Self::group_ui(ui, id);
}
IdSource::Other(other) => {
ui.code(other);
}
}
});
if let Some(parent) = info.parent {
ui.label("^ with");
Self::group_ui(ui, parent);
}
} else {
}
});
}
fn tree_ui(ui: &mut crate::Ui, id: Id, prefix: &str, depth: usize) {
let info = id.info(); let info = id.info();
if let Some(info) = info { if let Some(info) = info {
let response = let response =
@@ -273,11 +210,11 @@ mod id_source {
impl Display for IdSource { impl Display for IdSource {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self { match self {
IdSource::Id(id) => { Self::Id(id) => {
write!(f, "{}", id.short_debug_format()) write!(f, "{}", id.short_debug_format())
} }
IdSource::Other(other) => { Self::Other(other) => {
write!(f, "{}", other) write!(f, "{other}")
} }
} }
} }
@@ -319,7 +256,7 @@ mod id_source {
} }
fn write_u64(&mut self, i: u64) { fn write_u64(&mut self, i: u64) {
if !self.not_id && !self.val.is_some() { if !self.not_id && self.val.is_none() {
self.val = Some(i); self.val = Some(i);
} else { } else {
self.not_id = true; self.not_id = true;
@@ -345,10 +282,10 @@ mod id_source {
if ID_MAP.read().contains_key(&maybe_source_id) { if ID_MAP.read().contains_key(&maybe_source_id) {
IdSource::Id(maybe_source_id) IdSource::Id(maybe_source_id)
} else { } else {
IdSource::Other(format!("{:?}", t)) IdSource::Other(format!("{t:?}"))
} }
} else { } else {
IdSource::Other(format!("{:?}", t)) IdSource::Other(format!("{t:?}"))
} }
} }
@@ -373,7 +310,7 @@ mod id_source {
#[test] #[test]
fn test_fake_hasher() { fn test_fake_hasher() {
use std::hash::Hash; use std::hash::Hash as _;
let mut hasher = ExtractIdHasher::default(); let mut hasher = ExtractIdHasher::default();
let id = Id::new("test"); let id = Id::new("test");
@@ -391,15 +328,15 @@ impl std::fmt::Debug for Id {
if let Some(info) = self.info() { if let Some(info) = self.info() {
match info.source { match info.source {
id_source::IdSource::Id(source_id) => { id_source::IdSource::Id(source_id) => {
write!(f, "({:?})", source_id)?; write!(f, "({source_id:?})")?;
} }
id_source::IdSource::Other(label) => { id_source::IdSource::Other(label) => {
write!(f, " ({})", label)?; write!(f, " ({label})")?;
} }
} }
if let Some(parent) = info.parent { if let Some(parent) = info.parent {
// Let's hope there are no cycles! // Let's hope there are no cycles!
write!(f, " <- {:?}", parent)?; write!(f, " <- {parent:?}")?;
} }
} }

View File

@@ -7,8 +7,6 @@ use emath::GuiRounding as _;
use epaint::mutex::RwLock; use epaint::mutex::RwLock;
use crate::containers::menu; use crate::containers::menu;
#[cfg(debug_assertions)]
use crate::Stroke;
use crate::{containers::*, ecolor::*, layout::*, placer::Placer, widgets::*, *}; use crate::{containers::*, ecolor::*, layout::*, placer::Placer, widgets::*, *};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------