Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DebugOptions::show_unaligned #5165

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/ecolor/src/color32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl Color32 {
pub const LIGHT_RED: Self = Self::from_rgb(255, 128, 128);

pub const YELLOW: Self = Self::from_rgb(255, 255, 0);
pub const ORANGE: Self = Self::from_rgb(255, 165, 0);
pub const LIGHT_YELLOW: Self = Self::from_rgb(255, 255, 0xE0);
pub const KHAKI: Self = Self::from_rgb(240, 230, 140);

Expand Down
14 changes: 14 additions & 0 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,13 @@ pub struct DebugOptions {

/// Show interesting widgets under the mouse cursor.
pub show_widget_hits: bool,

/// If true, highlight widgets that are not aligned to integer point coordinates.
///
/// It's usually a good idea to keep to integer coordinates to avoid rounding issues.
///
/// See <https://github.com/emilk/egui/issues/5163> for more.
pub show_unaligned: bool,
}

#[cfg(debug_assertions)]
Expand All @@ -1181,6 +1188,7 @@ impl Default for DebugOptions {
show_resize: false,
show_interactive_widgets: false,
show_widget_hits: false,
show_unaligned: false,
}
}
}
Expand Down Expand Up @@ -2190,6 +2198,7 @@ impl DebugOptions {
show_resize,
show_interactive_widgets,
show_widget_hits,
show_unaligned,
} = self;

{
Expand Down Expand Up @@ -2219,6 +2228,11 @@ impl DebugOptions {

ui.checkbox(show_widget_hits, "Show widgets under mouse pointer");

ui.checkbox(
show_unaligned,
"Show rectangles not aligned to integer point coordinates",
);

ui.vertical_centered(|ui| reset_button(ui, self, "Reset debug options"));
}
}
Expand Down
25 changes: 25 additions & 0 deletions crates/egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2962,8 +2962,33 @@ impl Drop for Ui {
/// Show this rectangle to the user if certain debug options are set.
#[cfg(debug_assertions)]
fn register_rect(ui: &Ui, rect: Rect) {
use emath::Align2;

let debug = ui.style().debug;

if debug.show_unaligned {
let unaligned_line = |p0: Pos2, p1: Pos2| {
let color = Color32::ORANGE;
let font_id = TextStyle::Monospace.resolve(ui.style());
ui.painter().line_segment([p0, p1], (1.0, color));
ui.painter()
.text(p0, Align2::LEFT_TOP, "Unaligned", font_id, color);
};

if rect.left().fract() != 0.0 {
unaligned_line(rect.left_top(), rect.left_bottom());
}
if rect.right().fract() != 0.0 {
unaligned_line(rect.right_top(), rect.right_bottom());
}
if rect.top().fract() != 0.0 {
unaligned_line(rect.left_top(), rect.right_top());
}
if rect.bottom().fract() != 0.0 {
unaligned_line(rect.left_bottom(), rect.right_bottom());
}
}

let show_callstacks = debug.debug_on_hover
|| debug.debug_on_hover_with_all_modifiers && ui.input(|i| i.modifiers.all());

Expand Down
Loading