mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
Use a lot more let-else (#7582)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user