Skip to content

Commit

Permalink
Migrated to custom checkbox UI
Browse files Browse the repository at this point in the history
Fixes #2727
  • Loading branch information
abey79 committed Jul 27, 2023
1 parent 15531d3 commit 238ad94
Show file tree
Hide file tree
Showing 14 changed files with 455 additions and 347 deletions.
8 changes: 5 additions & 3 deletions crates/re_space_view_spatial/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ impl SpatialSpaceViewState {
space_view_id: SpaceViewId,
spatial_kind: SpatialSpaceViewKind,
) {
let re_ui = ctx.re_ui;

let view_coordinates = ctx
.store_db
.store()
Expand Down Expand Up @@ -177,7 +179,7 @@ impl SpatialSpaceViewState {
{
self.state_3d.reset_camera(&self.scene_bbox_accum, &view_coordinates);
}
ui.checkbox(&mut self.state_3d.spin, "Spin")
re_ui.checkbox(ui, &mut self.state_3d.spin, "Spin")
.on_hover_text("Spin camera around the orbit center.");
}
});
Expand All @@ -200,8 +202,8 @@ impl SpatialSpaceViewState {
ui.label(".");
});
});
ui.checkbox(&mut self.state_3d.show_axes, "Show origin axes").on_hover_text("Show X-Y-Z axes");
ui.checkbox(&mut self.state_3d.show_bbox, "Show bounding box").on_hover_text("Show the current scene bounding box");
re_ui.checkbox(ui, &mut self.state_3d.show_axes, "Show origin axes").on_hover_text("Show X-Y-Z axes");
re_ui.checkbox(ui, &mut self.state_3d.show_bbox, "Show bounding box").on_hover_text("Show the current scene bounding box");
});
ui.end_row();
}
Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view_tensor/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ impl TextureSettings {
selectable_value(ui, TextureScaling::Fill);
});
if *scaling == TextureScaling::Fill {
ui.checkbox(keep_aspect_ratio, "Keep aspect ratio");
re_ui.checkbox(ui, keep_aspect_ratio, "Keep aspect ratio");
}
});
ui.end_row();
Expand Down
10 changes: 6 additions & 4 deletions crates/re_space_view_text/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,23 @@ impl SpaceViewClass for TextSpaceView {
row_log_levels,
} = &mut state.filters;

let re_ui = ctx.re_ui;

ctx.re_ui.selection_grid(ui, "log_config").show(ui, |ui| {
ctx.re_ui.grid_left_hand_label(ui, "Columns");
ui.vertical(|ui| {
for (timeline, visible) in col_timelines {
ui.checkbox(visible, timeline.name().to_string());
re_ui.checkbox(ui, visible, timeline.name().to_string());
}
ui.checkbox(col_entity_path, "Entity path");
ui.checkbox(col_log_level, "Log level");
re_ui.checkbox(ui, col_entity_path, "Entity path");
re_ui.checkbox(ui, col_log_level, "Log level");
});
ui.end_row();

ctx.re_ui.grid_left_hand_label(ui, "Level Filter");
ui.vertical(|ui| {
for (log_level, visible) in row_log_levels {
ui.checkbox(visible, level_to_rich_text(ui, log_level));
re_ui.checkbox(ui, visible, level_to_rich_text(ui, log_level));
}
});
ui.end_row();
Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view_text_box/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl SpaceViewClass for TextBoxSpaceView {
ui.vertical(|ui| {
ui.radio_value(&mut state.monospace, false, "Proportional");
ui.radio_value(&mut state.monospace, true, "Monospace");
ui.checkbox(&mut state.word_wrap, "Word Wrap");
ctx.re_ui.checkbox(ui, &mut state.word_wrap, "Word Wrap");
});
ui.end_row();
});
Expand Down
1 change: 1 addition & 0 deletions crates/re_ui/examples/re_ui_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ impl eframe::App for ExampleApp {
.large_collapsing_header(ui, "Blueprint", true, |ui| {
ui.style_mut().wrap = Some(false);
ui.label("Some blueprint stuff here, that might be wide.");
self.re_ui.checkbox(ui, &mut self.dummy_bool, "Checkbox");
});
});
});
Expand Down
18 changes: 18 additions & 0 deletions crates/re_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,24 @@ impl ReUi {
response
}

