Skip to content

Commit

Permalink
Allow ESC to reset UI (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryevdv authored Oct 12, 2023
1 parent 2f8dfcd commit 6417711
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,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 @@ -1222,7 +1222,7 @@ impl SearchState {
.and_modify(|_| {
result = false;
})
.or_insert_with(BTreeMap::new);
.or_default();
result
}

Expand Down Expand Up @@ -1258,13 +1258,8 @@ impl SearchState {
let level1_index = entry_id.slot_index(1).unwrap();
let level2_index = entry_id.slot_index(2).unwrap();

let level0_subtree = self
.entry_tree
.entry(level0_index)
.or_insert_with(BTreeMap::new);
let level1_subtree = level0_subtree
.entry(level1_index)
.or_insert_with(BTreeSet::new);
let level0_subtree = self.entry_tree.entry(level0_index).or_default();
let level1_subtree = level0_subtree.entry(level1_index).or_default();
level1_subtree.insert(level2_index);
}
}
Expand Down Expand Up @@ -1820,7 +1815,14 @@ 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.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 @@ -1837,6 +1839,7 @@ impl ProfApp {
ShrinkVertical,
ResetVertical,
ToggleControls,
ResetUI,
NoAction,
}
let action = ctx.input(|i| {
Expand Down Expand Up @@ -1874,6 +1877,8 @@ impl ProfApp {
}
} else if i.key_pressed(egui::Key::H) {
Actions::ToggleControls
} else if i.key_pressed(egui::Key::Escape) {
Actions::ResetUI
} else if i.key_pressed(egui::Key::ArrowLeft) {
Actions::Pan(Percentage::from(5), PanDirection::Left)
} else if i.key_pressed(egui::Key::ArrowRight) {
Expand All @@ -1893,6 +1898,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 @@ -2416,7 +2422,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 6417711

Please sign in to comment.