Fix lints for Rust 1.89 and bump MSRV to 1.88

This commit is contained in:
Héctor Ramón Jiménez 2025-08-07 22:36:02 +02:00
parent 88185f9d97
commit d5cd0a6de9
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
21 changed files with 360 additions and 395 deletions

View file

@ -9,7 +9,7 @@ jobs:
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, windows-latest, macOS-latest] os: [ubuntu-latest, windows-latest, macOS-latest]
rust: [stable, beta, "1.85"] rust: [stable, beta, "1.88"]
steps: steps:
- uses: hecrj/setup-rust-action@v2 - uses: hecrj/setup-rust-action@v2
with: with:
@ -23,5 +23,7 @@ jobs:
sudo apt-get install -y libxkbcommon-dev libgtk-3-dev sudo apt-get install -y libxkbcommon-dev libgtk-3-dev
- name: Run tests - name: Run tests
run: | run: |
cargo test --verbose --workspace
cargo test --verbose --workspace -- --ignored cargo test --verbose --workspace -- --ignored
cargo test --verbose --workspace --all-features
cargo test --verbose --workspace --all-features -- --ignored cargo test --verbose --workspace --all-features -- --ignored

View file

@ -145,7 +145,7 @@ repository = "https://github.com/iced-rs/iced"
homepage = "https://iced.rs" homepage = "https://iced.rs"
categories = ["gui"] categories = ["gui"]
keywords = ["gui", "ui", "graphics", "interface", "widgets"] keywords = ["gui", "ui", "graphics", "interface", "widgets"]
rust-version = "1.85" rust-version = "1.88"
[workspace.dependencies] [workspace.dependencies]
iced = { version = "0.14.0-dev", path = "." } iced = { version = "0.14.0-dev", path = "." }

View file

@ -119,10 +119,10 @@ impl Editor {
let mut text = self.content.text(); let mut text = self.content.text();
if let Some(ending) = self.content.line_ending() { if let Some(ending) = self.content.line_ending()
if !text.ends_with(ending.as_str()) { && !text.ends_with(ending.as_str())
text.push_str(ending.as_str()); {
} text.push_str(ending.as_str());
} }
Task::perform( Task::perform(

View file

@ -71,11 +71,10 @@ impl Example {
} }
} }
Message::FocusAdjacent(direction) => { Message::FocusAdjacent(direction) => {
if let Some(pane) = self.focus { if let Some(pane) = self.focus
if let Some(adjacent) = self.panes.adjacent(pane, direction) && let Some(adjacent) = self.panes.adjacent(pane, direction)
{ {
self.focus = Some(adjacent); self.focus = Some(adjacent);
}
} }
} }
Message::Clicked(pane) => { Message::Clicked(pane) => {
@ -106,14 +105,12 @@ impl Example {
} }
} }
Message::CloseFocused => { Message::CloseFocused => {
if let Some(pane) = self.focus { if let Some(pane) = self.focus
if let Some(Pane { is_pinned, .. }) = self.panes.get(pane) { && let Some(Pane { is_pinned, .. }) = self.panes.get(pane)
if !is_pinned { && !is_pinned
if let Some((_, sibling)) = self.panes.close(pane) { && let Some((_, sibling)) = self.panes.close(pane)
self.focus = Some(sibling); {
} self.focus = Some(sibling);
}
}
} }
} }
} }

View file

@ -1 +1 @@
0e355b080ad33905145e9f70a3b29e2481197c8fc8f42491acd5358238ebbd5f 99f418007af163f172e163565f166da31015521e1bf7de95fa55cda2fb5a7db5

View file

@ -1 +0,0 @@
804a1bb6d49e3b3158463202960447d9e7820b967280f41dd0c34c00d3edf2c3

View file