#[allow(clippy::unused_self)]
pub fn checkbox(
&self,
ui: &mut egui::Ui,
selected: &mut bool,
text: impl Into<egui::WidgetText>,
) -> egui::Response {
ui.scope(|ui| {
ui.visuals_mut().widgets.hovered.expansion = 0.0;
ui.visuals_mut().widgets.active.expansion = 0.0;
ui.visuals_mut().widgets.open.expansion = 0.0;

// note: fully qualified syntax to dodge script/lint.py
egui::Ui::checkbox(ui, selected, text)
})
.inner
}

pub fn large_button(&self, ui: &mut egui::Ui, icon: &Icon) -> egui::Response {
self.large_button_impl(ui, icon, None, None)
}
Expand Down
3 changes: 2 additions & 1 deletion crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct App {
build_info: re_build_info::BuildInfo,
startup_options: StartupOptions,
ram_limit_warner: re_memory::RamLimitWarner,
re_ui: re_ui::ReUi,
pub(crate) re_ui: re_ui::ReUi,
screenshotter: crate::screenshotter::Screenshotter,

#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -467,6 +467,7 @@ impl App {
.show_animated_inside(ui, self.memory_panel_open, |ui| {
self.memory_panel.ui(
ui,
self.re_ui(),
&self.startup_options.memory_limit,
gpu_resource_stats,
store_stats,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const WATERMARK: bool = false; // Nice for recording media material
#[serde(default)]
pub struct AppState {
/// Global options for the whole viewer.
app_options: AppOptions,
pub(crate) app_options: AppOptions,

/// Things that need caching.
#[serde(skip)]
Expand Down
15 changes: 11 additions & 4 deletions crates/re_viewer/src/ui/memory_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl MemoryPanel {
pub fn ui(
&self,
ui: &mut egui::Ui,
re_ui: &re_ui::ReUi,
limit: &MemoryLimit,
gpu_resource_stats: &WgpuResourcePoolStatistics,
store_stats: &StoreHubStats,
Expand All @@ -54,7 +55,7 @@ impl MemoryPanel {
.min_width(250.0)
.default_width(300.0)
.show_inside(ui, |ui| {
Self::left_side(ui, limit, gpu_resource_stats, store_stats);
Self::left_side(ui, re_ui, limit, gpu_resource_stats, store_stats);
});

egui::CentralPanel::default().show_inside(ui, |ui| {
Expand All @@ -65,6 +66,7 @@ impl MemoryPanel {

fn left_side(
ui: &mut egui::Ui,
re_ui: &re_ui::ReUi,
limit: &MemoryLimit,
gpu_resource_stats: &WgpuResourcePoolStatistics,
store_stats: &StoreHubStats,
Expand All @@ -73,7 +75,7 @@ impl MemoryPanel {

ui.separator();
ui.collapsing("CPU Resources", |ui| {
Self::cpu_stats(ui, limit);
Self::cpu_stats(ui, re_ui, limit);
});

ui.separator();
Expand All @@ -100,7 +102,7 @@ impl MemoryPanel {
});
}

fn cpu_stats(ui: &mut egui::Ui, limit: &MemoryLimit) {
fn cpu_stats(ui: &mut egui::Ui, re_ui: &re_ui::ReUi, limit: &MemoryLimit) {
if let Some(limit) = limit.limit {
ui.label(format!("Memory limit: {}", format_bytes(limit as _)));
} else {
Expand Down Expand Up @@ -129,7 +131,12 @@ impl MemoryPanel {
}

let mut is_tracking_callstacks = re_memory::accounting_allocator::is_tracking_callstacks();
ui.checkbox(&mut is_tracking_callstacks, "Detailed allocation tracking")
re_ui
.checkbox(
ui,
&mut is_tracking_callstacks,
"Detailed allocation tracking",
)
.on_hover_text("This will slow down the program.");
re_memory::accounting_allocator::set_tracking_callstacks(is_tracking_callstacks);

Expand Down
4 changes: 2 additions & 2 deletions crates/re_viewer/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ pub use blueprint_panel::blueprint_panel_ui;
// ----

pub(crate) use {
self::mobile_warning_ui::mobile_warning_ui, self::rerun_menu::rerun_menu_button_ui,
self::top_panel::top_panel, self::wait_screen_ui::wait_screen_ui,
self::mobile_warning_ui::mobile_warning_ui, self::top_panel::top_panel,
self::wait_screen_ui::wait_screen_ui,
};
Loading

0 comments on commit 238ad94

Please sign in to comment.