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

Migrate to custom checkbox/radio_value UI #2851

Merged
merged 4 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 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,9 +202,9 @@ 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");
ui.checkbox(&mut self.state_3d.show_accumulated_bbox, "Show accumulated bounding box").on_hover_text("Show bounding box accumulated over all rendered frames");
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");
re_ui.checkbox(ui, &mut self.state_3d.show_accumulated_bbox, "Show accumulated bounding box").on_hover_text("Show bounding box accumulated over all rendered frames");
});
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
16 changes: 10 additions & 6 deletions crates/re_space_view_text/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,29 +97,33 @@ 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();

ctx.re_ui.grid_left_hand_label(ui, "Text style");
ui.vertical(|ui| {
ui.radio_value(&mut state.monospace, false, "Proportional");
ui.radio_value(&mut state.monospace, true, "Monospace");
ctx.re_ui
.radio_value(ui, &mut state.monospace, false, "Proportional");
ctx.re_ui
.radio_value(ui, &mut state.monospace, true, "Monospace");
});
ui.end_row();
});
Expand Down
8 changes: 5 additions & 3 deletions crates/re_space_view_text_box/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ impl SpaceViewClass for TextBoxSpaceView {
ctx.re_ui.selection_grid(ui, "text_config").show(ui, |ui| {
ctx.re_ui.grid_left_hand_label(ui, "Text style");
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
.radio_value(ui, &mut state.monospace, false, "Proportional");
ctx.re_ui
.radio_value(ui, &mut state.monospace, true, "Monospace");
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
37 changes: 37 additions & 0 deletions crates/re_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,43 @@ 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;

// NOLINT
ui.checkbox(selected, text)
})
.inner
}

#[allow(clippy::unused_self)]
pub fn radio_value<Value: PartialEq>(
&self,
ui: &mut egui::Ui,
current_value: &mut Value,
alternative: Value,
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;

// NOLINT
ui.radio_value(current_value, alternative, 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 @@ -480,6 +480,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