From d5cd0a6de9d0e0030bd5fd7e5347cd91e6a652f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 7 Aug 2025 22:36:02 +0200 Subject: [PATCH] Fix lints for Rust 1.89 and bump MSRV to `1.88` --- .github/workflows/test.yml | 4 +- Cargo.toml | 2 +- examples/editor/src/main.rs | 8 +- examples/pane_grid/src/main.rs | 23 +- .../creates_a_new_task-tiny-skia.sha256 | 2 +- .../snapshots/creates_a_new_task-wgpu.sha256 | 1 - examples/websocket/src/main.rs | 10 +- graphics/src/text/editor.rs | 18 +- wgpu/src/image/raster.rs | 6 +- widget/src/checkbox.rs | 8 +- widget/src/combo_box.rs | 60 ++-- widget/src/mouse_area.rs | 32 +-- widget/src/overlay/menu.rs | 40 ++- widget/src/pane_grid.rs | 269 +++++++++--------- widget/src/pane_grid/state.rs | 25 +- widget/src/pane_grid/title_bar.rs | 60 ++-- widget/src/scrollable.rs | 42 ++- widget/src/table.rs | 8 +- widget/src/text_editor.rs | 26 +- widget/src/text_input.rs | 55 ++-- winit/src/lib.rs | 56 ++-- 21 files changed, 360 insertions(+), 395 deletions(-) delete mode 100644 examples/todos/snapshots/creates_a_new_task-wgpu.sha256 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1e988195..d24f4503 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] - rust: [stable, beta, "1.85"] + rust: [stable, beta, "1.88"] steps: - uses: hecrj/setup-rust-action@v2 with: @@ -23,5 +23,7 @@ jobs: sudo apt-get install -y libxkbcommon-dev libgtk-3-dev - name: Run tests run: | + cargo test --verbose --workspace cargo test --verbose --workspace -- --ignored + cargo test --verbose --workspace --all-features cargo test --verbose --workspace --all-features -- --ignored diff --git a/Cargo.toml b/Cargo.toml index 6fed9896..be4070ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -145,7 +145,7 @@ repository = "https://github.com/iced-rs/iced" homepage = "https://iced.rs" categories = ["gui"] keywords = ["gui", "ui", "graphics", "interface", "widgets"] -rust-version = "1.85" +rust-version = "1.88" [workspace.dependencies] iced = { version = "0.14.0-dev", path = "." } diff --git a/examples/editor/src/main.rs b/examples/editor/src/main.rs index abad1abe..ad2337d8 100644 --- a/examples/editor/src/main.rs +++ b/examples/editor/src/main.rs @@ -119,10 +119,10 @@ impl Editor { let mut text = self.content.text(); - if let Some(ending) = self.content.line_ending() { - if !text.ends_with(ending.as_str()) { - text.push_str(ending.as_str()); - } + if let Some(ending) = self.content.line_ending() + && !text.ends_with(ending.as_str()) + { + text.push_str(ending.as_str()); } Task::perform( diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index 2d2b92d9..f94e83ca 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -71,11 +71,10 @@ impl Example { } } Message::FocusAdjacent(direction) => { - if let Some(pane) = self.focus { - if let Some(adjacent) = self.panes.adjacent(pane, direction) - { - self.focus = Some(adjacent); - } + if let Some(pane) = self.focus + && let Some(adjacent) = self.panes.adjacent(pane, direction) + { + self.focus = Some(adjacent); } } Message::Clicked(pane) => { @@ -106,14 +105,12 @@ impl Example { } } Message::CloseFocused => { - if let Some(pane) = self.focus { - if let Some(Pane { is_pinned, .. }) = self.panes.get(pane) { - if !is_pinned { - if let Some((_, sibling)) = self.panes.close(pane) { - self.focus = Some(sibling); - } - } - } + if let Some(pane) = self.focus + && let Some(Pane { is_pinned, .. }) = self.panes.get(pane) + && !is_pinned + && let Some((_, sibling)) = self.panes.close(pane) + { + self.focus = Some(sibling); } } } diff --git a/examples/todos/snapshots/creates_a_new_task-tiny-skia.sha256 b/examples/todos/snapshots/creates_a_new_task-tiny-skia.sha256 index f62b2f69..e6746cf8 100644 --- a/examples/todos/snapshots/creates_a_new_task-tiny-skia.sha256 +++ b/examples/todos/snapshots/creates_a_new_task-tiny-skia.sha256 @@ -1 +1 @@ -0e355b080ad33905145e9f70a3b29e2481197c8fc8f42491acd5358238ebbd5f \ No newline at end of file +99f418007af163f172e163565f166da31015521e1bf7de95fa55cda2fb5a7db5 \ No newline at end of file diff --git a/examples/todos/snapshots/creates_a_new_task-wgpu.sha256 b/examples/todos/snapshots/creates_a_new_task-wgpu.sha256 deleted file mode 100644 index 6dd6ccbe..00000000 --- a/examples/todos/snapshots/creates_a_new_task-wgpu.sha256 +++ /dev/null @@ -1 +0,0 @@ -804a1bb6d49e3b3158463202960447d9e7820b967280f41dd0c34c00d3edf2c3 \ No newline at end of file diff --git a/examples/websocket/src/main.rs b/examples/websocket/src/main.rs index 95f06fa4..1c034ee4 100644 --- a/examples/websocket/src/main.rs +++ b/examples/websocket/src/main.rs @@ -116,11 +116,11 @@ impl WebSocket { let mut button = button(text("Send").height(40).align_y(Center)) .padding([0, 20]); - if matches!(self.state, State::Connected(_)) { - if let Some(message) = echo::Message::new(&self.new_message) { - input = input.on_submit(Message::Send(message.clone())); - button = button.on_press(Message::Send(message)); - } + if matches!(self.state, State::Connected(_)) + && let Some(message) = echo::Message::new(&self.new_message) + { + input = input.on_submit(Message::Send(message.clone())); + button = button.on_press(Message::Send(message)); } row![input, button].spacing(10).align_y(Center) diff --git a/graphics/src/text/editor.rs b/graphics/src/text/editor.rs index 4afd7b12..72a6fc68 100644 --- a/graphics/src/text/editor.rs +++ b/graphics/src/text/editor.rs @@ -321,10 +321,11 @@ impl editor::Editor for Editor { ); // Deselect if selection matches cursor position - if let Some((start, end)) = editor.selection_bounds() { - if start.line == end.line && start.index == end.index { - editor.set_selection(cosmic_text::Selection::None); - } + if let Some((start, end)) = editor.selection_bounds() + && start.line == end.line + && start.index == end.index + { + editor.set_selection(cosmic_text::Selection::None); } } Action::SelectWord => { @@ -438,10 +439,11 @@ impl editor::Editor for Editor { ); // Deselect if selection matches cursor position - if let Some((start, end)) = editor.selection_bounds() { - if start.line == end.line && start.index == end.index { - editor.set_selection(cosmic_text::Selection::None); - } + if let Some((start, end)) = editor.selection_bounds() + && start.line == end.line + && start.index == end.index + { + editor.set_selection(cosmic_text::Selection::None); } } Action::Scroll { lines } => { diff --git a/wgpu/src/image/raster.rs b/wgpu/src/image/raster.rs index 83777807..470c39e2 100644 --- a/wgpu/src/image/raster.rs +++ b/wgpu/src/image/raster.rs @@ -99,10 +99,8 @@ impl Cache { self.map.retain(|k, memory| { let retain = hits.contains(k); - if !retain { - if let Memory::Device(entry) = memory { - atlas.remove(entry); - } + if !retain && let Memory::Device(entry) = memory { + atlas.remove(entry); } retain diff --git a/widget/src/checkbox.rs b/widget/src/checkbox.rs index 04e7472e..42ef89fd 100644 --- a/widget/src/checkbox.rs +++ b/widget/src/checkbox.rs @@ -320,11 +320,9 @@ where | Event::Touch(touch::Event::FingerPressed { .. }) => { let mouse_over = cursor.is_over(layout.bounds()); - if mouse_over { - if let Some(on_toggle) = &self.on_toggle { - shell.publish((on_toggle)(!self.is_checked)); - shell.capture_event(); - } + if mouse_over && let Some(on_toggle) = &self.on_toggle { + shell.publish((on_toggle)(!self.is_checked)); + shell.capture_event(); } } _ => {} diff --git a/widget/src/combo_box.rs b/widget/src/combo_box.rs index 5bf01eac..581a4fcd 100644 --- a/widget/src/combo_box.rs +++ b/widget/src/combo_box.rs @@ -599,17 +599,16 @@ where if is_focused { self.state.with_inner(|state| { - if !started_focused { - if let Some(on_option_hovered) = &mut self.on_option_hovered - { - let hovered_option = menu.hovered_option.unwrap_or(0); + if !started_focused + && let Some(on_option_hovered) = &mut self.on_option_hovered + { + let hovered_option = menu.hovered_option.unwrap_or(0); - if let Some(option) = - state.filtered_options.options.get(hovered_option) - { - shell.publish(on_option_hovered(option.clone())); - published_message_to_shell = true; - } + if let Some(option) = + state.filtered_options.options.get(hovered_option) + { + shell.publish(on_option_hovered(option.clone())); + published_message_to_shell = true; } } @@ -622,12 +621,11 @@ where let shift_modifier = modifiers.shift(); match (named_key, shift_modifier) { (key::Named::Enter, _) => { - if let Some(index) = &menu.hovered_option { - if let Some(option) = + if let Some(index) = &menu.hovered_option + && let Some(option) = state.filtered_options.options.get(*index) - { - menu.new_selection = Some(option.clone()); - } + { + menu.new_selection = Some(option.clone()); } shell.capture_event(); @@ -650,21 +648,19 @@ where if let Some(on_option_hovered) = &mut self.on_option_hovered - { - if let Some(option) = + && let Some(option) = menu.hovered_option.and_then(|index| { state .filtered_options .options .get(index) }) - { - // Notify the selection - shell.publish((on_option_hovered)( - option.clone(), - )); - published_message_to_shell = true; - } + { + // Notify the selection + shell.publish((on_option_hovered)( + option.clone(), + )); + published_message_to_shell = true; } shell.capture_event(); @@ -698,21 +694,19 @@ where if let Some(on_option_hovered) = &mut self.on_option_hovered - { - if let Some(option) = + && let Some(option) = menu.hovered_option.and_then(|index| { state .filtered_options .options .get(index) }) - { - // Notify the selection - shell.publish((on_option_hovered)( - option.clone(), - )); - published_message_to_shell = true; - } + { + // Notify the selection + shell.publish((on_option_hovered)( + option.clone(), + )); + published_message_to_shell = true; } shell.capture_event(); diff --git a/widget/src/mouse_area.rs b/widget/src/mouse_area.rs index e17ccd97..fefa68d5 100644 --- a/widget/src/mouse_area.rs +++ b/widget/src/mouse_area.rs @@ -377,24 +377,24 @@ fn update( shell.capture_event(); } - if let Some(position) = cursor_position { - if let Some(message) = widget.on_double_click.as_ref() { - let new_click = mouse::Click::new( - position, - mouse::Button::Left, - state.previous_click, - ); + if let Some(position) = cursor_position + && let Some(message) = widget.on_double_click.as_ref() + { + let new_click = mouse::Click::new( + position, + mouse::Button::Left, + state.previous_click, + ); - if new_click.kind() == mouse::click::Kind::Double { - shell.publish(message.clone()); - } - - state.previous_click = Some(new_click); - - // Even if this is not a double click, but the press is nevertheless - // processed by us and should not be popup to parent widgets. - shell.capture_event(); + if new_click.kind() == mouse::click::Kind::Double { + shell.publish(message.clone()); } + + state.previous_click = Some(new_click); + + // Even if this is not a double click, but the press is nevertheless + // processed by us and should not be popup to parent widgets. + shell.capture_event(); } } Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) diff --git a/widget/src/overlay/menu.rs b/widget/src/overlay/menu.rs index 7778768a..741dbf15 100644 --- a/widget/src/overlay/menu.rs +++ b/widget/src/overlay/menu.rs @@ -407,13 +407,12 @@ where ) { match event { Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => { - if cursor.is_over(layout.bounds()) { - if let Some(index) = *self.hovered_option { - if let Some(option) = self.options.get(index) { - shell.publish((self.on_selected)(option.clone())); - shell.capture_event(); - } - } + if cursor.is_over(layout.bounds()) + && let Some(index) = *self.hovered_option + && let Some(option) = self.options.get(index) + { + shell.publish((self.on_selected)(option.clone())); + shell.capture_event(); } } Event::Mouse(mouse::Event::CursorMoved { .. }) => { @@ -431,19 +430,16 @@ where let new_hovered_option = (cursor_position.y / option_height) as usize; - if *self.hovered_option != Some(new_hovered_option) { - if let Some(option) = + if *self.hovered_option != Some(new_hovered_option) + && let Some(option) = self.options.get(new_hovered_option) + { + if let Some(on_option_hovered) = self.on_option_hovered { - if let Some(on_option_hovered) = - self.on_option_hovered - { - shell - .publish(on_option_hovered(option.clone())); - } - - shell.request_redraw(); + shell.publish(on_option_hovered(option.clone())); } + + shell.request_redraw(); } *self.hovered_option = Some(new_hovered_option); @@ -464,11 +460,11 @@ where *self.hovered_option = Some((cursor_position.y / option_height) as usize); - if let Some(index) = *self.hovered_option { - if let Some(option) = self.options.get(index) { - shell.publish((self.on_selected)(option.clone())); - shell.capture_event(); - } + if let Some(index) = *self.hovered_option + && let Some(option) = self.options.get(index) + { + shell.publish((self.on_selected)(option.clone())); + shell.capture_event(); } } } diff --git a/widget/src/pane_grid.rs b/widget/src/pane_grid.rs index db60fabc..158c265b 100644 --- a/widget/src/pane_grid.rs +++ b/widget/src/pane_grid.rs @@ -593,56 +593,47 @@ where Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) | Event::Touch(touch::Event::FingerLifted { .. }) | Event::Touch(touch::Event::FingerLost { .. }) => { - if let Some((pane, origin)) = action.picked_pane() { - if let Some(on_drag) = on_drag { - if let Some(cursor_position) = cursor.position() { - if cursor_position.distance(origin) - > DRAG_DEADBAND_DISTANCE - { - let event = if let Some(edge) = - in_edge(layout, cursor_position) + if let Some((pane, origin)) = action.picked_pane() + && let Some(on_drag) = on_drag + && let Some(cursor_position) = cursor.position() + { + if cursor_position.distance(origin) > DRAG_DEADBAND_DISTANCE + { + let event = if let Some(edge) = + in_edge(layout, cursor_position) + { + DragEvent::Dropped { + pane, + target: Target::Edge(edge), + } + } else { + let dropped_region = self + .panes + .iter() + .copied() + .zip(&self.contents) + .zip(layout.children()) + .find_map(|(target, layout)| { + layout_region(layout, cursor_position) + .map(|region| (target, region)) + }); + + match dropped_region { + Some(((target, _), region)) + if pane != target => { DragEvent::Dropped { pane, - target: Target::Edge(edge), + target: Target::Pane(target, region), } - } else { - let dropped_region = self - .panes - .iter() - .copied() - .zip(&self.contents) - .zip(layout.children()) - .find_map(|(target, layout)| { - layout_region( - layout, - cursor_position, - ) - .map(|region| (target, region)) - }); - - match dropped_region { - Some(((target, _), region)) - if pane != target => - { - DragEvent::Dropped { - pane, - target: Target::Pane( - target, region, - ), - } - } - _ => DragEvent::Canceled { pane }, - } - }; - - shell.publish(on_drag(event)); - } else { - shell.publish(on_drag(DragEvent::Canceled { - pane, - })); + } + _ => DragEvent::Canceled { pane }, } - } + }; + + shell.publish(on_drag(event)); + } else { + shell.publish(on_drag(DragEvent::Canceled { pane })); } } @@ -660,34 +651,33 @@ where bounds.size(), ); - if let Some((axis, rectangle, _)) = splits.get(&split) { - if let Some(cursor_position) = cursor.position() { - let ratio = match axis { - Axis::Horizontal => { - let position = cursor_position.y - - bounds.y - - rectangle.y; + if let Some((axis, rectangle, _)) = splits.get(&split) + && let Some(cursor_position) = cursor.position() + { + let ratio = match axis { + Axis::Horizontal => { + let position = cursor_position.y + - bounds.y + - rectangle.y; - (position / rectangle.height) - .clamp(0.0, 1.0) - } - Axis::Vertical => { - let position = cursor_position.x - - bounds.x - - rectangle.x; + (position / rectangle.height) + .clamp(0.0, 1.0) + } + Axis::Vertical => { + let position = cursor_position.x + - bounds.x + - rectangle.x; - (position / rectangle.width) - .clamp(0.0, 1.0) - } - }; + (position / rectangle.width).clamp(0.0, 1.0) + } + }; - shell.publish(on_resize(ResizeEvent { - split, - ratio, - })); + shell.publish(on_resize(ResizeEvent { + split, + ratio, + })); - shell.capture_event(); - } + shell.capture_event(); } } else if action.picked_pane().is_some() { shell.request_redraw(); @@ -889,24 +879,23 @@ where viewport, ); - if picked_pane.is_some() && pane_in_edge.is_none() { - if let Some(region) = + if picked_pane.is_some() + && pane_in_edge.is_none() + && let Some(region) = cursor.position().and_then(|cursor_position| { layout_region(pane_layout, cursor_position) }) - { - let bounds = - layout_region_bounds(pane_layout, region); + { + let bounds = layout_region_bounds(pane_layout, region); - renderer.fill_quad( - renderer::Quad { - bounds, - border: style.hovered_region.border, - ..renderer::Quad::default() - }, - style.hovered_region.background, - ); - } + renderer.fill_quad( + renderer::Quad { + bounds, + border: style.hovered_region.border, + ..renderer::Quad::default() + }, + style.hovered_region.background, + ); } } _ => { @@ -937,64 +926,62 @@ where } // Render picked pane last - if let Some(((content, tree), origin, layout)) = render_picked_pane { - if let Some(cursor_position) = cursor.position() { - let bounds = layout.bounds(); + if let Some(((content, tree), origin, layout)) = render_picked_pane + && let Some(cursor_position) = cursor.position() + { + let bounds = layout.bounds(); - let translation = - cursor_position - Point::new(origin.x, origin.y); + let translation = cursor_position - Point::new(origin.x, origin.y); - renderer.with_translation(translation, |renderer| { - renderer.with_layer(bounds, |renderer| { - content.draw( - tree, - renderer, - theme, - defaults, - layout, - pane_cursor, - viewport, - ); - }); + renderer.with_translation(translation, |renderer| { + renderer.with_layer(bounds, |renderer| { + content.draw( + tree, + renderer, + theme, + defaults, + layout, + pane_cursor, + viewport, + ); }); - } + }); } - if picked_pane.is_none() { - if let Some((axis, split_region, is_picked)) = picked_split { - let highlight = if is_picked { - style.picked_split - } else { - style.hovered_split - }; + if picked_pane.is_none() + && let Some((axis, split_region, is_picked)) = picked_split + { + let highlight = if is_picked { + style.picked_split + } else { + style.hovered_split + }; - renderer.fill_quad( - renderer::Quad { - bounds: match axis { - Axis::Horizontal => Rectangle { - x: split_region.x, - y: (split_region.y - + (split_region.height - highlight.width) - / 2.0) - .round(), - width: split_region.width, - height: highlight.width, - }, - Axis::Vertical => Rectangle { - x: (split_region.x - + (split_region.width - highlight.width) - / 2.0) - .round(), - y: split_region.y, - width: highlight.width, - height: split_region.height, - }, + renderer.fill_quad( + renderer::Quad { + bounds: match axis { + Axis::Horizontal => Rectangle { + x: split_region.x, + y: (split_region.y + + (split_region.height - highlight.width) + / 2.0) + .round(), + width: split_region.width, + height: highlight.width, + }, + Axis::Vertical => Rectangle { + x: (split_region.x + + (split_region.width - highlight.width) / 2.0) + .round(), + y: split_region.y, + width: highlight.width, + height: split_region.height, }, - ..renderer::Quad::default() }, - highlight.color, - ); - } + ..renderer::Quad::default() + }, + highlight.color, + ); } } @@ -1086,15 +1073,15 @@ fn click_pane<'a, Message, T>( shell.publish(on_click(pane)); } - if let Some(on_drag) = &on_drag { - if content.can_be_dragged_at(layout, cursor_position) { - *action = state::Action::Dragging { - pane, - origin: cursor_position, - }; + if let Some(on_drag) = &on_drag + && content.can_be_dragged_at(layout, cursor_position) + { + *action = state::Action::Dragging { + pane, + origin: cursor_position, + }; - shell.publish(on_drag(DragEvent::Picked { pane })); - } + shell.publish(on_drag(DragEvent::Picked { pane })); } } } diff --git a/widget/src/pane_grid/state.rs b/widget/src/pane_grid/state.rs index d999434f..84c971bf 100644 --- a/widget/src/pane_grid/state.rs +++ b/widget/src/pane_grid/state.rs @@ -219,14 +219,14 @@ impl State { pane: Pane, swap: bool, ) { - if let Some((state, _)) = self.close(pane) { - if let Some((new_pane, _)) = self.split(axis, target, state) { - // Ensure new node corresponds to original closed `Pane` for state continuity - self.relabel(new_pane, pane); + if let Some((state, _)) = self.close(pane) + && let Some((new_pane, _)) = self.split(axis, target, state) + { + // Ensure new node corresponds to original closed `Pane` for state continuity + self.relabel(new_pane, pane); - if swap { - self.swap(target, pane); - } + if swap { + self.swap(target, pane); } } } @@ -257,13 +257,12 @@ impl State { pane: Pane, inverse: bool, ) { - if let Some((state, _)) = self.close(pane) { - if let Some((new_pane, _)) = + if let Some((state, _)) = self.close(pane) + && let Some((new_pane, _)) = self.split_node(axis, None, state, inverse) - { - // Ensure new node corresponds to original closed `Pane` for state continuity - self.relabel(new_pane, pane); - } + { + // Ensure new node corresponds to original closed `Pane` for state continuity + self.relabel(new_pane, pane); } } diff --git a/widget/src/pane_grid/title_bar.rs b/widget/src/pane_grid/title_bar.rs index 5cd53b50..e47f4a10 100644 --- a/widget/src/pane_grid/title_bar.rs +++ b/widget/src/pane_grid/title_bar.rs @@ -174,38 +174,28 @@ where let title_layout = children.next().unwrap(); let mut show_title = true; - if let Some(controls) = &self.controls { - if show_controls || self.always_show_controls { - let controls_layout = children.next().unwrap(); - if title_layout.bounds().width + controls_layout.bounds().width - > padded.bounds().width - { - if let Some(compact) = controls.compact.as_ref() { - let compact_layout = children.next().unwrap(); + if let Some(controls) = &self.controls + && (show_controls || self.always_show_controls) + { + let controls_layout = children.next().unwrap(); + if title_layout.bounds().width + controls_layout.bounds().width + > padded.bounds().width + { + if let Some(compact) = controls.compact.as_ref() { + let compact_layout = children.next().unwrap(); - compact.as_widget().draw( - &tree.children[2], - renderer, - theme, - &inherited_style, - compact_layout, - cursor, - viewport, - ); - } else { - show_title = false; - - controls.full.as_widget().draw( - &tree.children[1], - renderer, - theme, - &inherited_style, - controls_layout, - cursor, - viewport, - ); - } + compact.as_widget().draw( + &tree.children[2], + renderer, + theme, + &inherited_style, + compact_layout, + cursor, + viewport, + ); } else { + show_title = false; + controls.full.as_widget().draw( &tree.children[1], renderer, @@ -216,6 +206,16 @@ where viewport, ); } + } else { + controls.full.as_widget().draw( + &tree.children[1], + renderer, + theme, + &inherited_style, + controls_layout, + cursor, + viewport, + ); } } diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 61e78d50..baff578e 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -798,12 +798,11 @@ where }, ); - if !had_input_method { - if let InputMethod::Enabled { position, .. } = + if !had_input_method + && let InputMethod::Enabled { position, .. } = shell.input_method_mut() - { - *position = *position - translation; - } + { + *position = *position - translation; } }; @@ -1091,23 +1090,22 @@ where ); } - if let Some(scroller) = scrollbar.scroller { - if scroller.bounds.width > 0.0 - && scroller.bounds.height > 0.0 - && (style.scroller.color != Color::TRANSPARENT - || (style.scroller.border.color - != Color::TRANSPARENT - && style.scroller.border.width > 0.0)) - { - renderer.fill_quad( - renderer::Quad { - bounds: scroller.bounds, - border: style.scroller.border, - ..renderer::Quad::default() - }, - style.scroller.color, - ); - } + if let Some(scroller) = scrollbar.scroller + && scroller.bounds.width > 0.0 + && scroller.bounds.height > 0.0 + && (style.scroller.color != Color::TRANSPARENT + || (style.scroller.border.color + != Color::TRANSPARENT + && style.scroller.border.width > 0.0)) + { + renderer.fill_quad( + renderer::Quad { + bounds: scroller.bounds, + border: style.scroller.border, + ..renderer::Quad::default() + }, + style.scroller.color, + ); } }; diff --git a/widget/src/table.rs b/widget/src/table.rs index 8fd41306..03537f9a 100644 --- a/widget/src/table.rs +++ b/widget/src/table.rs @@ -127,10 +127,10 @@ where } } - if width == Length::Shrink { - if let Some(first) = columns.first_mut() { - first.width = Length::Fill; - } + if width == Length::Shrink + && let Some(first) = columns.first_mut() + { + first.width = Length::Fill; } Self { diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 451072a8..3657c817 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -689,22 +689,20 @@ where } } Event::Window(window::Event::RedrawRequested(now)) => { - if let Some(focus) = &mut state.focus { - if focus.is_window_focused { - focus.now = *now; + if let Some(focus) = &mut state.focus + && focus.is_window_focused + { + focus.now = *now; - let millis_until_redraw = - Focus::CURSOR_BLINK_INTERVAL_MILLIS - - (focus.now - focus.updated_at).as_millis() - % Focus::CURSOR_BLINK_INTERVAL_MILLIS; + let millis_until_redraw = + Focus::CURSOR_BLINK_INTERVAL_MILLIS + - (focus.now - focus.updated_at).as_millis() + % Focus::CURSOR_BLINK_INTERVAL_MILLIS; - shell.request_redraw_at( - focus.now - + Duration::from_millis( - millis_until_redraw as u64, - ), - ); - } + shell.request_redraw_at( + focus.now + + Duration::from_millis(millis_until_redraw as u64), + ); } } _ => {} diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index 3e849175..fa3dd770 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -1247,12 +1247,12 @@ where Event::Keyboard(keyboard::Event::KeyReleased { key, .. }) => { let state = state::(tree); - if state.is_focused.is_some() { - if let keyboard::Key::Character("v") = key.as_ref() { - state.is_pasting = None; + if state.is_focused.is_some() + && let keyboard::Key::Character("v") = key.as_ref() + { + state.is_pasting = None; - shell.capture_event(); - } + shell.capture_event(); } state.is_pasting = None; @@ -1328,32 +1328,31 @@ where Event::Window(window::Event::RedrawRequested(now)) => { let state = state::(tree); - if let Some(focus) = &mut state.is_focused { - if focus.is_window_focused { - if matches!( - state.cursor.state(&self.value), - cursor::State::Index(_) - ) { - focus.now = *now; + if let Some(focus) = &mut state.is_focused + && focus.is_window_focused + { + if matches!( + state.cursor.state(&self.value), + cursor::State::Index(_) + ) { + focus.now = *now; - let millis_until_redraw = - CURSOR_BLINK_INTERVAL_MILLIS - - (*now - focus.updated_at).as_millis() - % CURSOR_BLINK_INTERVAL_MILLIS; + let millis_until_redraw = CURSOR_BLINK_INTERVAL_MILLIS + - (*now - focus.updated_at).as_millis() + % CURSOR_BLINK_INTERVAL_MILLIS; - shell.request_redraw_at( - *now + Duration::from_millis( - millis_until_redraw as u64, - ), - ); - } - - shell.request_input_method(&self.input_method( - state, - layout, - &self.value, - )); + shell.request_redraw_at( + *now + Duration::from_millis( + millis_until_redraw as u64, + ), + ); } + + shell.request_input_method(&self.input_method( + state, + layout, + &self.value, + )); } } _ => {} diff --git a/winit/src/lib.rs b/winit/src/lib.rs index c4e62863..0ad2c507 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -62,6 +62,7 @@ use window::WindowManager; use rustc_hash::FxHashMap; use std::borrow::Cow; use std::mem::ManuallyDrop; +use std::slice; use std::sync::Arc; /// Runs a [`Program`] with the provided settings. @@ -652,11 +653,11 @@ async fn run_instance

( let now = Instant::now(); for (_id, window) in window_manager.iter_mut() { - if let Some(redraw_at) = window.redraw_at { - if redraw_at <= now { - window.raw.request_redraw(); - window.redraw_at = None; - } + if let Some(redraw_at) = window.redraw_at + && redraw_at <= now + { + window.raw.request_redraw(); + window.redraw_at = None; } } @@ -760,7 +761,7 @@ async fn run_instance

( let draw_span = debug::draw(id); let (ui_state, _) = ui.update( - &[redraw_event.clone()], + slice::from_ref(&redraw_event), cursor, &mut window.renderer, &mut clipboard, @@ -1346,17 +1347,14 @@ fn run_action<'a, P, C>( } } window::Action::ShowSystemMenu(id) => { - if let Some(window) = window_manager.get_mut(id) { - if let mouse::Cursor::Available(point) = + if let Some(window) = window_manager.get_mut(id) + && let mouse::Cursor::Available(point) = window.state.cursor() - { - window.raw.show_window_menu( - winit::dpi::LogicalPosition { - x: point.x, - y: point.y, - }, - ); - } + { + window.raw.show_window_menu(winit::dpi::LogicalPosition { + x: point.x, + y: point.y, + }); } } window::Action::GetRawId(id, channel) => { @@ -1375,20 +1373,20 @@ fn run_action<'a, P, C>( } } window::Action::Screenshot(id, channel) => { - if let Some(window) = window_manager.get_mut(id) { - if let Some(compositor) = compositor { - let bytes = compositor.screenshot( - &mut window.renderer, - window.state.viewport(), - window.state.background_color(), - ); + if let Some(window) = window_manager.get_mut(id) + && let Some(compositor) = compositor + { + let bytes = compositor.screenshot( + &mut window.renderer, + window.state.viewport(), + window.state.background_color(), + ); - let _ = channel.send(core::window::Screenshot::new( - bytes, - window.state.physical_size(), - window.state.viewport().scale_factor(), - )); - } + let _ = channel.send(core::window::Screenshot::new( + bytes, + window.state.physical_size(), + window.state.viewport().scale_factor(), + )); } } window::Action::EnableMousePassthrough(id) => {