diff --git a/CHANGELOG.md b/CHANGELOG.md index 4517efe9..a5f3d5a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md) and [ * Add support for [cint](https://crates.io/crates/cint) under `cint` feature. * Add features `extra_asserts` and `extra_debug_asserts` to enable additional checks. * `TextEdit` now supports edits on a generic buffer using `TextBuffer`. +* Add `Context::set_debug_on_hover` and `egui::trace!(ui)` ### Changed 🔧 * Plot: Changed `Curve` to `Line`. diff --git a/egui/src/context.rs b/egui/src/context.rs index 00b5b6e6..438f1e3a 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -726,6 +726,20 @@ impl Context { false } } + + // --------------------------------------------------------------------- + + /// Wether or not to debug widget layout on hover. + pub fn debug_on_hover(&self) -> bool { + self.memory().options.style.debug.debug_on_hover + } + + /// Turn on/off wether or not to debug widget layout on hover. + pub fn set_debug_on_hover(&self, debug_on_hover: bool) { + let mut style = (*self.memory().options.style).clone(); + style.debug.debug_on_hover = debug_on_hover; + self.set_style(style); + } } /// ## Animation @@ -780,12 +794,14 @@ impl Context { .show(ui, |ui| { let mut tessellation_options = self.memory().options.tessellation_options; tessellation_options.ui(ui); + ui.vertical_centered(|ui| reset_button(ui, &mut tessellation_options)); self.memory().options.tessellation_options = tessellation_options; }); } pub fn inspection_ui(&self, ui: &mut Ui) { use crate::containers::*; + crate::trace!(ui); ui.label(format!("Is using pointer: {}", self.is_using_pointer())) .on_hover_text( diff --git a/egui/src/layout.rs b/egui/src/layout.rs index c1508a29..5d263300 100644 --- a/egui/src/layout.rs +++ b/egui/src/layout.rs @@ -731,14 +731,13 @@ impl Layout { /// ## Debug stuff impl Layout { /// Shows where the next widget is going to be placed - pub(crate) fn debug_paint_cursor( + pub(crate) fn paint_text_at_cursor( &self, + painter: &crate::Painter, region: &Region, stroke: epaint::Stroke, - painter: &crate::Painter, + text: impl ToString, ) { - use epaint::*; - let cursor = region.cursor; let next_pos = self.next_widget_position(region); @@ -769,12 +768,6 @@ impl Layout { } } - painter.text( - next_pos, - align, - "cursor", - TextStyle::Monospace, - Color32::WHITE, - ); + painter.debug_text(next_pos, align, stroke.color, text); } } diff --git a/egui/src/lib.rs b/egui/src/lib.rs index 3df09074..7884a890 100644 --- a/egui/src/lib.rs +++ b/egui/src/lib.rs @@ -416,6 +416,31 @@ macro_rules! github_link_file { // ---------------------------------------------------------------------------- +/// Show debug info on hover when [`Context::set_debug_on_hover`] has been turned on. +/// +/// ``` +/// # let ui = &mut egui::Ui::__test(); +/// // Turn on tracing of widgets +/// ui.ctx().set_debug_on_hover(true); +/// +/// /// Show [`std::file`], [`std::line`] and argument on hover +/// egui::trace!(ui, "MyWindow"); +/// +/// /// Show [`std::file`] and [`std::line`] on hover +/// egui::trace!(ui); +/// ``` +#[macro_export] +macro_rules! trace { + ($ui:expr) => {{ + $ui.trace_location(format!("{}:{}", file!(), line!())) + }}; + ($ui:expr, $label:expr) => {{ + $ui.trace_location(format!("{} - {}:{}", $label, file!(), line!())) + }}; +} + +// ---------------------------------------------------------------------------- + /// An assert that is only active when `egui` is compiled with the `egui_assert` feature /// or with the `debug_egui_assert` feature in debug builds. #[macro_export] diff --git a/egui/src/memory.rs b/egui/src/memory.rs index 0a082738..d9cb1535 100644 --- a/egui/src/memory.rs +++ b/egui/src/memory.rs @@ -83,6 +83,7 @@ pub struct Options { /// The default style for new `Ui`:s. #[cfg_attr(feature = "persistence", serde(skip))] pub(crate) style: std::sync::Arc