Skip to content

Commit

Permalink
Allow ESC to reset UI
Browse files Browse the repository at this point in the history
  • Loading branch information
bryevdv committed Oct 10, 2023
1 parent f0d1d37 commit 37f45e0
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ impl SearchState {
if !self.result_cache.contains_key(entry.entry_id()) {
self.result_cache
.entry(entry.entry_id().clone())
.or_insert_with(BTreeMap::new);
.or_default();
}

// Always recurse into tiles, because results can be fetched
Expand All @@ -1214,7 +1214,7 @@ impl SearchState {
.and_modify(|_| {
result = false;
})
.or_insert_with(BTreeMap::new);
.or_default();
result
}

Expand Down Expand Up @@ -1253,10 +1253,10 @@ impl SearchState {
let level0_subtree = self
.entry_tree
.entry(level0_index)
.or_insert_with(BTreeMap::new);
.or_default();
let level1_subtree = level0_subtree
.entry(level1_index)
.or_insert_with(BTreeSet::new);
.or_default();
level1_subtree.insert(level2_index);
}
}
Expand Down Expand Up @@ -1771,7 +1771,15 @@ impl ProfApp {
cx.scale_factor = 1.0;
}

fn keyboard(ctx: &egui::Context, cx: &mut Context) {
fn reset_ui(cx: &mut Context, windows: &mut [Window]) {
cx.show_controls = false;
for window in windows.iter_mut() {
window.config.kind_filter.clear();
window.config.items_selected.clear();
}
}

fn keyboard(ctx: &egui::Context, cx: &mut Context, windows: &mut [Window]) {
// Focus is elsewhere, don't check any keys
if ctx.memory(|m| m.focus().is_some()) {
return;
Expand All @@ -1787,6 +1795,7 @@ impl ProfApp {
ShrinkVertical,
ResetVertical,
ToggleControls,
ResetUI,
NoAction,
}
let action = ctx.input(|i| {
Expand Down Expand Up @@ -1816,6 +1825,8 @@ impl ProfApp {
}
} else if i.key_pressed(egui::Key::H) {
Actions::ToggleControls
} else if i.key_pressed(egui::Key::Escape) {
Actions::ResetUI
} else {
Actions::NoAction
}
Expand All @@ -1830,6 +1841,7 @@ impl ProfApp {
Actions::ShrinkVertical => ProfApp::multiply_scale_factor(cx, 0.5),
Actions::ResetVertical => ProfApp::reset_scale_factor(cx),
Actions::ToggleControls => cx.show_controls = !cx.show_controls,
Actions::ResetUI => ProfApp::reset_ui(cx, windows),
Actions::NoAction => {}
}
}
Expand Down Expand Up @@ -2351,7 +2363,7 @@ impl eframe::App for ProfApp {
}
}

Self::keyboard(ctx, cx);
Self::keyboard(ctx, cx, windows);

// Keep repainting as long as we have outstanding requests.
if !pending_data_sources.is_empty()
Expand Down

0 comments on commit 37f45e0

Please sign in to comment.