1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -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

@@ -1114,16 +1114,16 @@ fn get_display_size(resize_observer_entries: &js_sys::Array) -> Result<(u32, u32
} else if JsValue::from_str("contentBoxSize").js_in(entry.as_ref()) {
let content_box_size = entry.content_box_size();
let idx0 = content_box_size.at(0);
if !idx0.is_undefined() {
let size: web_sys::ResizeObserverSize = idx0.dyn_into()?;
width = size.inline_size();
height = size.block_size();
} else {
if idx0.is_undefined() {
// legacy
let size = JsValue::clone(content_box_size.as_ref());
let size: web_sys::ResizeObserverSize = size.dyn_into()?;
width = size.inline_size();
height = size.block_size();
} else {
let size: web_sys::ResizeObserverSize = idx0.dyn_into()?;
width = size.inline_size();
height = size.block_size();
}
if DEBUG_RESIZE {
log::info!("contentBoxSize {width}x{height}");

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) => {

View File

@@ -466,10 +466,10 @@ impl WrapApp {
for file in &i.raw.hovered_files {
if let Some(path) = &file.path {
write!(text, "\n{}", path.display()).ok();
} else if !file.mime.is_empty() {
write!(text, "\n{}", file.mime).ok();
} else {
} else if file.mime.is_empty() {
text += "\n???";
} else {
write!(text, "\n{}", file.mime).ok();
}
}
text
@@ -505,10 +505,10 @@ impl WrapApp {
for file in &self.dropped_files {
let mut info = if let Some(path) = &file.path {
path.display().to_string()
} else if !file.name.is_empty() {
file.name.clone()
} else {
} else if file.name.is_empty() {
"???".to_owned()
} else {
file.name.clone()
};
let mut additional_info = vec![];

View File

@@ -135,10 +135,10 @@ impl AllocInfo {
what,
self.megabytes()
)
} else if self.element_size != ElementSize::Heterogenous {
} else if self.element_size == ElementSize::Heterogenous {
format!(
"{:6} {:16} {} {:3} allocations",
self.num_elements(),
"",
what,
self.megabytes(),
self.num_allocs()
@@ -146,7 +146,7 @@ impl AllocInfo {
} else {
format!(
"{:6} {:16} {} {:3} allocations",
"",
self.num_elements(),
what,
self.megabytes(),
self.num_allocs()

View File

@@ -50,10 +50,10 @@ impl eframe::App for MyApp {
for file in &self.dropped_files {
let mut info = if let Some(path) = &file.path {
path.display().to_string()
} else if !file.name.is_empty() {
file.name.clone()
} else {
} else if file.name.is_empty() {
"???".to_owned()
} else {
file.name.clone()
};
let mut additional_info = vec![];
@@ -95,10 +95,10 @@ fn preview_files_being_dropped(ctx: &egui::Context) {
for file in &i.raw.hovered_files {
if let Some(path) = &file.path {
write!(text, "\n{}", path.display()).ok();
} else if !file.mime.is_empty() {
write!(text, "\n{}", file.mime).ok();
} else {
} else if file.mime.is_empty() {
text += "\n???";
} else {
write!(text, "\n{}", file.mime).ok();
}
}
text

View File

@@ -416,16 +416,7 @@ fn drag_source<R>(
) -> InnerResponse<R> {
let is_being_dragged = ui.ctx().is_being_dragged(id);
if !is_being_dragged {
let res = ui.scope(body);
// Check for drags:
let response = ui.interact(res.response.rect, id, egui::Sense::drag());
if response.hovered() {
ui.set_cursor_icon(egui::CursorIcon::Grab);
}
res
} else {
if is_being_dragged {
ui.set_cursor_icon(egui::CursorIcon::Grabbing);
// Paint the body to a new layer:
@@ -440,6 +431,15 @@ fn drag_source<R>(
);
}
res
} else {
let res = ui.scope(body);
// Check for drags:
let response = ui.interact(res.response.rect, id, egui::Sense::drag());
if response.hovered() {
ui.set_cursor_icon(egui::CursorIcon::Grab);
}
res
}
}