Skip to content

Commit 912c08e

Browse files
committed
snowcap: Update cursor position on touch event
Iced widgets ignores the touch position when updating widget, leading to some confusing behavior. This is just a workaround that update the surface "cursor position" since it's used by mouse_area and buttons.
1 parent 9364f6d commit 912c08e

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

snowcap/src/handlers/pointer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ impl PointerHandler for State {
2323
return;
2424
};
2525

26+
surface.pointer_location = Some(event.position);
27+
2628
let iced_event = match event.kind {
2729
PointerEventKind::Enter { serial: _ } => {
28-
surface.pointer_location = Some(event.position);
2930
iced::Event::Mouse(iced::mouse::Event::CursorEntered)
3031
}
3132
PointerEventKind::Leave { serial: _ } => {
3233
surface.pointer_location = None;
3334
iced::Event::Mouse(iced::mouse::Event::CursorLeft)
3435
}
3536
PointerEventKind::Motion { time: _ } => {
36-
surface.pointer_location = Some(event.position);
3737
iced::Event::Mouse(iced::mouse::Event::CursorMoved {
3838
position: iced::Point {
3939
x: event.position.0 as f32,

snowcap/src/handlers/touch.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,11 @@ impl State {
103103
y: touch.last_pos.1 as f32,
104104
};
105105

106-
let event = iced::Event::Touch(iced::touch::Event::FingerPressed { id, position });
106+
// HACK: Iced ignores the touch locations, so we're overriding the cursor position here.
107+
// FIXME: Once iced gets correct touch handling, remove this.
108+
surface.pointer_location = Some(touch.last_pos);
107109

110+
let event = iced::Event::Touch(iced::touch::Event::FingerPressed { id, position });
108111
surface.widgets.queue_event(event);
109112
self.active_touches.push(touch);
110113
}
@@ -127,14 +130,17 @@ impl State {
127130
return;
128131
};
129132

133+
// HACK: Iced ignores the touch locations, so we're overriding the cursor position here.
134+
// FIXME: Once iced gets correct touch handling, remove this.
135+
surface.pointer_location = Some(touch.last_pos);
136+
130137
let id = iced::touch::Finger(touch.id as u64);
131138
let position = iced::Point {
132139
x: touch.last_pos.0 as f32,
133140
y: touch.last_pos.1 as f32,
134141
};
135142

136143
let event = iced::Event::Touch(iced::touch::Event::FingerMoved { id, position });
137-
138144
surface.widgets.queue_event(event);
139145
}
140146

@@ -149,14 +155,17 @@ impl State {
149155
return;
150156
};
151157

158+
// HACK: Iced ignores the touch locations, so we're overriding the cursor position here.
159+
// FIXME: Once iced gets correct touch handling, remove this.
160+
surface.pointer_location = Some(touch.last_pos);
161+
152162
let id = iced::touch::Finger(touch.id as u64);
153163
let position = iced::Point {
154164
x: touch.last_pos.0 as f32,
155165
y: touch.last_pos.1 as f32,
156166
};
157167

158168
let event = iced::Event::Touch(iced::touch::Event::FingerLifted { id, position });
159-
160169
surface.widgets.queue_event(event);
161170
}
162171

@@ -178,7 +187,6 @@ impl State {
178187
};
179188

180189
let event = iced::Event::Touch(iced::touch::Event::FingerLost { id, position });
181-
182190
surface.widgets.queue_event(event);
183191
}
184192
}

0 commit comments

Comments
 (0)