Skip to content

Commit

Permalink
Add (debug-only) style panel (#2914)
Browse files Browse the repository at this point in the history
### What

This PR adds the egui style editor in a "left-left-panel". That's a
debug-only feature, as the behaviour is often unexpected due to how
often we bypass egui-native styling hooks.

>[!NOTE]
>Cannot be tested with demo site as this is debug-only.

<img width="1728" alt="image"
src="https://github.com/rerun-io/rerun/assets/49431240/1d3c9368-d617-4855-b08a-1a078fd2bf55">

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] ~~I have tested [demo.rerun.io](https://demo.rerun.io/pr/2914) (if
applicable)~~

- [PR Build Summary](https://build.rerun.io/pr/2914)
- [Docs
preview](https://rerun.io/preview/pr%3Aantoine%2Fstyle-panel/docs)
- [Examples
preview](https://rerun.io/preview/pr%3Aantoine%2Fstyle-panel/examples)
  • Loading branch information
abey79 authored Aug 7, 2023
1 parent d7ec72e commit b63f875
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/re_ui/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub enum UICommand {
ToggleSelectionPanel,
ToggleTimePanel,

#[cfg(debug_assertions)]
ToggleStylePanel,

#[cfg(not(target_arch = "wasm32"))]
ToggleFullscreen,
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -105,6 +108,12 @@ impl UICommand {
UICommand::ToggleSelectionPanel => ("Toggle Selection Panel", "Toggle the right panel"),
UICommand::ToggleTimePanel => ("Toggle Time Panel", "Toggle the bottom panel"),

#[cfg(debug_assertions)]
UICommand::ToggleStylePanel => (
"Toggle Style Panel",
"View and change global egui style settings",
),

#[cfg(not(target_arch = "wasm32"))]
UICommand::ToggleFullscreen => (
"Toggle fullscreen",
Expand Down Expand Up @@ -192,6 +201,9 @@ impl UICommand {
UICommand::ToggleSelectionPanel => Some(ctrl_shift(Key::S)),
UICommand::ToggleTimePanel => Some(ctrl_shift(Key::T)),

#[cfg(debug_assertions)]
UICommand::ToggleStylePanel => Some(ctrl_shift(Key::U)),

#[cfg(not(target_arch = "wasm32"))]
UICommand::ToggleFullscreen => Some(key(Key::F11)),
#[cfg(not(target_arch = "wasm32"))]
Expand Down
23 changes: 23 additions & 0 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ pub struct App {
memory_panel: crate::memory_panel::MemoryPanel,
memory_panel_open: bool,

style_panel_open: bool,

pub(crate) latest_queue_interest: web_time::Instant,

/// Measures how long a frame takes to paint
Expand Down Expand Up @@ -202,6 +204,8 @@ impl App {
memory_panel: Default::default(),
memory_panel_open: false,

style_panel_open: false,

latest_queue_interest: web_time::Instant::now(), // TODO(emilk): `Instant::MIN` when we have our own `Instant` that supports it.

frame_time_history: egui::util::History::new(1..100, 0.5),
Expand Down Expand Up @@ -358,6 +362,11 @@ impl App {
}
UICommand::ToggleTimePanel => app_blueprint.toggle_time_panel(&self.command_sender),

#[cfg(debug_assertions)]
UICommand::ToggleStylePanel => {
self.style_panel_open ^= true;
}

#[cfg(not(target_arch = "wasm32"))]
UICommand::ToggleFullscreen => {
_frame.set_fullscreen(!_frame.info().window_info.fullscreen);
Expand Down Expand Up @@ -488,6 +497,18 @@ impl App {
});
}

fn style_panel_ui(&mut self, ctx: &egui::Context, ui: &mut egui::Ui) {
egui::SidePanel::left("style_panel")
.default_width(300.0)
.resizable(true)
.frame(self.re_ui.top_panel_frame())
.show_animated_inside(ui, self.style_panel_open, |ui| {
egui::ScrollArea::vertical().show(ui, |ui| {
ctx.settings_ui(ui);
});
});
}

/// Top-level ui function.
///
/// Shows the viewer ui.
Expand Down Expand Up @@ -524,6 +545,8 @@ impl App {

self.memory_panel_ui(ui, gpu_resource_stats, store_stats);

self.style_panel_ui(egui_ctx, ui);

if let Some(store_view) = store_context {
// TODO(jleibs): We don't necessarily want to show the wait
// screen just because we're missing a recording. If we've
Expand Down
3 changes: 3 additions & 0 deletions crates/re_viewer/src/ui/rerun_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ impl App {
UICommand::OpenProfiler.menu_button_ui(ui, &self.command_sender);

UICommand::ToggleMemoryPanel.menu_button_ui(ui, &self.command_sender);

#[cfg(debug_assertions)]
UICommand::ToggleStylePanel.menu_button_ui(ui, &self.command_sender);
}

ui.add_space(spacing);
Expand Down

0 comments on commit b63f875

Please sign in to comment.