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:
@@ -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()) {
|
} else if JsValue::from_str("contentBoxSize").js_in(entry.as_ref()) {
|
||||||
let content_box_size = entry.content_box_size();
|
let content_box_size = entry.content_box_size();
|
||||||
let idx0 = content_box_size.at(0);
|
let idx0 = content_box_size.at(0);
|
||||||
if !idx0.is_undefined() {
|
if idx0.is_undefined() {
|
||||||
let size: web_sys::ResizeObserverSize = idx0.dyn_into()?;
|
|
||||||
width = size.inline_size();
|
|
||||||
height = size.block_size();
|
|
||||||
} else {
|
|
||||||
// legacy
|
// legacy
|
||||||
let size = JsValue::clone(content_box_size.as_ref());
|
let size = JsValue::clone(content_box_size.as_ref());
|
||||||
let size: web_sys::ResizeObserverSize = size.dyn_into()?;
|
let size: web_sys::ResizeObserverSize = size.dyn_into()?;
|
||||||
width = size.inline_size();
|
width = size.inline_size();
|
||||||
height = size.block_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 {
|
if DEBUG_RESIZE {
|
||||||
log::info!("contentBoxSize {width}x{height}");
|
log::info!("contentBoxSize {width}x{height}");
|
||||||
|
|||||||
@@ -272,10 +272,10 @@ impl Response {
|
|||||||
false
|
false
|
||||||
} else if let Some(pos) = pointer_interact_pos {
|
} else if let Some(pos) = pointer_interact_pos {
|
||||||
let layer_under_pointer = self.ctx.layer_id_at(pos);
|
let layer_under_pointer = self.ctx.layer_id_at(pos);
|
||||||
if layer_under_pointer != Some(self.layer_id) {
|
if layer_under_pointer == Some(self.layer_id) {
|
||||||
true
|
|
||||||
} else {
|
|
||||||
!self.interact_rect.contains(pos)
|
!self.interact_rect.contains(pos)
|
||||||
|
} else {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
false // clicked without a pointer, weird
|
false // clicked without a pointer, weird
|
||||||
|
|||||||
@@ -156,13 +156,13 @@ fn select_line_at(text: &str, ccursor: CCursor) -> CCursorRange {
|
|||||||
let min = ccursor_previous_line(text, ccursor);
|
let min = ccursor_previous_line(text, ccursor);
|
||||||
let max = ccursor_next_line(text, min);
|
let max = ccursor_next_line(text, min);
|
||||||
CCursorRange::two(min, max)
|
CCursorRange::two(min, max)
|
||||||
} else if !is_linebreak(char_after_cursor) {
|
} else if is_linebreak(char_after_cursor) {
|
||||||
let max = ccursor_next_line(text, ccursor);
|
|
||||||
CCursorRange::two(ccursor, max)
|
|
||||||
} else {
|
|
||||||
let min = ccursor_previous_line(text, ccursor);
|
let min = ccursor_previous_line(text, ccursor);
|
||||||
let max = ccursor_next_line(text, ccursor);
|
let max = ccursor_next_line(text, ccursor);
|
||||||
CCursorRange::two(min, max)
|
CCursorRange::two(min, max)
|
||||||
|
} else {
|
||||||
|
let max = ccursor_next_line(text, ccursor);
|
||||||
|
CCursorRange::two(ccursor, max)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let min = ccursor_previous_line(text, ccursor);
|
let min = ccursor_previous_line(text, ccursor);
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ impl<'a> Slider<'a> {
|
|||||||
/// Default: `0.0` (disabled).
|
/// Default: `0.0` (disabled).
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn step_by(mut self, step: f64) -> Self {
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -680,7 +680,9 @@ impl TextEdit<'_> {
|
|||||||
.wrap_mode(wrap_mode)
|
.wrap_mode(wrap_mode)
|
||||||
.allocate(ui);
|
.allocate(ui);
|
||||||
|
|
||||||
allocated.frame = if !custom_frame {
|
allocated.frame = if custom_frame {
|
||||||
|
allocated.frame
|
||||||
|
} else {
|
||||||
let visuals = ui.style().interact(&allocated.response);
|
let visuals = ui.style().interact(&allocated.response);
|
||||||
let background_color =
|
let background_color =
|
||||||
background_color.unwrap_or_else(|| ui.visuals().text_edit_bg_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)))
|
.outer_margin(Margin::same(-(visuals.expansion as i8)))
|
||||||
.stroke(stroke)
|
.stroke(stroke)
|
||||||
} else {
|
|
||||||
allocated.frame
|
|
||||||
};
|
};
|
||||||
|
|
||||||
allocated.paint(ui)
|
allocated.paint(ui)
|
||||||
@@ -1019,7 +1019,9 @@ fn events(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Paste(text_to_insert) => {
|
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);
|
let mut ccursor = text.delete_selected(&cursor_range);
|
||||||
if multiline {
|
if multiline {
|
||||||
text.insert_text_at(&mut ccursor, text_to_insert, char_limit);
|
text.insert_text_at(&mut ccursor, text_to_insert, char_limit);
|
||||||
@@ -1029,8 +1031,6 @@ fn events(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Some(CCursorRange::one(ccursor))
|
Some(CCursorRange::one(ccursor))
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Text(text_to_insert) => {
|
Event::Text(text_to_insert) => {
|
||||||
|
|||||||
@@ -466,10 +466,10 @@ impl WrapApp {
|
|||||||
for file in &i.raw.hovered_files {
|
for file in &i.raw.hovered_files {
|
||||||
if let Some(path) = &file.path {
|
if let Some(path) = &file.path {
|
||||||
write!(text, "\n{}", path.display()).ok();
|
write!(text, "\n{}", path.display()).ok();
|
||||||
} else if !file.mime.is_empty() {
|
} else if file.mime.is_empty() {
|
||||||
write!(text, "\n{}", file.mime).ok();
|
|
||||||
} else {
|
|
||||||
text += "\n???";
|
text += "\n???";
|
||||||
|
} else {
|
||||||
|
write!(text, "\n{}", file.mime).ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
text
|
text
|
||||||
@@ -505,10 +505,10 @@ impl WrapApp {
|
|||||||
for file in &self.dropped_files {
|
for file in &self.dropped_files {
|
||||||
let mut info = if let Some(path) = &file.path {
|
let mut info = if let Some(path) = &file.path {
|
||||||
path.display().to_string()
|
path.display().to_string()
|
||||||
} else if !file.name.is_empty() {
|
} else if file.name.is_empty() {
|
||||||
file.name.clone()
|
|
||||||
} else {
|
|
||||||
"???".to_owned()
|
"???".to_owned()
|
||||||
|
} else {
|
||||||
|
file.name.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut additional_info = vec![];
|
let mut additional_info = vec![];
|
||||||
|
|||||||
@@ -135,10 +135,10 @@ impl AllocInfo {
|
|||||||
what,
|
what,
|
||||||
self.megabytes()
|
self.megabytes()
|
||||||
)
|
)
|
||||||
} else if self.element_size != ElementSize::Heterogenous {
|
} else if self.element_size == ElementSize::Heterogenous {
|
||||||
format!(
|
format!(
|
||||||
"{:6} {:16} {} {:3} allocations",
|
"{:6} {:16} {} {:3} allocations",
|
||||||
self.num_elements(),
|
"",
|
||||||
what,
|
what,
|
||||||
self.megabytes(),
|
self.megabytes(),
|
||||||
self.num_allocs()
|
self.num_allocs()
|
||||||
@@ -146,7 +146,7 @@ impl AllocInfo {
|
|||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
"{:6} {:16} {} {:3} allocations",
|
"{:6} {:16} {} {:3} allocations",
|
||||||
"",
|
self.num_elements(),
|
||||||
what,
|
what,
|
||||||
self.megabytes(),
|
self.megabytes(),
|
||||||
self.num_allocs()
|
self.num_allocs()
|
||||||
|
|||||||
@@ -50,10 +50,10 @@ impl eframe::App for MyApp {
|
|||||||
for file in &self.dropped_files {
|
for file in &self.dropped_files {
|
||||||
let mut info = if let Some(path) = &file.path {
|
let mut info = if let Some(path) = &file.path {
|
||||||
path.display().to_string()
|
path.display().to_string()
|
||||||
} else if !file.name.is_empty() {
|
} else if file.name.is_empty() {
|
||||||
file.name.clone()
|
|
||||||
} else {
|
|
||||||
"???".to_owned()
|
"???".to_owned()
|
||||||
|
} else {
|
||||||
|
file.name.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut additional_info = vec![];
|
let mut additional_info = vec![];
|
||||||
@@ -95,10 +95,10 @@ fn preview_files_being_dropped(ctx: &egui::Context) {
|
|||||||
for file in &i.raw.hovered_files {
|
for file in &i.raw.hovered_files {
|
||||||
if let Some(path) = &file.path {
|
if let Some(path) = &file.path {
|
||||||
write!(text, "\n{}", path.display()).ok();
|
write!(text, "\n{}", path.display()).ok();
|
||||||
} else if !file.mime.is_empty() {
|
} else if file.mime.is_empty() {
|
||||||
write!(text, "\n{}", file.mime).ok();
|
|
||||||
} else {
|
|
||||||
text += "\n???";
|
text += "\n???";
|
||||||
|
} else {
|
||||||
|
write!(text, "\n{}", file.mime).ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
text
|
text
|
||||||
|
|||||||
@@ -416,16 +416,7 @@ fn drag_source<R>(
|
|||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
let is_being_dragged = ui.ctx().is_being_dragged(id);
|
let is_being_dragged = ui.ctx().is_being_dragged(id);
|
||||||
|
|
||||||
if !is_being_dragged {
|
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 {
|
|
||||||
ui.set_cursor_icon(egui::CursorIcon::Grabbing);
|
ui.set_cursor_icon(egui::CursorIcon::Grabbing);
|
||||||
|
|
||||||
// Paint the body to a new layer:
|
// 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
|
res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user