Replies: 2 comments 4 replies
-
Please check that it is in the form below.
|
Beta Was this translation helpful? Give feedback.
2 replies
-
Would something like this work? It gets focus when you click on it or tab until you reach it, and it loses focus when you click away or press Escape, like the TextEdit. impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
let mut size = ui.available_size();
size.y /= 3.0;
focusable_rect(ui, size, Color32::RED);
focusable_rect(ui, size, Color32::GREEN);
focusable_rect(ui, size, Color32::BLUE);
});
}
}
fn focusable_rect(
ui: &mut egui::Ui,
size: impl Into<egui::Vec2>,
color: egui::Color32,
) -> Response {
let r = ui.allocate_response(size.into(), Sense::click());
if r.clicked() {
r.request_focus();
}
if r.has_focus() {
ui.painter().rect_filled(r.rect, 0.0, color);
} else {
ui.painter()
.rect_filled(r.rect, 0.0, color.gamma_multiply(0.1));
}
r
} Screencast.from.2024-07-14.11-59-49.mp4 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a window that I treat as a raw paint canvas. I want to receive kb events (and have the window highlighted to show its accepting keystrokes). I dont expect egui to do anything with the keys, I grab them myself. At the moment I grab them when I see nobody else has focus (which is a bit lame). I did this
In the draw of the window area (ui is the window's .show ui). But I still dont get the focus
Beta Was this translation helpful? Give feedback.
All reactions