-
I'm looking for a way to use shortcuts with Consuming the shortcut doesnt seem to block the input from going into the textedit. I also tried Example of not working code: egui::CentralPanel::default().show(ctx, |ui| {
ui.input_mut(|i| {
let shortcut = i.consume_shortcut(&egui::KeyboardShortcut { modifiers: Modifiers::NONE, logical_key: egui::Key::Num1 });
});
egui::ScrollArea::vertical().show(ui, |ui| {
ui.add_sized(
ui.available_size(),
egui::TextEdit::multiline(&mut self.text).lock_focus(true),
);
});
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
nvm, managed to get this working. Overwriting the text input events is what is required here. If anyone else finds this: Destroying all events when the shortcut is triggered: if shortcut {
i.events = vec![];
} egui::CentralPanel::default().show(ctx, |ui| {
ui.input_mut(|i| {
if i.consume_shortcut(&egui::KeyboardShortcut { modifiers: Modifiers::NONE, logical_key: egui::Key::Num1 }) {
i.events = vec![];
}
});
egui::ScrollArea::vertical().show(ui, |ui| {
ui.add_sized(
ui.available_size(),
egui::TextEdit::multiline(&mut self.text).lock_focus(true),
);
});
}); And i.events = i.events
.iter()
.filter(|x| match x {
egui::Event::Text(t) => {
if t == "1" {
return false;
} else {
return true;
}
}
_ => return true,
})
.map(|x| x.to_owned())
.collect(); |
Beta Was this translation helpful? Give feedback.
nvm, managed to get this working. Overwriting the text input events is what is required here.
If anyone else finds this:
Destroying all events when the shortcut is triggered:
And
i.events
can be filtered for specifically …