pub struct Modifiers { /* private fields */ }
Expand description
Describes keyboard modifiers event.
Implementations§
Source§impl Modifiers
impl Modifiers
Sourcepub fn state(&self) -> ModifiersState
pub fn state(&self) -> ModifiersState
The state of the modifiers.
Examples found in repository?
examples/window.rs (line 376)
334 fn window_event(
335 &mut self,
336 event_loop: &ActiveEventLoop,
337 window_id: WindowId,
338 event: WindowEvent,
339 ) {
340 let window = match self.windows.get_mut(&window_id) {
341 Some(window) => window,
342 None => return,
343 };
344
345 match event {
346 WindowEvent::Resized(size) => {
347 window.resize(size);
348 }
349 WindowEvent::Focused(focused) => {
350 if focused {
351 info!("Window={window_id:?} focused");
352 } else {
353 info!("Window={window_id:?} unfocused");
354 }
355 }
356 WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
357 info!("Window={window_id:?} changed scale to {scale_factor}");
358 }
359 WindowEvent::ThemeChanged(theme) => {
360 info!("Theme changed to {theme:?}");
361 window.set_theme(theme);
362 }
363 WindowEvent::RedrawRequested => {
364 if let Err(err) = window.draw() {
365 error!("Error drawing window: {err}");
366 }
367 }
368 WindowEvent::Occluded(occluded) => {
369 window.set_occluded(occluded);
370 }
371 WindowEvent::CloseRequested => {
372 info!("Closing Window={window_id:?}");
373 self.windows.remove(&window_id);
374 }
375 WindowEvent::ModifiersChanged(modifiers) => {
376 window.modifiers = modifiers.state();
377 info!("Modifiers changed to {:?}", window.modifiers);
378 }
379 WindowEvent::MouseWheel { delta, .. } => match delta {
380 MouseScrollDelta::LineDelta(x, y) => {
381 info!("Mouse wheel Line Delta: ({x},{y})");
382 }
383 MouseScrollDelta::PixelDelta(px) => {
384 info!("Mouse wheel Pixel Delta: ({},{})", px.x, px.y);
385 }
386 },
387 WindowEvent::KeyboardInput {
388 event,
389 is_synthetic: false,
390 ..
391 } => {
392 let mods = window.modifiers;
393
394 // Dispatch actions only on press.
395 if event.state.is_pressed() {
396 let action = if let Key::Character(ch) = event.logical_key.as_ref() {
397 Self::process_key_binding(&ch.to_uppercase(), &mods)
398 } else {
399 None
400 };
401
402 if let Some(action) = action {
403 self.handle_action(event_loop, window_id, action);
404 }
405 }
406 }
407 WindowEvent::MouseInput { button, state, .. } => {
408 let mods = window.modifiers;
409 if let Some(action) = state
410 .is_pressed()
411 .then(|| Self::process_mouse_binding(button, &mods))
412 .flatten()
413 {
414 self.handle_action(event_loop, window_id, action);
415 }
416 }
417 WindowEvent::CursorLeft { .. } => {
418 info!("Cursor left Window={window_id:?}");
419 window.cursor_left();
420 }
421 WindowEvent::CursorMoved { position, .. } => {
422 info!("Moved cursor to {position:?}");
423 window.cursor_moved(position);
424 }
425 WindowEvent::ActivationTokenDone { token: _token, .. } => {
426 #[cfg(any(x11_platform, wayland_platform))]
427 {
428 startup_notify::set_activation_token_env(_token);
429 if let Err(err) = self.create_window(event_loop, None) {
430 error!("Error creating new window: {err}");
431 }
432 }
433 }
434 WindowEvent::Ime(event) => match event {
435 Ime::Enabled => info!("IME enabled for Window={window_id:?}"),
436 Ime::Preedit(text, caret_pos) => {
437 info!("Preedit: {}, with caret at {:?}", text, caret_pos);
438 }
439 Ime::Commit(text) => {
440 info!("Committed: {}", text);
441 }
442 Ime::Disabled => info!("IME disabled for Window={window_id:?}"),
443 },
444 WindowEvent::PinchGesture { delta, .. } => {
445 window.zoom += delta;
446 let zoom = window.zoom;
447 if delta > 0.0 {
448 info!("Zoomed in {delta:.5} (now: {zoom:.5})");
449 } else {
450 info!("Zoomed out {delta:.5} (now: {zoom:.5})");
451 }
452 }
453 WindowEvent::RotationGesture { delta, .. } => {
454 window.rotated += delta;
455 let rotated = window.rotated;
456 if delta > 0.0 {
457 info!("Rotated counterclockwise {delta:.5} (now: {rotated:.5})");
458 } else {
459 info!("Rotated clockwise {delta:.5} (now: {rotated:.5})");
460 }
461 }
462 WindowEvent::PanGesture { delta, phase, .. } => {
463 window.panned.x += delta.x;
464 window.panned.y += delta.y;
465 info!("Panned ({delta:?})) (now: {:?}), {phase:?}", window.panned);
466 }
467 WindowEvent::DoubleTapGesture { .. } => {
468 info!("Smart zoom");
469 }
470 WindowEvent::TouchpadPressure { .. }
471 | WindowEvent::HoveredFileCancelled
472 | WindowEvent::KeyboardInput { .. }
473 | WindowEvent::CursorEntered { .. }
474 | WindowEvent::AxisMotion { .. }
475 | WindowEvent::DroppedFile(_)
476 | WindowEvent::HoveredFile(_)
477 | WindowEvent::Destroyed
478 | WindowEvent::Touch(_)
479 | WindowEvent::Moved(_) => (),
480 }
481 }
Sourcepub fn lshift_state(&self) -> ModifiersKeyState
pub fn lshift_state(&self) -> ModifiersKeyState
The state of the left shift key.
Sourcepub fn rshift_state(&self) -> ModifiersKeyState
pub fn rshift_state(&self) -> ModifiersKeyState
The state of the right shift key.
Sourcepub fn lalt_state(&self) -> ModifiersKeyState
pub fn lalt_state(&self) -> ModifiersKeyState
The state of the left alt key.
Sourcepub fn ralt_state(&self) -> ModifiersKeyState
pub fn ralt_state(&self) -> ModifiersKeyState
The state of the right alt key.
Sourcepub fn lcontrol_state(&self) -> ModifiersKeyState
pub fn lcontrol_state(&self) -> ModifiersKeyState
The state of the left control key.
Sourcepub fn rcontrol_state(&self) -> ModifiersKeyState
pub fn rcontrol_state(&self) -> ModifiersKeyState
The state of the right control key.
Sourcepub fn lsuper_state(&self) -> ModifiersKeyState
pub fn lsuper_state(&self) -> ModifiersKeyState
The state of the left super key.
Sourcepub fn rsuper_state(&self) -> ModifiersKeyState
pub fn rsuper_state(&self) -> ModifiersKeyState
The state of the right super key.
Trait Implementations§
Source§impl From<ModifiersState> for Modifiers
impl From<ModifiersState> for Modifiers
Source§fn from(value: ModifiersState) -> Self
fn from(value: ModifiersState) -> Self
Converts to this type from the input type.
impl Copy for Modifiers
impl Eq for Modifiers
impl StructuralPartialEq for Modifiers
Auto Trait Implementations§
impl Freeze for Modifiers
impl RefUnwindSafe for Modifiers
impl Send for Modifiers
impl Sync for Modifiers
impl Unpin for Modifiers
impl UnwindSafe for Modifiers
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.