1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

Add assert messages and print bad argument values in asserts (#5216)

Enabled the `missing_assert_message` lint

* [x] I have followed the instructions in the PR template

---------

Co-authored-by: Lucas Meurer <lucasmeurer96@gmail.com>
This commit is contained in:
Nicolas
2025-03-25 09:20:29 +01:00
committed by GitHub
parent 903bd81313
commit 58b2ac88c0
35 changed files with 331 additions and 108 deletions

View File

@@ -91,8 +91,14 @@ impl FontImpl {
scale_in_pixels: f32,
tweak: FontTweak,
) -> Self {
assert!(scale_in_pixels > 0.0);
assert!(pixels_per_point > 0.0);
assert!(
scale_in_pixels > 0.0,
"scale_in_pixels is smaller than 0, got: {scale_in_pixels:?}"
);
assert!(
pixels_per_point > 0.0,
"pixels_per_point must be greater than 0, got: {pixels_per_point:?}"
);
use ab_glyph::{Font, ScaleFont};
let scaled = ab_glyph_font.as_scaled(scale_in_pixels);
@@ -264,7 +270,7 @@ impl FontImpl {
}
fn allocate_glyph(&self, glyph_id: ab_glyph::GlyphId) -> GlyphInfo {
assert!(glyph_id.0 != 0);
assert!(glyph_id.0 != 0, "Can't allocate glyph for id 0");
use ab_glyph::{Font as _, ScaleFont};
let glyph = glyph_id.with_scale_and_position(

View File

@@ -529,7 +529,7 @@ fn halign_and_justify_row(
(num_leading_spaces, row.glyphs.len() - num_trailing_spaces)
};
let num_glyphs_in_range = glyph_range.1 - glyph_range.0;
assert!(num_glyphs_in_range > 0);
assert!(num_glyphs_in_range > 0, "Should have at least one glyph");
let original_min_x = row.glyphs[glyph_range.0].logical_rect().min.x;
let original_max_x = row.glyphs[glyph_range.1 - 1].logical_rect().max.x;
@@ -898,7 +898,10 @@ fn add_hline(point_scale: PointScale, [start, stop]: [Pos2; 2], stroke: Stroke,
} else {
// Thin lines often lost, so this is a bad idea
assert_eq!(start.y, stop.y);
assert_eq!(
start.y, stop.y,
"Horizontal line must be horizontal, but got: {start:?} -> {stop:?}"
);
let min_y = point_scale.round_to_pixel(start.y - 0.5 * stroke.width);
let max_y = point_scale.round_to_pixel(min_y + stroke.width);

View File

@@ -892,7 +892,7 @@ impl Galley {
}
ccursor_it.index += row.char_count_including_newline();
}
debug_assert!(ccursor_it == self.end());
debug_assert!(ccursor_it == self.end(), "Cursor out of bounds");
if let Some(last_row) = self.rows.last() {
LayoutCursor {