Skip to content
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

Collapse panels #238

Merged
merged 11 commits into from
Oct 31, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

A rough time-line of major user-facing things added, removed and changed. Newest on top.

* 2022-10-28: Add buttons to collapse/expand the side panels ([#238](https://github.com/rerun-io/rerun/pull/238)).
* 2022-10-26: Replace old `space=…` and `set_space_up` code with new space transform hierarchy. See [`USAGE.md`](rerun_py/USAGE.md) for details ([#224](https://github.com/rerun-io/rerun/pull/224)).
* 2022-10-19: Add support for SegmentationMaps ([#187](https://github.com/rerun-io/rerun/pull/187)).
* 2022-10-14: Add support for logging 3D Arrows ([#199](https://github.com/rerun-io/rerun/pull/199)).
Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ opt-level = 2
debug = true

[patch.crates-io]
# 2022-10-16 - table: fix deadlocks caused by lock fairness
eframe = { git = "https://github.com/emilk/egui", rev = "3d36a20376a8479647557d172e1abc82abbff135" }
egui = { git = "https://github.com/emilk/egui", rev = "3d36a20376a8479647557d172e1abc82abbff135" }
egui_extras = { git = "https://github.com/emilk/egui", rev = "3d36a20376a8479647557d172e1abc82abbff135" }
egui_glow = { git = "https://github.com/emilk/egui", rev = "3d36a20376a8479647557d172e1abc82abbff135" }
egui-wgpu = { git = "https://github.com/emilk/egui", rev = "3d36a20376a8479647557d172e1abc82abbff135" }
# 2022-10-28 - panel toggle animation
eframe = { git = "https://github.com/emilk/egui", rev = "f7a15a34f9bd17f39ae75c488b722873465c8d86" }
egui = { git = "https://github.com/emilk/egui", rev = "f7a15a34f9bd17f39ae75c488b722873465c8d86" }
egui_extras = { git = "https://github.com/emilk/egui", rev = "f7a15a34f9bd17f39ae75c488b722873465c8d86" }
egui_glow = { git = "https://github.com/emilk/egui", rev = "f7a15a34f9bd17f39ae75c488b722873465c8d86" }
egui-wgpu = { git = "https://github.com/emilk/egui", rev = "f7a15a34f9bd17f39ae75c488b722873465c8d86" }
# eframe = { path = "../../egui/crates/eframe" }
# egui = { path = "../../egui/crates/egui" }
# egui_extras = { path = "../../egui/crates/egui_extras" }
# egui_glow = { path = "../../egui/crates/egui_glow" }
# egui-wgpu = { path = "../../egui/crates/egui-wgpu" }

# Because gltf hasn't published a new version: https://github.com/gltf-rs/gltf/issues/357
gltf = { git = "https://github.com/rerun-io/gltf", rev = "3c14ded73755d1ce9e47010edb06db63cb7e2cca" }
Expand Down
63 changes: 37 additions & 26 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ impl eframe::App for App {
return;
}

if egui_ctx.input_mut().consume_key(
egui::Modifiers::COMMAND | egui::Modifiers::SHIFT,
egui::Key::R,
) {
Wumpf marked this conversation as resolved.
Show resolved Hide resolved
self.reset(egui_ctx);
}

#[cfg(all(feature = "puffin", not(target_arch = "wasm32")))]
if egui_ctx.input_mut().consume_key(
egui::Modifiers::COMMAND | egui::Modifiers::SHIFT,
egui::Key::P,
) {
self.state.profiler.start();
}

self.state.cache.new_frame();

if let Some(rx) = &mut self.rx {
Expand Down Expand Up @@ -277,6 +292,20 @@ impl eframe::App for App {
}

impl App {
/// Reset the viewer to how it looked the first time you ran it.
fn reset(&mut self, egui_ctx: &egui::Context) {
self.state = Default::default();

// Keep dark/light mode setting:
let is_dark_mode = egui_ctx.style().visuals.dark_mode;
*egui_ctx.memory() = Default::default();
egui_ctx.set_visuals(if is_dark_mode {
egui::Visuals::dark()
} else {
egui::Visuals::light()
});
}

fn log_db(&mut self) -> &mut LogDb {
self.log_dbs.entry(self.state.selected_rec_id).or_default()
}
Expand Down Expand Up @@ -415,19 +444,9 @@ impl AppState {
rec_cfg,
};

if ctx.rec_cfg.selection.is_some() {
egui::SidePanel::right("selection_view").show(egui_ctx, |ui| {
let blueprint = blueprints.entry(*selected_recording_id).or_default();
selection_panel.ui(&mut ctx, blueprint, ui);
});
}

egui::TopBottomPanel::bottom("time_panel")
.resizable(true)
.default_height(210.0)
.show(egui_ctx, |ui| {
time_panel.ui(&mut ctx, ui);
});
let blueprint = blueprints.entry(*selected_recording_id).or_default();
selection_panel.show_panel(&mut ctx, blueprint, egui_ctx);
time_panel.show_panel(&mut ctx, blueprint, egui_ctx);

let central_panel_frame = egui::Frame {
fill: egui_ctx.style().visuals.window_fill(),
Expand Down Expand Up @@ -689,27 +708,19 @@ fn file_menu(ui: &mut egui::Ui, app: &mut App, _frame: &mut eframe::Frame) {
ui.menu_button("Advanced", |ui| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a great place for such a fundamental view operation. should go to a View menu. But that can ofc wait

if ui
.button("Reset viewer")
.on_hover_text("Reset the viewer to how it looked the first time you ran it.")
.on_hover_text(
"Reset the viewer to how it looked the first time you ran it (⌘⇧R or ⌃⇧R)",
)
.clicked()
{
app.state = Default::default();

// Keep dark/light mode setting:
let is_dark_mode = ui.ctx().style().visuals.dark_mode;
*ui.ctx().memory() = Default::default();
ui.ctx().set_visuals(if is_dark_mode {
egui::Visuals::dark()
} else {
egui::Visuals::light()
});

app.reset(ui.ctx());
ui.close_menu();
}

#[cfg(all(feature = "puffin", not(target_arch = "wasm32")))]
if ui
.button("Profile viewer")
.on_hover_text("Starts a profiler, showing what makes the viewer run slow")
.on_hover_text("Starts a profiler, showing what makes the viewer run slow (⌘⇧P or ⌃⇧P)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have a way generate these strings from the set shortcut? I mean at least soemthing like format!("Starts a profiler, showing what makes the viewer run slow ({} or {})", get_puffin_shortcut().as_string(), get_puffin_alt_shortcut().as_string())

Also, more importantly neiother ⌘ nor ⌃ makes much sense to a windows user!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(applies to all shortcut strings ofc)

Copy link
Member Author

@emilk emilk Oct 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One problem is that different platforms use different standards for showing shortcuts

  • ⇧⌘P-style is standard on MacOS
  • I believe Shift+Ctrl+P is standard on Windows?
  • On Linux I have no idea.

The further problem is that when running on Web it's difficult to know what platform we are running on (but I could add some detection code to egui_web that does its best).

Another problem is that on Mac it is more convenient/natural to use ⌘ Command while on Windows Ctrl is more natural.

Maybe @martenbjork has a suggestion here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I have a pretty good plan now. I'll use the user-agent to detect Mac, If mac, I'll show the shortcut as "⇧⌘P", and else as "Ctrl+Shift+P", but I'll save that improvement for a separate PR.

.clicked()
{
app.state.profiler.start();
Expand Down
68 changes: 59 additions & 9 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,71 @@ pub(crate) struct SelectionPanel {}

impl SelectionPanel {
#[allow(clippy::unused_self)]
pub fn ui(
pub fn show_panel(
&mut self,
ctx: &mut ViewerContext<'_>,
blueprint: &mut Blueprint,
ui: &mut egui::Ui,
egui_ctx: &egui::Context,
) {
crate::profile_function!();
blueprint.selection_panel_expanded ^= egui_ctx.input_mut().consume_key(
egui::Modifiers::COMMAND | egui::Modifiers::SHIFT,
egui::Key::S,
);

let panel_frame = egui::Frame {
fill: egui_ctx.style().visuals.window_fill(),
inner_margin: egui::style::Margin::same(4.0),
stroke: egui_ctx.style().visuals.window_stroke(),
..Default::default()
};

let collapsed = egui::SidePanel::right("selection_view_collapsed")
.resizable(false)
.frame(panel_frame)
.default_width(16.0);
let expanded = egui::SidePanel::right("selection_view_expanded")
.resizable(true)
.frame(panel_frame);

egui::SidePanel::show_animated_between(
egui_ctx,
blueprint.selection_panel_expanded,
collapsed,
expanded,
|ui: &mut egui::Ui, expansion: f32| {
if expansion < 1.0 {
// Collapsed, or animating:
if ui
.small_button("⏴")
.on_hover_text("Expand Selection View (⌘⇧S or ⌃⇧S)")
.clicked()
{
blueprint.selection_panel_expanded = true;
}
} else {
// Expanded:
if ui
.small_button("⏵")
.on_hover_text("Collapse Selection View (⌘⇧S or ⌃⇧S)")
.clicked()
{
blueprint.selection_panel_expanded = false;
}

ui.horizontal(|ui| {
ui.heading("Selection");
self.contents(ctx, blueprint, ui);
}
},
);
}

if ctx.rec_cfg.selection.is_some() && ui.small_button("Deselect").clicked() {
ctx.rec_cfg.selection = Selection::None;
}
});
#[allow(clippy::unused_self)]
fn contents(
&mut self,
ctx: &mut ViewerContext<'_>,
blueprint: &mut Blueprint,
ui: &mut egui::Ui,
) {
crate::profile_function!();

ui.separator();

Expand Down
68 changes: 65 additions & 3 deletions crates/re_viewer/src/ui/time_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::{
TimeRange, TimeRangeF, TimeReal, TimeView, ViewerContext,
};

use super::Blueprint;

/// A panel that shows objects to the left, time on the top.
///
/// This includes the timeline controls and streams view.
Expand Down Expand Up @@ -42,11 +44,61 @@ impl Default for TimePanel {
}

impl TimePanel {
pub fn ui(&mut self, ctx: &mut ViewerContext<'_>, ui: &mut egui::Ui) {
pub fn show_panel(
Wumpf marked this conversation as resolved.
Show resolved Hide resolved
&mut self,
ctx: &mut ViewerContext<'_>,
blueprint: &mut Blueprint,
egui_ctx: &egui::Context,
) {
blueprint.time_panel_expanded ^= egui_ctx.input_mut().consume_key(
egui::Modifiers::COMMAND | egui::Modifiers::SHIFT,
egui::Key::T,
);

let panel_frame = egui::Frame {
fill: egui_ctx.style().visuals.window_fill(),
inner_margin: egui::style::Margin::same(4.0),
stroke: egui_ctx.style().visuals.window_stroke(),
..Default::default()
};

let collapsed = egui::TopBottomPanel::bottom("time_panel_collapsed")
.resizable(false)
.frame(panel_frame)
.default_height(16.0);
let expanded = egui::TopBottomPanel::bottom("time_panel_expanded")
.resizable(true)
.frame(panel_frame)
.default_height(250.0);

egui::TopBottomPanel::show_animated_between(
egui_ctx,
blueprint.time_panel_expanded,
collapsed,
expanded,
|ui: &mut egui::Ui, expansion: f32| {
if expansion < 1.0 {
// Collapsed, or animating:
if ui
.small_button("⏶")
.on_hover_text("Expand Timeline View (⌘⇧T or ⌃⇧T)")
.clicked()
{
blueprint.time_panel_expanded = true;
}
} else {
// Expanded:
self.ui(ctx, blueprint, ui);
}
},
);
}

fn ui(&mut self, ctx: &mut ViewerContext<'_>, blueprint: &mut Blueprint, ui: &mut egui::Ui) {
crate::profile_function!();

// play control and current time
top_row_ui(ctx, ui);
top_row_ui(ctx, blueprint, ui);

self.next_col_right = ui.min_rect().left(); // this will expand during the call

Expand Down Expand Up @@ -359,8 +411,18 @@ impl TimePanel {
}
}

fn top_row_ui(ctx: &mut ViewerContext<'_>, ui: &mut egui::Ui) {
fn top_row_ui(ctx: &mut ViewerContext<'_>, blueprint: &mut Blueprint, ui: &mut egui::Ui) {
ui.horizontal(|ui| {
if ui
.small_button("⏷")
.on_hover_text("Collapse Timeline View (⌘⇧T or ⌃⇧T)")
.clicked()
{
blueprint.time_panel_expanded = false;
}

ui.separator();

ctx.rec_cfg
.time_ctrl
.timeline_selector_ui(&ctx.log_db.time_points, ui);
Expand Down
Loading