pub struct Modifiers {
pub shift: bool,
pub alt: bool,
pub ctrl: bool,
}Expand description
Modifier keys held down during an event.
Fields§
§shift: boolShift was held.
alt: boolAlt (Option on macOS) was held.
ctrl: boolCtrl was held.
Implementations§
Source§impl Modifiers
impl Modifiers
Sourcepub fn is_none(self) -> bool
pub fn is_none(self) -> bool
Whether no modifier is held.
Examples found in repository?
examples/paint.rs (line 150)
143 fn handle(&mut self, event: &Event) -> bool {
144 match event {
145 Event::Key(key) => {
146 if key.is_char('q') || key.is_ctrl('c') {
147 return false;
148 }
149 match key.code {
150 KeyCode::Char(c @ '1'..='8') if key.modifiers.is_none() => {
151 self.brush = c as usize - '1' as usize;
152 self.draw_status();
153 }
154 KeyCode::Char('c') if key.modifiers.is_none() => self.clear(),
155 _ => {}
156 }
157 }
158 Event::Mouse(mouse) => match mouse.kind {
159 MouseKind::Down(MouseButton::Left) | MouseKind::Drag(MouseButton::Left) => {
160 self.begin_stroke_if_pressed(mouse.kind);
161 self.stroke(mouse.x, mouse.y, PALETTE[self.brush]);
162 }
163 MouseKind::Down(MouseButton::Right) | MouseKind::Drag(MouseButton::Right) => {
164 self.begin_stroke_if_pressed(mouse.kind);
165 self.stroke(mouse.x, mouse.y, Colour::Black);
166 }
167 MouseKind::Up(_) => self.last = None,
168 MouseKind::ScrollUp => {
169 self.brush = (self.brush + PALETTE.len() - 1) % PALETTE.len();
170 self.draw_status();
171 }
172 MouseKind::ScrollDown => {
173 self.brush = (self.brush + 1) % PALETTE.len();
174 self.draw_status();
175 }
176 _ => {}
177 },
178 // Pasted text is not typing: ignore it, so pasting `cargo run q` can
179 // neither clear the canvas nor quit. More kinds of event may come.
180 _ => {}
181 }
182 true
183 }Trait Implementations§
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 UnsafeUnpin 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