pub enum Command {
Show 61 variants
Escape,
Activate,
Enter,
Space,
Tab,
ViewUp,
ViewDown,
Left,
Right,
Up,
Down,
WordLeft,
WordRight,
Home,
End,
DocHome,
DocEnd,
PageUp,
PageDown,
Snapshot,
ScrollLock,
Pause,
Insert,
Delete,
DelBack,
DelWord,
DelWordBack,
Deselect,
SelectAll,
Find,
FindReplace,
FindNext,
FindPrev,
Bold,
Italic,
Underline,
Link,
Cut,
Copy,
Paste,
Undo,
Redo,
New,
Open,
Save,
Print,
NavNext,
NavPrev,
NavParent,
NavDown,
TabNew,
TabNext,
TabPrev,
Help,
Rename,
Refresh,
Spelling,
Menu,
Fullscreen,
Close,
Exit,
}
Expand description
Command input (Event::Command
)
Command
events are mostly produced as a result of OS-specific keyboard
bindings; for example, Command::Copy
is produced by pressing
Command+C on MacOS or Ctrl+C on other platforms.
See crate::event::config::Shortcuts
for more on these bindings.
A Command
event does not necessarily come from keyboard input; for example
some menu widgets send Command::Activate
to trigger an entry as a result
of mouse input.
Most Command
entries represent an action (such as Copy
or FindNext
)
but some represent an important key whose action may be context-dependent
(e.g. Escape
, Space
).
Variants§
Escape
Escape key
Each press of this key should somehow relax control. It is expected that
widgets receiving this key repeatedly eventually (soon) have no more
use for this themselves and return it via Response::Unused
.
This is in some cases remapped to Command::Deselect
.
Activate
Programmatic activation
A synthetic event to activate widgets. Consider matching
Command::is_activate
or using using Event::on_activate
instead for generally applicable activation.
Enter
Return / enter key
This may insert a line-break or may activate something.
Space
Space bar key
Tab
Tab key
This key is used to insert (horizontal) tabulators as well as to navigate focus (in reverse when combined with Shift).
This is usually not sent to widgets but instead used for navigation.
ViewUp
Move view up without affecting selection
ViewDown
Move view down without affecting selection
Left
Move left
Right
Move right
Up
Move up
Down
Move down
WordLeft
Move left one word
WordRight
Move right one word
Home
Move to start (of the line)
End
Move to end (of the line)
DocHome
Move to start of the document
DocEnd
Move to end of the document
PageUp
Move up a page
PageDown
Move down a page
Snapshot
Capture a screenshot
ScrollLock
Lock output of screen
Pause
Pause key
Insert
Insert key
Delete
Delete forwards
DelBack
Delete backwards (Backspace key)
DelWord
Delete forwards one word
DelWordBack
Delete backwards one word
Deselect
Clear any selections
SelectAll
Select all contents
Find
Find (start)
FindReplace
Find and replace (start)
FindNext
Find next
FindPrev
Find previous
Bold
Make text bold
Italic
Make text italic
Underline
Underline text
Link
Insert a link
Cut
Copy to clipboard and clear
Copy
Copy to clipboard
Paste
Copy from clipboard
Undo
Undo the last action
Redo
Redo the last undone action
New
New document
Open
Open document
Save
Save document
Print document
Navigate forwards one page/item
Navigate backwards one page/item
Navigate to the parent item
May be used to browse “up” to a parent directory.
Navigate “down”
This is an opposite to NavParent
, and will mostly not be used.
TabNew
Open a new tab
TabNext
Navigate to next tab
TabPrev
Navigate to previous tab
Help
Show help
Rename
Rename
Refresh
Refresh
Spelling
Spell-check tool
Menu
Open the menu / activate the menubar
Fullscreen
Make view fullscreen
Close
Close window/tab/popup
Exit
Exit program (e.g. Ctrl+Q)
Implementations§
source§impl Command
impl Command
sourcepub fn new(vkey: VirtualKeyCode) -> Option<Self>
pub fn new(vkey: VirtualKeyCode) -> Option<Self>
Try constructing from a VirtualKeyCode
sourcepub fn is_activate(self) -> bool
pub fn is_activate(self) -> bool
True for “activation” commands
This matches:
Self::Activate
— programmatic activationSelf::Enter
— Enter and Return keysSelf::Space
— Space key
Examples found in repository?
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
pub fn on_activate<F: FnOnce(&mut EventMgr) -> Response>(
self,
mgr: &mut EventMgr,
id: WidgetId,
f: F,
) -> Response {
match self {
Event::Command(cmd) if cmd.is_activate() => f(mgr),
Event::PressStart { source, coord, .. } if source.is_primary() => {
mgr.grab_press(id, source, coord, GrabMode::Grab, None);
Response::Used
}
Event::PressMove { source, cur_id, .. } => {
let target = if id == cur_id { cur_id } else { None };
mgr.set_grab_depress(source, target);
Response::Used
}
Event::PressEnd {
end_id, success, ..
} if success && id == end_id => f(mgr),
Event::PressEnd { .. } => Response::Used,
_ => Response::Unused,
}
}
sourcepub fn suitable_for_sel_focus(self) -> bool
pub fn suitable_for_sel_focus(self) -> bool
Convert to selection-focus command
Certain limited commands may be sent to widgets with selection focus but not character or navigation focus.
Examples found in repository?
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
fn start_key_event(&mut self, widget: &mut dyn Widget, vkey: VirtualKeyCode, scancode: u32) {
log::trace!(
"start_key_event: widget={}, vkey={vkey:?}, scancode={scancode}",
widget.id()
);
use VirtualKeyCode as VK;
let opt_command = self.config.shortcuts(|s| s.get(self.modifiers, vkey));
if let Some(cmd) = opt_command {
let mut targets = vec![];
let mut send = |_self: &mut Self, id: WidgetId, cmd| -> bool {
if !targets.contains(&id) {
let used = _self.send_event(widget, id.clone(), Event::Command(cmd));
if used {
_self.add_key_depress(scancode, id.clone());
}
targets.push(id);
used
} else {
false
}
};
if self.char_focus || cmd.suitable_for_sel_focus() {
if let Some(id) = self.sel_focus.clone() {
if send(self, id, cmd) {
return;
}
}
}
if !self.modifiers.alt() {
if let Some(id) = self.nav_focus.clone() {
if send(self, id, cmd) {
return;
}
}
}
if let Some(id) = self.popups.last().map(|popup| popup.1.parent.clone()) {
if send(self, id, cmd) {
return;
}
}
if let Some(id) = self.nav_fallback.clone() {
if send(self, id, cmd) {
return;
}
}
}
// Next priority goes to accelerator keys when Alt is held or alt_bypass is true
let mut target = None;
let mut n = 0;
for (i, id) in (self.popups.iter().rev())
.map(|(_, popup, _)| popup.parent.clone())
.chain(std::iter::once(widget.id()))
.enumerate()
{
if let Some(layer) = self.accel_layers.get(&id) {
// but only when Alt is held or alt-bypass is enabled:
if self.modifiers == ModifiersState::ALT
|| layer.0 && self.modifiers == ModifiersState::empty()
{
if let Some(id) = layer.1.get(&vkey).cloned() {
target = Some(id);
n = i;
break;
}
}
}
}
// If we found a key binding below the top layer, we should close everything above
if n > 0 {
let len = self.popups.len();
for i in ((len - n)..len).rev() {
let id = self.popups[i].0;
self.close_window(id, false);
}
}
if let Some(id) = target {
if widget
.find_widget(&id)
.map(|w| w.navigable())
.unwrap_or(false)
{
self.set_nav_focus(id.clone(), true);
}
self.add_key_depress(scancode, id.clone());
self.send_event(widget, id, Event::Command(Command::Activate));
} else if self.config.nav_focus && vkey == VK::Tab {
self.clear_char_focus();
let shift = self.modifiers.shift();
self.next_nav_focus(widget, shift, true);
} else if vkey == VK::Escape {
if let Some(id) = self.popups.last().map(|(id, _, _)| *id) {
self.close_window(id, true);
}
}
}
sourcepub fn as_direction(self) -> Option<Direction>
pub fn as_direction(self) -> Option<Direction>
Convert arrow keys to a direction
Trait Implementations§
source§impl<'de> Deserialize<'de> for Command
impl<'de> Deserialize<'de> for Command
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl PartialEq<Command> for Command
impl PartialEq<Command> for Command
impl Copy for Command
impl Eq for Command
impl StructuralEq for Command
impl StructuralPartialEq for Command
Auto Trait Implementations§
impl RefUnwindSafe for Command
impl Send for Command
impl Sync for Command
impl Unpin for Command
impl UnwindSafe for Command
Blanket Implementations§
source§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.