@ -116,11 +116,11 @@ impl WebSocket {
let mut button = button(text("Send").height(40).align_y(Center)) let mut button = button(text("Send").height(40).align_y(Center))
.padding([0, 20]); .padding([0, 20]);
if matches!(self.state, State::Connected(_)) { if matches!(self.state, State::Connected(_))
if let Some(message) = echo::Message::new(&self.new_message) { && let Some(message) = echo::Message::new(&self.new_message)
input = input.on_submit(Message::Send(message.clone())); {
button = button.on_press(Message::Send(message)); input = input.on_submit(Message::Send(message.clone()));
} button = button.on_press(Message::Send(message));
} }
row![input, button].spacing(10).align_y(Center) row![input, button].spacing(10).align_y(Center)

View file

@ -321,10 +321,11 @@ impl editor::Editor for Editor {
); );
// Deselect if selection matches cursor position // Deselect if selection matches cursor position
if let Some((start, end)) = editor.selection_bounds() { if let Some((start, end)) = editor.selection_bounds()
if start.line == end.line && start.index == end.index { && start.line == end.line
editor.set_selection(cosmic_text::Selection::None); && start.index == end.index
} {
editor.set_selection(cosmic_text::Selection::None);
} }
} }
Action::SelectWord => { Action::SelectWord => {
@ -438,10 +439,11 @@ impl editor::Editor for Editor {
); );
// Deselect if selection matches cursor position // Deselect if selection matches cursor position
if let Some((start, end)) = editor.selection_bounds() { if let Some((start, end)) = editor.selection_bounds()
if start.line == end.line && start.index == end.index { && start.line == end.line
editor.set_selection(cosmic_text::Selection::None); && start.index == end.index
} {
editor.set_selection(cosmic_text::Selection::None);
} }
} }
Action::Scroll { lines } => { Action::Scroll { lines } => {

View file

@ -99,10 +99,8 @@ impl Cache {
self.map.retain(|k, memory| { self.map.retain(|k, memory| {
let retain = hits.contains(k); let retain = hits.contains(k);
if !retain { if !retain && let Memory::Device(entry) = memory {
if let Memory::Device(entry) = memory { atlas.remove(entry);
atlas.remove(entry);
}
} }
retain retain

View file

@ -320,11 +320,9 @@ where
| Event::Touch(touch::Event::FingerPressed { .. }) => { | Event::Touch(touch::Event::FingerPressed { .. }) => {
let mouse_over = cursor.is_over(layout.bounds()); let mouse_over = cursor.is_over(layout.bounds());
if mouse_over { if mouse_over && let Some(on_toggle) = &self.on_toggle {
if let Some(on_toggle) = &self.on_toggle { shell.publish((on_toggle)(!self.is_checked));
shell.publish((on_toggle)(!self.is_checked)); shell.capture_event();
shell.capture_event();
}
} }
} }
_ => {} _ => {}

View file

@ -599,17 +599,16 @@ where
if is_focused { if is_focused {
self.state.with_inner(|state| { self.state.with_inner(|state| {
if !started_focused { if !started_focused
if let Some(on_option_hovered) = &mut self.on_option_hovered && let Some(on_option_hovered) = &mut self.on_option_hovered
{ {
let hovered_option = menu.hovered_option.unwrap_or(0); let hovered_option = menu.hovered_option.unwrap_or(0);
if let Some(option) = if let Some(option) =
state.filtered_options.options.get(hovered_option) state.filtered_options.options.get(hovered_option)
{ {
shell.publish(on_option_hovered(option.clone())); shell.publish(on_option_hovered(option.clone()));
published_message_to_shell = true; published_message_to_shell = true;
}
} }
} }
@ -622,12 +621,11 @@ where
let shift_modifier = modifiers.shift(); let shift_modifier = modifiers.shift();
match (named_key, shift_modifier) { match (named_key, shift_modifier) {
(key::Named::Enter, _) => { (key::Named::Enter, _) => {
if let Some(index) = &menu.hovered_option { if let Some(index) = &menu.hovered_option
if let Some(option) = && let Some(option) =
state.filtered_options.options.get(*index) state.filtered_options.options.get(*index)
{ {
menu.new_selection = Some(option.clone()); menu.new_selection = Some(option.clone());
}
} }
shell.capture_event(); shell.capture_event();
@ -650,21 +648,19 @@ where
if let Some(on_option_hovered) = if let Some(on_option_hovered) =
&mut self.on_option_hovered &mut self.on_option_hovered
{ && let Some(option) =
if let Some(option) =
menu.hovered_option.and_then(|index| { menu.hovered_option.and_then(|index| {
state state
.filtered_options .filtered_options
.options .options
.get(index) .get(index)
}) })
{ {
// Notify the selection // Notify the selection
shell.publish((on_option_hovered)( shell.publish((on_option_hovered)(
option.clone(), option.clone(),
)); ));
published_message_to_shell = true; published_message_to_shell = true;
}
} }
shell.capture_event(); shell.capture_event();
@ -698,21 +694,19 @@ where
if let Some(on_option_hovered) = if let Some(on_option_hovered) =
&mut self.on_option_hovered &mut self.on_option_hovered
{ && let Some(option) =
if let Some(option) =
menu.hovered_option.and_then(|index| { menu.hovered_option.and_then(|index| {
state state
.filtered_options .filtered_options
.options .options
.get(index) .get(index)
}) })
{ {
// Notify the selection // Notify the selection
shell.publish((on_option_hovered)( shell.publish((on_option_hovered)(
option.clone(), option.clone(),
)); ));
published_message_to_shell = true; published_message_to_shell = true;
}
} }
shell.capture_event(); shell.capture_event();

View file

@ -377,24 +377,24 @@ fn update<Message: Clone, Theme, Renderer>(
shell.capture_event(); shell.capture_event();
} }
if let Some(position) = cursor_position { if let Some(position) = cursor_position
if let Some(message) = widget.on_double_click.as_ref() { && let Some(message) = widget.on_double_click.as_ref()
let new_click = mouse::Click::new( {
position, let new_click = mouse::Click::new(
mouse::Button::Left, position,
state.previous_click, mouse::Button::Left,
); state.previous_click,
);
if new_click.kind() == mouse::click::Kind::Double { if new_click.kind() == mouse::click::Kind::Double {
shell.publish(message.clone()); 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();
} }
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)) Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left))

View file

@ -407,13 +407,12 @@ where
) { ) {
match event { match event {
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => { Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
if cursor.is_over(layout.bounds()) { if cursor.is_over(layout.bounds())
if let Some(index) = *self.hovered_option { && let Some(index) = *self.hovered_option
if let Some(option) = self.options.get(index) { && let Some(option) = self.options.get(index)
shell.publish((self.on_selected)(option.clone())); {
shell.capture_event(); shell.publish((self.on_selected)(option.clone()));
} shell.capture_event();
}
} }
} }
Event::Mouse(mouse::Event::CursorMoved { .. }) => { Event::Mouse(mouse::Event::CursorMoved { .. }) => {
@ -431,19 +430,16 @@ where
let new_hovered_option = let new_hovered_option =
(cursor_position.y / option_height) as usize; (cursor_position.y / option_height) as usize;
if *self.hovered_option != Some(new_hovered_option) { if *self.hovered_option != Some(new_hovered_option)
if let Some(option) = && let Some(option) =
self.options.get(new_hovered_option) self.options.get(new_hovered_option)
{
if let Some(on_option_hovered) = self.on_option_hovered
{ {
if let Some(on_option_hovered) = shell.publish(on_option_hovered(option.clone()));
self.on_option_hovered
{
shell
.publish(on_option_hovered(option.clone()));
}
shell.request_redraw();
} }
shell.request_redraw();
} }
*self.hovered_option = Some(new_hovered_option); *self.hovered_option = Some(new_hovered_option);
@ -464,11 +460,11 @@ where
*self.hovered_option = *self.hovered_option =
Some((cursor_position.y / option_height) as usize); Some((cursor_position.y / option_height) as usize);
if let Some(index) = *self.hovered_option { if let Some(index) = *self.hovered_option
if let Some(option) = self.options.get(index) { && let Some(option) = self.options.get(index)
shell.publish((self.on_selected)(option.clone())); {
shell.capture_event(); shell.publish((self.on_selected)(option.clone()));
} shell.capture_event();
} }
} }
} }

View file

@ -593,56 +593,47 @@ where
Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left))
| Event::Touch(touch::Event::FingerLifted { .. }) | Event::Touch(touch::Event::FingerLifted { .. })
| Event::Touch(touch::Event::FingerLost { .. }) => { | Event::Touch(touch::Event::FingerLost { .. }) => {
if let Some((pane, origin)) = action.picked_pane() { if let Some((pane, origin)) = action.picked_pane()
if let Some(on_drag) = on_drag { && let Some(on_drag) = on_drag
if let Some(cursor_position) = cursor.position() { && let Some(cursor_position) = cursor.position()
if cursor_position.distance(origin) {
> DRAG_DEADBAND_DISTANCE if cursor_position.distance(origin) > DRAG_DEADBAND_DISTANCE
{ {
let event = if let Some(edge) = let event = if let Some(edge) =
in_edge(layout, cursor_position) 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 { DragEvent::Dropped {
pane, pane,
target: Target::Edge(edge), target: Target::Pane(target, region),
} }
} else { }
let dropped_region = self _ => DragEvent::Canceled { pane },
.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,
}));
} }
} };
shell.publish(on_drag(event));
} else {
shell.publish(on_drag(DragEvent::Canceled { pane }));
} }
} }
@ -660,34 +651,33 @@ where
bounds.size(), bounds.size(),
); );
if let Some((axis, rectangle, _)) = splits.get(&split) { if let Some((axis, rectangle, _)) = splits.get(&split)
if let Some(cursor_position) = cursor.position() { && let Some(cursor_position) = cursor.position()
let ratio = match axis { {
Axis::Horizontal => { let ratio = match axis {
let position = cursor_position.y Axis::Horizontal => {
- bounds.y let position = cursor_position.y
- rectangle.y; - bounds.y
- rectangle.y;
(position / rectangle.height) (position / rectangle.height)
.clamp(0.0, 1.0) .clamp(0.0, 1.0)
} }
Axis::Vertical => { Axis::Vertical => {
let position = cursor_position.x let position = cursor_position.x
- bounds.x - bounds.x
- rectangle.x; - rectangle.x;
(position / rectangle.width) (position / rectangle.width).clamp(0.0, 1.0)
.clamp(0.0, 1.0) }
} };
};
shell.publish(on_resize(ResizeEvent { shell.publish(on_resize(ResizeEvent {
split, split,
ratio, ratio,
})); }));
shell.capture_event(); shell.capture_event();
}
} }
} else if action.picked_pane().is_some() { } else if action.picked_pane().is_some() {
shell.request_redraw(); shell.request_redraw();
@ -889,24 +879,23 @@ where
viewport, viewport,
); );
if picked_pane.is_some() && pane_in_edge.is_none() { if picked_pane.is_some()
if let Some(region) = && pane_in_edge.is_none()
&& let Some(region) =
cursor.position().and_then(|cursor_position| { cursor.position().and_then(|cursor_position| {
layout_region(pane_layout, cursor_position) layout_region(pane_layout, cursor_position)
}) })
{ {
let bounds = let bounds = layout_region_bounds(pane_layout, region);
layout_region_bounds(pane_layout, region);
renderer.fill_quad( renderer.fill_quad(
renderer::Quad { renderer::Quad {
bounds, bounds,
border: style.hovered_region.border, border: style.hovered_region.border,
..renderer::Quad::default() ..renderer::Quad::default()
}, },
style.hovered_region.background, style.hovered_region.background,
); );
}
} }
} }
_ => { _ => {
@ -937,64 +926,62 @@ where
} }
// Render picked pane last // Render picked pane last
if let Some(((content, tree), origin, layout)) = render_picked_pane { if let Some(((content, tree), origin, layout)) = render_picked_pane
if let Some(cursor_position) = cursor.position() { && let Some(cursor_position) = cursor.position()
let bounds = layout.bounds(); {
let bounds = layout.bounds();
let translation = let translation = cursor_position - Point::new(origin.x, origin.y);
cursor_position - Point::new(origin.x, origin.y);
renderer.with_translation(translation, |renderer| { renderer.with_translation(translation, |renderer| {
renderer.with_layer(bounds, |renderer| { renderer.with_layer(bounds, |renderer| {
content.draw( content.draw(
tree, tree,
renderer, renderer,
theme, theme,
defaults, defaults,
layout, layout,
pane_cursor, pane_cursor,
viewport, viewport,
); );
});
}); });
} });
} }
if picked_pane.is_none() { if picked_pane.is_none()
if let Some((axis, split_region, is_picked)) = picked_split { && let Some((axis, split_region, is_picked)) = picked_split
let highlight = if is_picked { {
style.picked_split let highlight = if is_picked {
} else { style.picked_split
style.hovered_split } else {
}; style.hovered_split
};
renderer.fill_quad( renderer.fill_quad(
renderer::Quad { renderer::Quad {
bounds: match axis { bounds: match axis {
Axis::Horizontal => Rectangle { Axis::Horizontal => Rectangle {
x: split_region.x, x: split_region.x,
y: (split_region.y y: (split_region.y
+ (split_region.height - highlight.width) + (split_region.height - highlight.width)
/ 2.0) / 2.0)
.round(), .round(),
width: split_region.width, width: split_region.width,
height: highlight.width, height: highlight.width,
}, },
Axis::Vertical => Rectangle { Axis::Vertical => Rectangle {
x: (split_region.x x: (split_region.x
+ (split_region.width - highlight.width) + (split_region.width - highlight.width) / 2.0)
/ 2.0) .round(),
.round(), y: split_region.y,
y: split_region.y, width: highlight.width,
width: highlight.width, height: split_region.height,
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)); shell.publish(on_click(pane));
} }
if let Some(on_drag) = &on_drag { if let Some(on_drag) = &on_drag
if content.can_be_dragged_at(layout, cursor_position) { && content.can_be_dragged_at(layout, cursor_position)
*action = state::Action::Dragging { {
pane, *action = state::Action::Dragging {
origin: cursor_position, pane,
}; origin: cursor_position,
};
shell.publish(on_drag(DragEvent::Picked { pane })); shell.publish(on_drag(DragEvent::Picked { pane }));
}
} }
} }
} }

View file

@ -219,14 +219,14 @@ impl<T> State<T> {
pane: Pane, pane: Pane,
swap: bool, swap: bool,
) { ) {
if let Some((state, _)) = self.close(pane) { if let Some((state, _)) = self.close(pane)
if let Some((new_pane, _)) = self.split(axis, target, state) { && 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); // Ensure new node corresponds to original closed `Pane` for state continuity
self.relabel(new_pane, pane);
if swap { if swap {
self.swap(target, pane); self.swap(target, pane);
}
} }
} }
} }
@ -257,13 +257,12 @@ impl<T> State<T> {
pane: Pane, pane: Pane,
inverse: bool, inverse: bool,
) { ) {
if let Some((state, _)) = self.close(pane) { if let Some((state, _)) = self.close(pane)
if let Some((new_pane, _)) = && let Some((new_pane, _)) =
self.split_node(axis, None, state, inverse) self.split_node(axis, None, state, inverse)
{ {
// Ensure new node corresponds to original closed `Pane` for state continuity // Ensure new node corresponds to original closed `Pane` for state continuity
self.relabel(new_pane, pane); self.relabel(new_pane, pane);
}
} }
} }

View file

@ -174,38 +174,28 @@ where
let title_layout = children.next().unwrap(); let title_layout = children.next().unwrap();
let mut show_title = true; let mut show_title = true;
if let Some(controls) = &self.controls { if let Some(controls) = &self.controls
if show_controls || self.always_show_controls { && (show_controls || self.always_show_controls)
let controls_layout = children.next().unwrap(); {
if title_layout.bounds().width + controls_layout.bounds().width let controls_layout = children.next().unwrap();
> padded.bounds().width 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(compact) = controls.compact.as_ref() {
let compact_layout = children.next().unwrap();
compact.as_widget().draw( compact.as_widget().draw(
&tree.children[2], &tree.children[2],
renderer, renderer,
theme, theme,
&inherited_style, &inherited_style,
compact_layout, compact_layout,
cursor, cursor,
viewport, viewport,
); );
} else {
show_title = false;
controls.full.as_widget().draw(
&tree.children[1],
renderer,
theme,
&inherited_style,
controls_layout,
cursor,
viewport,
);
}
} else { } else {
show_title = false;
controls.full.as_widget().draw( controls.full.as_widget().draw(
&tree.children[1], &tree.children[1],
renderer, renderer,
@ -216,6 +206,16 @@ where
viewport, viewport,
); );
} }
} else {
controls.full.as_widget().draw(
&tree.children[1],
renderer,
theme,
&inherited_style,
controls_layout,
cursor,
viewport,
);
} }
} }

