1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 05:40:03 -04:00

Output events when widgets gain keyboard focus

Part of https://github.com/emilk/egui/issues/167
This commit is contained in:
Emil Ernerfeldt
2021-03-07 19:32:27 +01:00
parent a370339db7
commit cd4c07e09a
15 changed files with 140 additions and 12 deletions

View File

@@ -30,6 +30,11 @@ pub fn toggle_ui(ui: &mut egui::Ui, on: &mut bool) -> egui::Response {
// This is where we get a region of the screen assigned.
// We also tell the Ui to sense clicks in the allocated region.
let (rect, mut response) = ui.allocate_exact_size(desired_size, egui::Sense::click());
if response.gained_kb_focus() {
// Inform accessibility systems that the widget is selected:
ui.output()
.push_gained_focus_event(egui::WidgetType::Checkbox, "");
}
// 3. Interact: Time to check for clicks!
if response.clicked() {
@@ -67,6 +72,10 @@ pub fn toggle_ui(ui: &mut egui::Ui, on: &mut bool) -> egui::Response {
fn toggle_ui_compact(ui: &mut egui::Ui, on: &mut bool) -> egui::Response {
let desired_size = ui.spacing().interact_size.y * egui::vec2(2.0, 1.0);
let (rect, mut response) = ui.allocate_exact_size(desired_size, egui::Sense::click());
if response.gained_kb_focus() {
ui.output()
.push_gained_focus_event(egui::WidgetType::Checkbox, "");
}
if response.clicked() {
*on = !*on;
response.mark_changed();