-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add buttons and shortcuts for zooming the whole GUI #265
Changes from all commits
76602e8
bd1394c
89a44c6
c8266da
7e882b8
2d81b2f
c3f9170
bded61f
b6dd60c
6ff58f8
bae00d1
22d9787
9999ad5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,20 +189,8 @@ impl App { | |
pub fn promise_exists(&mut self, name: impl AsRef<str>) -> bool { | ||
self.pending_promises.contains_key(name.as_ref()) | ||
} | ||
} | ||
|
||
impl eframe::App for App { | ||
fn save(&mut self, storage: &mut dyn eframe::Storage) { | ||
eframe::set_value(storage, eframe::APP_KEY, &self.state); | ||
} | ||
|
||
fn update(&mut self, egui_ctx: &egui::Context, frame: &mut eframe::Frame) { | ||
#[cfg(not(target_arch = "wasm32"))] | ||
if self.ctrl_c.load(std::sync::atomic::Ordering::SeqCst) { | ||
frame.close(); | ||
return; | ||
} | ||
|
||
fn check_keyboard_shortcuts(&mut self, egui_ctx: &egui::Context, frame: &mut eframe::Frame) { | ||
if egui_ctx | ||
.input_mut() | ||
.consume_shortcut(&kb_shortcuts::RESET_VIEWER) | ||
|
@@ -218,6 +206,29 @@ impl eframe::App for App { | |
self.state.profiler.start(); | ||
} | ||
|
||
if !frame.is_web() { | ||
egui::gui_zoom::zoom_with_keyboard_shortcuts( | ||
egui_ctx, | ||
frame.info().native_pixels_per_point, | ||
); | ||
} | ||
} | ||
} | ||
|
||
impl eframe::App for App { | ||
fn save(&mut self, storage: &mut dyn eframe::Storage) { | ||
eframe::set_value(storage, eframe::APP_KEY, &self.state); | ||
} | ||
|
||
fn update(&mut self, egui_ctx: &egui::Context, frame: &mut eframe::Frame) { | ||
#[cfg(not(target_arch = "wasm32"))] | ||
if self.ctrl_c.load(std::sync::atomic::Ordering::Relaxed) { | ||
frame.close(); | ||
return; | ||
} | ||
|
||
self.check_keyboard_shortcuts(egui_ctx, frame); | ||
|
||
self.state.cache.new_frame(); | ||
|
||
if let Some(rx) = &mut self.rx { | ||
|
@@ -527,24 +538,47 @@ fn top_panel(egui_ctx: &egui::Context, frame: &mut eframe::Frame, app: &mut App) | |
} | ||
}; | ||
|
||
let gui_zoom = if let Some(native_pixels_per_point) = frame.info().native_pixels_per_point { | ||
native_pixels_per_point / egui_ctx.pixels_per_point() | ||
} else { | ||
1.0 | ||
}; | ||
|
||
// On Mac, we share the same space as the native red/yellow/green close/minimize/maximize buttons. | ||
// This means we need to make room for them. | ||
let native_buttons_size_in_native_scale = egui::vec2(64.0, 24.0); // source: I measured /emilk | ||
|
||
let bar_height = if crate::FULLSIZE_CONTENT { | ||
// Use more vertical space when zoomed in… | ||
let bar_height = native_buttons_size_in_native_scale.y; | ||
|
||
// …but never shrink below the native button height when zoomed out. | ||
bar_height.max(gui_zoom * native_buttons_size_in_native_scale.y) | ||
} else { | ||
egui_ctx.style().spacing.interact_size.y | ||
}; | ||
|
||
egui::TopBottomPanel::top("top_bar") | ||
.frame(panel_frame) | ||
.exact_height(bar_height) | ||
.show(egui_ctx, |ui| { | ||
egui::menu::bar(ui, |ui| { | ||
#[cfg(target_os = "macos")] | ||
if crate::native::FULLSIZE_CONTENT { | ||
// We use up the same row as the native red/yellow/green close/minimize/maximize buttons. | ||
// This means we need to make room for them: | ||
ui.add_space(64.0); | ||
|
||
// …and match their height: | ||
ui.set_min_size(egui::vec2(ui.available_width(), 24.0)); | ||
ui.set_height(bar_height); | ||
|
||
if crate::FULLSIZE_CONTENT { | ||
// Always use the same width measured in native GUI coordinates: | ||
ui.add_space(gui_zoom * native_buttons_size_in_native_scale.x); | ||
} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
ui.menu_button("File", |ui| { | ||
file_menu(ui, app, frame); | ||
}); | ||
|
||
ui.menu_button("View", |ui| { | ||
view_menu(ui, app, frame); | ||
}); | ||
|
||
ui.menu_button("Recordings", |ui| { | ||
recordings_menu(ui, app); | ||
}); | ||
|
@@ -634,7 +668,8 @@ fn file_saver_progress_ui(egui_ctx: &egui::Context, app: &mut App) { | |
} | ||
} | ||
|
||
fn file_menu(ui: &mut egui::Ui, app: &mut App, _frame: &mut eframe::Frame) { | ||
#[cfg(not(target_arch = "wasm32"))] | ||
fn file_menu(ui: &mut egui::Ui, app: &mut App, frame: &mut eframe::Frame) { | ||
// TODO(emilk): support saving data on web | ||
#[cfg(not(target_arch = "wasm32"))] | ||
{ | ||
|
@@ -646,7 +681,7 @@ fn file_menu(ui: &mut egui::Ui, app: &mut App, _frame: &mut eframe::Frame) { | |
ui.spinner(); | ||
}); | ||
ui.horizontal(|ui| { | ||
let _ = ui.button("Save time selection…"); | ||
let _ = ui.button("Save Time Selection…"); | ||
ui.spinner(); | ||
}); | ||
}); | ||
|
@@ -715,7 +750,7 @@ fn file_menu(ui: &mut egui::Ui, app: &mut App, _frame: &mut eframe::Frame) { | |
#[cfg(not(target_arch = "wasm32"))] | ||
if ui | ||
.button("Load") | ||
.on_hover_text("Load a Rerun data file (.rrd)") | ||
.on_hover_text("Load a Rerun Data File (.rrd)") | ||
.clicked() | ||
{ | ||
if let Some(path) = rfd::FileDialog::new() | ||
|
@@ -728,37 +763,43 @@ fn file_menu(ui: &mut egui::Ui, app: &mut App, _frame: &mut eframe::Frame) { | |
} | ||
} | ||
|
||
ui.menu_button("Advanced", |ui| { | ||
ui.set_min_width(180.0); | ||
#[cfg(not(target_arch = "wasm32"))] | ||
if ui.button("Quit").clicked() { | ||
frame.close(); | ||
} | ||
} | ||
|
||
if ui | ||
.add( | ||
egui::Button::new("Reset viewer") | ||
.shortcut_text(ui.ctx().format_shortcut(&kb_shortcuts::RESET_VIEWER)), | ||
) | ||
.on_hover_text("Reset the viewer to how it looked the first time you ran it") | ||
.clicked() | ||
{ | ||
app.reset(ui.ctx()); | ||
ui.close_menu(); | ||
} | ||
fn view_menu(ui: &mut egui::Ui, app: &mut App, frame: &mut eframe::Frame) { | ||
ui.set_min_width(180.0); | ||
|
||
#[cfg(all(feature = "puffin", not(target_arch = "wasm32")))] | ||
if ui | ||
.add( | ||
egui::Button::new("Profile viewer") | ||
.shortcut_text(ui.ctx().format_shortcut(&kb_shortcuts::SHOW_PROFILER)), | ||
) | ||
.on_hover_text("Starts a profiler, showing what makes the viewer run slow") | ||
.clicked() | ||
{ | ||
app.state.profiler.start(); | ||
} | ||
}); | ||
// On the web the browser controls the zoom | ||
if !frame.is_web() { | ||
egui::gui_zoom::zoom_menu_buttons(ui, frame.info().native_pixels_per_point); | ||
ui.separator(); | ||
} | ||
Comment on lines
+775
to
+779
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually I can't zoom at all on the web since we grab cmd + There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do we grab I can zoom with cmd+/- on Mac Firefox on https://www.egui.rs/ - can you? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah apologies, I meant cmd + scrollwheel. Cmd + works |
||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
if ui.button("Quit").clicked() { | ||
_frame.close(); | ||
if ui | ||
.add( | ||
egui::Button::new("Reset Viewer") | ||
.shortcut_text(ui.ctx().format_shortcut(&kb_shortcuts::RESET_VIEWER)), | ||
) | ||
.on_hover_text("Reset the viewer to how it looked the first time you ran it") | ||
.clicked() | ||
{ | ||
app.reset(ui.ctx()); | ||
ui.close_menu(); | ||
} | ||
|
||
#[cfg(all(feature = "puffin", not(target_arch = "wasm32")))] | ||
if ui | ||
.add( | ||
egui::Button::new("Profile Viewer") | ||
.shortcut_text(ui.ctx().format_shortcut(&kb_shortcuts::SHOW_PROFILER)), | ||
) | ||
.on_hover_text("Starts a profiler, showing what makes the viewer run slow") | ||
.clicked() | ||
{ | ||
app.state.profiler.start(); | ||
} | ||
} | ||
|
||
|
@@ -771,6 +812,11 @@ fn recordings_menu(ui: &mut egui::Ui, app: &mut App) { | |
.sorted_by_key(|log_db| log_db.recording_info().map(|ri| ri.started)) | ||
.collect_vec(); | ||
|
||
if log_dbs.is_empty() { | ||
ui.weak("(empty)"); | ||
return; | ||
} | ||
|
||
ui.style_mut().wrap = Some(false); | ||
for log_db in log_dbs { | ||
let info = if let Some(rec_info) = log_db.recording_info() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you try this on Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a Mac-only setting.