View file

@ -798,12 +798,11 @@ where
}, },
); );
if !had_input_method { if !had_input_method
if let InputMethod::Enabled { position, .. } = && let InputMethod::Enabled { position, .. } =
shell.input_method_mut() shell.input_method_mut()
{ {
*position = *position - translation; *position = *position - translation;
}
} }
}; };
@ -1091,23 +1090,22 @@ where
); );
} }
if let Some(scroller) = scrollbar.scroller { if let Some(scroller) = scrollbar.scroller
if scroller.bounds.width > 0.0 && scroller.bounds.width > 0.0
&& scroller.bounds.height > 0.0 && scroller.bounds.height > 0.0
&& (style.scroller.color != Color::TRANSPARENT && (style.scroller.color != Color::TRANSPARENT
|| (style.scroller.border.color || (style.scroller.border.color
!= Color::TRANSPARENT != Color::TRANSPARENT
&& style.scroller.border.width > 0.0)) && style.scroller.border.width > 0.0))
{ {
renderer.fill_quad( renderer.fill_quad(
renderer::Quad { renderer::Quad {
bounds: scroller.bounds, bounds: scroller.bounds,
border: style.scroller.border, border: style.scroller.border,
..renderer::Quad::default() ..renderer::Quad::default()
}, },
style.scroller.color, style.scroller.color,
); );
}
} }
}; };

