Change force to be Option<f32> instead of f32 (#3240)

This commit is contained in:
lucasmerlin 2023-08-12 13:50:40 +02:00 committed by GitHub
parent 6633ecce64
commit 1036cb1f7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 11 deletions

View File

@ -68,7 +68,7 @@ pub fn push_touches(runner: &mut AppRunner, phase: egui::TouchPhase, event: &web
id: egui::TouchId::from(touch.identifier()), id: egui::TouchId::from(touch.identifier()),
phase, phase,
pos: pos_from_touch(canvas_origin, &touch), pos: pos_from_touch(canvas_origin, &touch),
force: touch.force(), force: Some(touch.force()),
}); });
} }
} }

View File

@ -441,7 +441,7 @@ impl State {
id: egui::TouchId(0), id: egui::TouchId(0),
phase: egui::TouchPhase::Start, phase: egui::TouchPhase::Start,
pos, pos,
force: 0.0, force: None,
}); });
} else { } else {
self.any_pointer_button_down = false; self.any_pointer_button_down = false;
@ -453,7 +453,7 @@ impl State {
id: egui::TouchId(0), id: egui::TouchId(0),
phase: egui::TouchPhase::End, phase: egui::TouchPhase::End,
pos, pos,
force: 0.0, force: None,
}); });
}; };
} }
@ -479,7 +479,7 @@ impl State {
id: egui::TouchId(0), id: egui::TouchId(0),
phase: egui::TouchPhase::Move, phase: egui::TouchPhase::Move,
pos: pos_in_points, pos: pos_in_points,
force: 0.0, force: None,
}); });
} }
} else { } else {
@ -505,13 +505,13 @@ impl State {
touch.location.y as f32 / self.pixels_per_point(), touch.location.y as f32 / self.pixels_per_point(),
), ),
force: match touch.force { force: match touch.force {
Some(winit::event::Force::Normalized(force)) => force as f32, Some(winit::event::Force::Normalized(force)) => Some(force as f32),
Some(winit::event::Force::Calibrated { Some(winit::event::Force::Calibrated {
force, force,
max_possible_force, max_possible_force,
.. ..
}) => (force / max_possible_force) as f32, }) => Some((force / max_possible_force) as f32),
None => 0_f32, None => None,
}, },
}); });
// If we're not yet translating a touch or we're translating this very // If we're not yet translating a touch or we're translating this very

View File

@ -274,10 +274,10 @@ pub enum Event {
/// Position of the touch (or where the touch was last detected) /// Position of the touch (or where the touch was last detected)
pos: Pos2, pos: Pos2,
/// Describes how hard the touch device was pressed. May always be `0` if the platform does /// Describes how hard the touch device was pressed. May always be `None` if the platform does
/// not support pressure sensitivity. /// not support pressure sensitivity.
/// The value is in the range from 0.0 (no pressure) to 1.0 (maximum pressure). /// The value is in the range from 0.0 (no pressure) to 1.0 (maximum pressure).
force: f32, force: Option<f32>,
}, },
/// A raw mouse wheel event as sent by the backend (minus the z coordinate), /// A raw mouse wheel event as sent by the backend (minus the z coordinate),

View File

@ -118,7 +118,7 @@ struct ActiveTouch {
/// ///
/// Note that a value of 0.0 either indicates a very light touch, or it means that the device /// Note that a value of 0.0 either indicates a very light touch, or it means that the device
/// is not capable of measuring the touch force. /// is not capable of measuring the touch force.
force: f32, force: Option<f32>,
} }
impl TouchState { impl TouchState {
@ -249,7 +249,7 @@ impl TouchState {
// first pass: calculate force and center of touch positions: // first pass: calculate force and center of touch positions:
for touch in self.active_touches.values() { for touch in self.active_touches.values() {
state.avg_force += touch.force; state.avg_force += touch.force.unwrap_or(0.0);
state.avg_pos.x += touch.pos.x; state.avg_pos.x += touch.pos.x;
state.avg_pos.y += touch.pos.y; state.avg_pos.y += touch.pos.y;
} }