diff --git a/egui/src/containers/window.rs b/egui/src/containers/window.rs index 5ab9987e..8c213c17 100644 --- a/egui/src/containers/window.rs +++ b/egui/src/containers/window.rs @@ -367,8 +367,7 @@ impl<'open> Window<'open> { } }) }) - .map(|ir| (Some(ir.inner), Some(ir.response))) - .unwrap_or((None, None)); + .map_or((None, None), |ir| (Some(ir.inner), Some(ir.response))); let outer_rect = frame.end(&mut area_content_ui).rect; paint_resize_corner(&mut area_content_ui, &possible, outer_rect, frame_stroke); diff --git a/egui/src/input_state.rs b/egui/src/input_state.rs index 3c5e6518..cc75db3e 100644 --- a/egui/src/input_state.rs +++ b/egui/src/input_state.rs @@ -139,8 +139,7 @@ impl InputState { // `raw.zoom_delta` which is based on the `ctrl-scroll` event which, in turn, may be // synthesized from an original touch gesture. self.multi_touch() - .map(|touch| touch.zoom_delta) - .unwrap_or(self.raw.zoom_delta) + .map_or(self.raw.zoom_delta, |touch| touch.zoom_delta) } /// 2D non-proportional zoom scale factor this frame (e.g. from ctrl-scroll or pinch gesture). @@ -162,9 +161,10 @@ impl InputState { // the distances of the finger tips. It is therefore potentially more accurate than // `raw.zoom_delta` which is based on the `ctrl-scroll` event which, in turn, may be // synthesized from an original touch gesture. - self.multi_touch() - .map(|touch| touch.zoom_delta_2d) - .unwrap_or_else(|| Vec2::splat(self.raw.zoom_delta)) + self.multi_touch().map_or_else( + || Vec2::splat(self.raw.zoom_delta), + |touch| touch.zoom_delta_2d, + ) } pub fn wants_repaint(&self) -> bool { diff --git a/egui/src/widgets/text_edit.rs b/egui/src/widgets/text_edit.rs index 860cff7f..2caa77e4 100644 --- a/egui/src/widgets/text_edit.rs +++ b/egui/src/widgets/text_edit.rs @@ -658,9 +658,15 @@ impl<'t> TextEdit<'t> { if ui.memory().has_focus(id) && interactive { ui.memory().lock_focus(id, lock_focus); - let mut cursorp = state - .cursorp - .map(|cursorp| { + let mut cursorp = state.cursorp.map_or_else( + || { + if cursor_at_end { + CursorPair::one(galley.end()) + } else { + CursorPair::default() + } + }, + |cursorp| { // We only keep the PCursor (paragraph number, and character offset within that paragraph). // This is so what if we resize the `TextEdit` region, and text wrapping changes, // we keep the same byte character offset from the beginning of the text, @@ -672,14 +678,8 @@ impl<'t> TextEdit<'t> { primary: galley.from_pcursor(cursorp.primary.pcursor), secondary: galley.from_pcursor(cursorp.secondary.pcursor), } - }) - .unwrap_or_else(|| { - if cursor_at_end { - CursorPair::one(galley.end()) - } else { - CursorPair::default() - } - }); + }, + ); // We feed state to the undoer both before and after handling input // so that the undoer creates automatic saves even when there are no events for a while. diff --git a/egui_demo_lib/src/apps/demo/code_example.rs b/egui_demo_lib/src/apps/demo/code_example.rs index ef371a5e..51f79fea 100644 --- a/egui_demo_lib/src/apps/demo/code_example.rs +++ b/egui_demo_lib/src/apps/demo/code_example.rs @@ -150,8 +150,7 @@ fn remove_leading_indentation(code: &str) -> String { let start = first_line_indent.min(indent); let end = code .find('\n') - .map(|endline| endline + 1) - .unwrap_or_else(|| code.len()); + .map_or_else(|| code.len(), |endline| endline + 1); out += &code[start..end]; code = &code[end..]; } diff --git a/egui_demo_lib/src/apps/demo/multi_touch.rs b/egui_demo_lib/src/apps/demo/multi_touch.rs index 929f3c53..8c6a7292 100644 --- a/egui_demo_lib/src/apps/demo/multi_touch.rs +++ b/egui_demo_lib/src/apps/demo/multi_touch.rs @@ -49,11 +49,7 @@ impl super::View for MultiTouch { ui.separator(); ui.label("Try touch gestures Pinch/Stretch, Rotation, and Pressure with 2+ fingers."); - let num_touches = ui - .input() - .multi_touch() - .map(|mt| mt.num_touches) - .unwrap_or(0); + let num_touches = ui.input().multi_touch().map_or(0, |mt| mt.num_touches); ui.label(format!("Current touches: {}", num_touches)); Frame::dark_canvas(ui.style()).show(ui, |ui| { diff --git a/egui_demo_lib/src/easy_mark/easy_mark_highlighter.rs b/egui_demo_lib/src/easy_mark/easy_mark_highlighter.rs index e1850aa9..12f271e1 100644 --- a/egui_demo_lib/src/easy_mark/easy_mark_highlighter.rs +++ b/egui_demo_lib/src/easy_mark/easy_mark_highlighter.rs @@ -28,10 +28,7 @@ pub fn highlight_easymark(visuals: &egui::Visuals, mut text: &str) -> egui::text while !text.is_empty() { if start_of_line && text.starts_with("```") { - let end = text - .find("\n```") - .map(|i| i + 4) - .unwrap_or_else(|| text.len()); + let end = text.find("\n```").map_or_else(|| text.len(), |i| i + 4); job.append( &text[..end], 0.0, @@ -52,8 +49,7 @@ pub fn highlight_easymark(visuals: &egui::Visuals, mut text: &str) -> egui::text style.code = true; let end = text[1..] .find(&['`', '\n'][..]) - .map(|i| i + 2) - .unwrap_or_else(|| text.len()); + .map_or_else(|| text.len(), |i| i + 2); job.append(&text[..end], 0.0, format_from_style(visuals, &style)); text = &text[end..]; style.code = false; @@ -112,12 +108,10 @@ pub fn highlight_easymark(visuals: &egui::Visuals, mut text: &str) -> egui::text // Swallow everything up to the next special character: let line_end = text[skip..] .find('\n') - .map(|i| (skip + i + 1)) - .unwrap_or_else(|| text.len()); + .map_or_else(|| text.len(), |i| (skip + i + 1)); let end = text[skip..] .find(&['*', '`', '~', '_', '/', '$', '^', '\\', '<', '['][..]) - .map(|i| (skip + i).max(1)) // make sure we swallow at least one character - .unwrap_or_else(|| text.len()); + .map_or_else(|| text.len(), |i| (skip + i).max(1)); if line_end <= end { job.append(&text[..line_end], 0.0, format_from_style(visuals, &style)); diff --git a/egui_demo_lib/src/easy_mark/easy_mark_parser.rs b/egui_demo_lib/src/easy_mark/easy_mark_parser.rs index 304a57eb..abb4179f 100644 --- a/egui_demo_lib/src/easy_mark/easy_mark_parser.rs +++ b/egui_demo_lib/src/easy_mark/easy_mark_parser.rs @@ -319,8 +319,7 @@ impl<'a> Iterator for Parser<'a> { let end = self .s .find(&['*', '`', '~', '_', '/', '$', '^', '\\', '<', '[', '\n'][..]) - .map(|special| special.max(1)) // make sure we swallow at least one character - .unwrap_or_else(|| self.s.len()); + .map_or_else(|| self.s.len(), |special| special.max(1)); let item = Item::Text(self.style, &self.s[..end]); self.s = &self.s[end..]; diff --git a/egui_demo_lib/src/syntax_highlighting.rs b/egui_demo_lib/src/syntax_highlighting.rs index a4b0238a..29c178b5 100644 --- a/egui_demo_lib/src/syntax_highlighting.rs +++ b/egui_demo_lib/src/syntax_highlighting.rs @@ -416,8 +416,7 @@ impl Highligher { } else if text.starts_with(|c: char| c.is_ascii_alphanumeric()) { let end = text[1..] .find(|c: char| !c.is_ascii_alphanumeric()) - .map(|i| i + 1) - .unwrap_or_else(|| text.len()); + .map_or_else(|| text.len(), |i| i + 1); let word = &text[..end]; let tt = if is_keyword(word) { TokenType::Keyword @@ -429,8 +428,7 @@ impl Highligher { } else if text.starts_with(|c: char| c.is_ascii_whitespace()) { let end = text[1..] .find(|c: char| !c.is_ascii_whitespace()) - .map(|i| i + 1) - .unwrap_or_else(|| text.len()); + .map_or_else(|| text.len(), |i| i + 1); job.append(&text[..end], 0.0, theme.formats[TokenType::Whitespace]); text = &text[end..]; } else {