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

Use a lot more let-else (#7582)

This commit is contained in:
Emil Ernerfeldt
2025-10-02 19:47:00 +02:00
committed by GitHub
parent 4c1f344ef8
commit bd45406fad
45 changed files with 812 additions and 847 deletions

View File

@@ -161,12 +161,12 @@ impl ImageLoader for ImageCrateLoader {
match ctx.try_load_bytes(uri) {
Ok(BytesPoll::Ready { bytes, mime, .. }) => {
// (2)
if let Some(mime) = mime {
if !is_supported_mime(&mime) {
return Err(LoadError::FormatNotSupported {
detected_format: Some(mime),
});
}
if let Some(mime) = mime
&& !is_supported_mime(&mime)
{
return Err(LoadError::FormatNotSupported {
detected_format: Some(mime),
});
}
load_image(ctx, uri, &self.cache, &bytes)
}

View File

@@ -144,11 +144,11 @@ impl Sizing {
let mut remainder_length = length - sum_non_remainder;
let avg_remainder_length = 0.0f32.max(remainder_length / num_remainders as f32).floor();
for &size in &self.sizes {
if let Size::Remainder { range } = size {
if avg_remainder_length < range.min {
remainder_length -= range.min;
num_remainders -= 1;
}
if let Size::Remainder { range } = size
&& avg_remainder_length < range.min
{
remainder_length -= range.min;
num_remainders -= 1;
}
}
if num_remainders > 0 {

View File

@@ -472,10 +472,10 @@ impl<'a> TableBuilder<'a> {
for (i, column) in columns.iter_mut().enumerate() {
let column_resize_id = ui.id().with("resize_column").with(i);
if let Some(response) = ui.ctx().read_response(column_resize_id) {
if response.double_clicked() {
column.auto_size_this_frame = true;
}
if let Some(response) = ui.ctx().read_response(column_resize_id)
&& response.double_clicked()
{
column.auto_size_this_frame = true;
}
}
@@ -864,27 +864,27 @@ impl Table<'_> {
if column.auto_size_this_frame {
// Auto-size: resize to what is needed.
*column_width = width_range.clamp(max_used_widths[i]);
} else if resize_response.dragged() {
if let Some(pointer) = ui.ctx().pointer_latest_pos() {
let mut new_width = *column_width + pointer.x - x;
if !column.clip {
// Unless we clip we don't want to shrink below the
// size that was actually used.
// However, we still want to allow content that shrinks when you try
// to make the column less wide, so we allow some small shrinkage each frame:
// big enough to allow shrinking over time, small enough not to look ugly when
// shrinking fails. This is a bit of a HACK around immediate mode.
let max_shrinkage_per_frame = 8.0;
new_width =
new_width.at_least(max_used_widths[i] - max_shrinkage_per_frame);
}
new_width = width_range.clamp(new_width);
let x = x - *column_width + new_width;
(p0.x, p1.x) = (x, x);
*column_width = new_width;
} else if resize_response.dragged()
&& let Some(pointer) = ui.ctx().pointer_latest_pos()
{
let mut new_width = *column_width + pointer.x - x;
if !column.clip {
// Unless we clip we don't want to shrink below the
// size that was actually used.
// However, we still want to allow content that shrinks when you try
// to make the column less wide, so we allow some small shrinkage each frame:
// big enough to allow shrinking over time, small enough not to look ugly when
// shrinking fails. This is a bit of a HACK around immediate mode.
let max_shrinkage_per_frame = 8.0;
new_width =
new_width.at_least(max_used_widths[i] - max_shrinkage_per_frame);
}
new_width = width_range.clamp(new_width);
let x = x - *column_width + new_width;
(p0.x, p1.x) = (x, x);
*column_width = new_width;
}
let dragging_something_else =
@@ -991,7 +991,7 @@ impl<'a> TableBody<'a> {
row_index: self.row_index,
col_index: 0,
height,
striped: self.striped && self.row_index % 2 == 0,
striped: self.striped && self.row_index.is_multiple_of(2),
hovered: self.hovered_row_index == Some(self.row_index),
selected: false,
overline: false,
@@ -1073,7 +1073,7 @@ impl<'a> TableBody<'a> {
row_index,
col_index: 0,
height: row_height_sans_spacing,
striped: self.striped && (row_index + self.row_index) % 2 == 0,
striped: self.striped && (row_index + self.row_index).is_multiple_of(2),
hovered: self.hovered_row_index == Some(row_index),
selected: false,
overline: false,
@@ -1155,7 +1155,7 @@ impl<'a> TableBody<'a> {
row_index,
col_index: 0,
height: row_height,
striped: self.striped && (row_index + self.row_index) % 2 == 0,
striped: self.striped && (row_index + self.row_index).is_multiple_of(2),
hovered: self.hovered_row_index == Some(row_index),
selected: false,
overline: false,
@@ -1178,7 +1178,7 @@ impl<'a> TableBody<'a> {
row_index,
col_index: 0,
height: row_height,
striped: self.striped && (row_index + self.row_index) % 2 == 0,
striped: self.striped && (row_index + self.row_index).is_multiple_of(2),
hovered: self.hovered_row_index == Some(row_index),
overline: false,
selected: false,