View file

@ -127,10 +127,10 @@ where
} }
} }
if width == Length::Shrink { if width == Length::Shrink
if let Some(first) = columns.first_mut() { && let Some(first) = columns.first_mut()
first.width = Length::Fill; {
} first.width = Length::Fill;
} }
Self { Self {

View file

@ -689,22 +689,20 @@ where
} }
} }
Event::Window(window::Event::RedrawRequested(now)) => { Event::Window(window::Event::RedrawRequested(now)) => {
if let Some(focus) = &mut state.focus { if let Some(focus) = &mut state.focus
if focus.is_window_focused { && focus.is_window_focused
focus.now = *now; {
focus.now = *now;
let millis_until_redraw = let millis_until_redraw =
Focus::CURSOR_BLINK_INTERVAL_MILLIS Focus::CURSOR_BLINK_INTERVAL_MILLIS
- (focus.now - focus.updated_at).as_millis() - (focus.now - focus.updated_at).as_millis()
% Focus::CURSOR_BLINK_INTERVAL_MILLIS; % Focus::CURSOR_BLINK_INTERVAL_MILLIS;
shell.request_redraw_at( shell.request_redraw_at(
focus.now focus.now
+ Duration::from_millis( + Duration::from_millis(millis_until_redraw as u64),
millis_until_redraw as u64, );
),
);
}
} }
} }
_ => {} _ => {}

