From 8dbab600cfe5a6fcec4376b2b4ece7d95fb0dd25 Mon Sep 17 00:00:00 2001 From: StillGreen-san <40620628+StillGreen-san@users.noreply.github.com> Date: Thu, 29 Feb 2024 18:21:34 +0100 Subject: [PATCH 1/3] handle unavailable cursor position in draw_tab --- src/native/tab_bar.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/native/tab_bar.rs b/src/native/tab_bar.rs index 3d7c29bf..8864a4be 100644 --- a/src/native/tab_bar.rs +++ b/src/native/tab_bar.rs @@ -672,9 +672,9 @@ fn draw_tab( item.expect("Graphics: Layout should have an texts layout for an IconText") .bounds() } - let is_mouse_over = layout - .bounds() - .contains(cursor.position().unwrap_or_default()); + let is_mouse_over = cursor + .position() + .map_or(false, |pos| layout.bounds().contains(pos)); let style = if is_mouse_over { theme.hovered(style, is_selected) } else { From e719ba50a134e85d38c381f54ffce3d7a97cd47e Mon Sep 17 00:00:00 2001 From: StillGreen-san <40620628+StillGreen-san@users.noreply.github.com> Date: Thu, 29 Feb 2024 18:24:17 +0100 Subject: [PATCH 2/3] refactor bounds retrieval in draw_tab --- src/native/tab_bar.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/native/tab_bar.rs b/src/native/tab_bar.rs index 8864a4be..53faf14e 100644 --- a/src/native/tab_bar.rs +++ b/src/native/tab_bar.rs @@ -672,16 +672,15 @@ fn draw_tab( item.expect("Graphics: Layout should have an texts layout for an IconText") .bounds() } - let is_mouse_over = cursor - .position() - .map_or(false, |pos| layout.bounds().contains(pos)); + + let bounds = layout.bounds(); + let is_mouse_over = cursor.position().map_or(false, |pos| bounds.contains(pos)); let style = if is_mouse_over { theme.hovered(style, is_selected) } else { theme.active(style, is_selected) }; - let bounds = layout.bounds(); let mut children = layout.children(); let label_layout = children .next() From 2846a39899ae07b7785ff640446878ec206d46c8 Mon Sep 17 00:00:00 2001 From: StillGreen-san <40620628+StillGreen-san@users.noreply.github.com> Date: Thu, 29 Feb 2024 18:36:57 +0100 Subject: [PATCH 3/3] handle unavailable cursor position for remaining checks in tab_bar --- src/native/tab_bar.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/native/tab_bar.rs b/src/native/tab_bar.rs index 53faf14e..2125d94e 100644 --- a/src/native/tab_bar.rs +++ b/src/native/tab_bar.rs @@ -523,16 +523,16 @@ where match event { Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) | Event::Touch(touch::Event::FingerPressed { .. }) => { - if layout - .bounds() - .contains(cursor.position().unwrap_or_default()) + if cursor + .position() + .map_or(false, |pos| layout.bounds().contains(pos)) { let tabs_map: Vec = layout .children() .map(|layout| { - layout - .bounds() - .contains(cursor.position().unwrap_or_default()) + cursor + .position() + .map_or(false, |pos| layout.bounds().contains(pos)) }) .collect(); @@ -544,7 +544,7 @@ where let tab_layout = layout.children().nth(new_selected).expect("Native: Layout should have a tab layout at the selected index"); let cross_layout = tab_layout.children().nth(1).expect("Native: Layout should have a close layout"); - cross_layout.bounds().contains(cursor.position().unwrap_or_default()) + cursor.position().map_or(false, |pos| cross_layout.bounds().contains(pos) ) }) .map_or_else( || (self.on_select)(self.tab_indices[new_selected].clone()), @@ -572,9 +572,9 @@ where let mut mouse_interaction = mouse::Interaction::default(); for layout in children { - let is_mouse_over = layout - .bounds() - .contains(cursor.position().unwrap_or_default()); + let is_mouse_over = cursor + .position() + .map_or(false, |pos| layout.bounds().contains(pos)); let new_mouse_interaction = if is_mouse_over { mouse::Interaction::Pointer } else { @@ -601,7 +601,7 @@ where ) { let bounds = layout.bounds(); let children = layout.children(); - let is_mouse_over = bounds.contains(cursor.position().unwrap_or_default()); + let is_mouse_over = cursor.position().map_or(false, |pos| bounds.contains(pos)); let style_sheet = if is_mouse_over { theme.hovered(&self.style, false) } else {