1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -04:00

Flip if-else:s with a negation (#8063)

This commit is contained in:
Emil Ernerfeldt
2026-04-04 12:03:41 +02:00
committed by GitHub
parent eb35f7d12f
commit c2b482ff7e
9 changed files with 44 additions and 44 deletions

View File

@@ -272,10 +272,10 @@ impl Response {
false
} else if let Some(pos) = pointer_interact_pos {
let layer_under_pointer = self.ctx.layer_id_at(pos);
if layer_under_pointer != Some(self.layer_id) {
true
} else {
if layer_under_pointer == Some(self.layer_id) {
!self.interact_rect.contains(pos)
} else {
true
}
} else {
false // clicked without a pointer, weird

View File

@@ -156,13 +156,13 @@ fn select_line_at(text: &str, ccursor: CCursor) -> CCursorRange {
let min = ccursor_previous_line(text, ccursor);
let max = ccursor_next_line(text, min);
CCursorRange::two(min, max)
} else if !is_linebreak(char_after_cursor) {
let max = ccursor_next_line(text, ccursor);
CCursorRange::two(ccursor, max)
} else {
} else if is_linebreak(char_after_cursor) {
let min = ccursor_previous_line(text, ccursor);
let max = ccursor_next_line(text, ccursor);
CCursorRange::two(min, max)
} else {
let max = ccursor_next_line(text, ccursor);
CCursorRange::two(ccursor, max)
}
} else {
let min = ccursor_previous_line(text, ccursor);

View File

@@ -314,7 +314,7 @@ impl<'a> Slider<'a> {
/// Default: `0.0` (disabled).
#[inline]
pub fn step_by(mut self, step: f64) -> Self {
self.step = if step != 0.0 { Some(step) } else { None };
self.step = if step == 0.0 { None } else { Some(step) };
self
}

View File

@@ -680,7 +680,9 @@ impl TextEdit<'_> {
.wrap_mode(wrap_mode)
.allocate(ui);
allocated.frame = if !custom_frame {
allocated.frame = if custom_frame {
allocated.frame
} else {
let visuals = ui.style().interact(&allocated.response);
let background_color =
background_color.unwrap_or_else(|| ui.visuals().text_edit_bg_color());
@@ -713,8 +715,6 @@ impl TextEdit<'_> {
)
.outer_margin(Margin::same(-(visuals.expansion as i8)))
.stroke(stroke)
} else {
allocated.frame
};
allocated.paint(ui)
@@ -1019,7 +1019,9 @@ fn events(
}
}
Event::Paste(text_to_insert) => {
if !text_to_insert.is_empty() {
if text_to_insert.is_empty() {
None
} else {
let mut ccursor = text.delete_selected(&cursor_range);
if multiline {
text.insert_text_at(&mut ccursor, text_to_insert, char_limit);
@@ -1029,8 +1031,6 @@ fn events(
}
Some(CCursorRange::one(ccursor))
} else {
None
}
}
Event::Text(text_to_insert) => {