View file

@ -1247,12 +1247,12 @@ where
Event::Keyboard(keyboard::Event::KeyReleased { key, .. }) => { Event::Keyboard(keyboard::Event::KeyReleased { key, .. }) => {
let state = state::<Renderer>(tree); let state = state::<Renderer>(tree);
if state.is_focused.is_some() { if state.is_focused.is_some()
if let keyboard::Key::Character("v") = key.as_ref() { && let keyboard::Key::Character("v") = key.as_ref()
state.is_pasting = None; {
state.is_pasting = None;
shell.capture_event(); shell.capture_event();
}
} }
state.is_pasting = None; state.is_pasting = None;
@ -1328,32 +1328,31 @@ where
Event::Window(window::Event::RedrawRequested(now)) => { Event::Window(window::Event::RedrawRequested(now)) => {
let state = state::<Renderer>(tree); let state = state::<Renderer>(tree);
if let Some(focus) = &mut state.is_focused { if let Some(focus) = &mut state.is_focused
if focus.is_window_focused { && focus.is_window_focused
if matches!( {
state.cursor.state(&self.value), if matches!(
cursor::State::Index(_) state.cursor.state(&self.value),
) { cursor::State::Index(_)
focus.now = *now; ) {
focus.now = *now;
let millis_until_redraw = let millis_until_redraw = CURSOR_BLINK_INTERVAL_MILLIS
CURSOR_BLINK_INTERVAL_MILLIS - (*now - focus.updated_at).as_millis()
- (*now - focus.updated_at).as_millis() % CURSOR_BLINK_INTERVAL_MILLIS;
% CURSOR_BLINK_INTERVAL_MILLIS;
shell.request_redraw_at( shell.request_redraw_at(
*now + Duration::from_millis( *now + Duration::from_millis(
millis_until_redraw as u64, millis_until_redraw as u64,
), ),
); );
}
shell.request_input_method(&self.input_method(
state,
layout,
&self.value,
));
} }
shell.request_input_method(&self.input_method(
state,
layout,
&self.value,
));
} }
} }
_ => {} _ => {}

View file

@ -62,6 +62,7 @@ use window::WindowManager;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use std::borrow::Cow; use std::borrow::Cow;
use std::mem::ManuallyDrop; use std::mem::ManuallyDrop;
use std::slice;
use std::sync::Arc; use std::sync::Arc;
/// Runs a [`Program`] with the provided settings. /// Runs a [`Program`] with the provided settings.
@ -652,11 +653,11 @@ async fn run_instance<P>(
let now = Instant::now(); let now = Instant::now();
for (_id, window) in window_manager.iter_mut() { for (_id, window) in window_manager.iter_mut() {
if let Some(redraw_at) = window.redraw_at { if let Some(redraw_at) = window.redraw_at
if redraw_at <= now { && redraw_at <= now
window.raw.request_redraw(); {
window.redraw_at = None; window.raw.request_redraw();
} window.redraw_at = None;
} }
} }
@ -760,7 +761,7 @@ async fn run_instance<P>(
let draw_span = debug::draw(id); let draw_span = debug::draw(id);
let (ui_state, _) = ui.update( let (ui_state, _) = ui.update(
&[redraw_event.clone()], slice::from_ref(&redraw_event),
cursor, cursor,
&mut window.renderer, &mut window.renderer,
&mut clipboard, &mut clipboard,
@ -1346,17 +1347,14 @@ fn run_action<'a, P, C>(
} }
} }
window::Action::ShowSystemMenu(id) => { window::Action::ShowSystemMenu(id) => {
if let Some(window) = window_manager.get_mut(id) { if let Some(window) = window_manager.get_mut(id)
if let mouse::Cursor::Available(point) = && let mouse::Cursor::Available(point) =
window.state.cursor() window.state.cursor()
{ {
window.raw.show_window_menu( window.raw.show_window_menu(winit::dpi::LogicalPosition {
winit::dpi::LogicalPosition { x: point.x,
x: point.x, y: point.y,
y: point.y, });
},
);
}
} }
} }
window::Action::GetRawId(id, channel) => { window::Action::GetRawId(id, channel) => {
@ -1375,20 +1373,20 @@ fn run_action<'a, P, C>(
} }
} }
window::Action::Screenshot(id, channel) => { window::Action::Screenshot(id, channel) => {
if let Some(window) = window_manager.get_mut(id) { if let Some(window) = window_manager.get_mut(id)
if let Some(compositor) = compositor { && let Some(compositor) = compositor
let bytes = compositor.screenshot( {
&mut window.renderer, let bytes = compositor.screenshot(
window.state.viewport(), &mut window.renderer,
window.state.background_color(), window.state.viewport(),
); window.state.background_color(),
);
let _ = channel.send(core::window::Screenshot::new( let _ = channel.send(core::window::Screenshot::new(
bytes, bytes,
window.state.physical_size(), window.state.physical_size(),
window.state.viewport().scale_factor(), window.state.viewport().scale_factor(),
)); ));
}
} }
} }
window::Action::EnableMousePassthrough(id) => { window::Action::EnableMousePassthrough(id) => {