summaryrefslogtreecommitdiffstats
path: root/native/src/overlay/menu.rs
diff options
context:
space:
mode:
authorLibravatar anunge <aymeric.nunge@gmail.com>2021-02-12 21:52:20 +0200
committerLibravatar GitHub <noreply@github.com>2021-02-12 20:52:20 +0100
commit9e453843b26f2f73228316334298a4c608b2f050 (patch)
tree775e8a583079a1f54dd670581aa4664dc7bdcd42 /native/src/overlay/menu.rs
parent2f10a1f2a2c92aada5d167d82e008588256b590f (diff)
downloadiced-9e453843b26f2f73228316334298a4c608b2f050.tar.gz
iced-9e453843b26f2f73228316334298a4c608b2f050.tar.bz2
iced-9e453843b26f2f73228316334298a4c608b2f050.zip
Touch support for `PaneGrid` and `PickList` (#650)
* touch events properly parsed and converted to logical size, button working * scrolling with a nice touch * fixed application state level touch cursor. panel_grid is touchable now. * format glicthes fixes * format glitches * tight format * fixed pane grid * fixing with upstream * Remove unused `touch` module from `iced_core` * Remove unused `crate::text` import in `iced_native` * Remove redundant match branch in `iced_winit` * Keep removed line break in `UserInterface::update` * Compute `text_size` only when bounds contains cursor in `overlay::menu` Co-authored-by: Héctor Ramón Jiménez <hector0193@gmail.com>
Diffstat (limited to 'native/src/overlay/menu.rs')
-rw-r--r--native/src/overlay/menu.rs26
1 files changed, 24 insertions, 2 deletions
diff --git a/native/src/overlay/menu.rs b/native/src/overlay/menu.rs
index abac849f..5ad1391f 100644
--- a/native/src/overlay/menu.rs
+++ b/native/src/overlay/menu.rs
@@ -6,6 +6,7 @@ use crate::mouse;
use crate::overlay;
use crate::scrollable;
use crate::text;
+use crate::touch;
use crate::{
Clipboard, Container, Element, Hasher, Layout, Length, Point, Rectangle,
Scrollable, Size, Vector, Widget,
@@ -337,15 +338,36 @@ where
}
Event::Mouse(mouse::Event::CursorMoved { .. }) => {
let bounds = layout.bounds();
- let text_size =
- self.text_size.unwrap_or(renderer.default_size());
if bounds.contains(cursor_position) {
+ let text_size =
+ self.text_size.unwrap_or(renderer.default_size());
+
+ *self.hovered_option = Some(
+ ((cursor_position.y - bounds.y)
+ / f32::from(text_size + self.padding * 2))
+ as usize,
+ );
+ }
+ }
+ Event::Touch(touch::Event::FingerPressed { .. }) => {
+ let bounds = layout.bounds();
+
+ if bounds.contains(cursor_position) {
+ let text_size =
+ self.text_size.unwrap_or(renderer.default_size());
+
*self.hovered_option = Some(
((cursor_position.y - bounds.y)
/ f32::from(text_size + self.padding * 2))
as usize,
);
+
+ if let Some(index) = *self.hovered_option {
+ if let Some(option) = self.options.get(index) {
+ *self.last_selection = Some(option.clone());
+ }
+ }
}
}
_ => {}