re_viewer 0.32.2

The Rerun viewer
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
use std::str::FromStr as _;

use egui::{NumExt as _, Ui};
use re_entity_db::FetchStage;
use re_log_types::{Timestamp, TimestampFormat};
use re_memory::MemoryLimit;
use re_ui::syntax_highlighting::SyntaxHighlightedBuilder;
use re_ui::{DesignTokens, UiExt as _};
use re_viewer_context::{AppOptions, ExperimentalAppOptions, VideoOptions};

pub fn settings_screen_ui(ui: &mut egui::Ui, app_options: &mut AppOptions, keep_open: &mut bool) {
    egui::Frame {
        inner_margin: egui::Margin::same(5),
        ..Default::default()
    }
    .show(ui, |ui| {
        const MAX_WIDTH: f32 = 600.0;
        const MIN_WIDTH: f32 = 300.0;

        let centering_margin = ((ui.available_width() - MAX_WIDTH) / 2.0).at_least(0.0);
        let max_rect = ui.max_rect().expand2(-centering_margin * egui::Vec2::X);
        let mut child_ui = ui.new_child(egui::UiBuilder::new().max_rect(max_rect));

        egui::ScrollArea::both()
            .auto_shrink(false)
            .show(&mut child_ui, |ui| {
                ui.set_min_width(MIN_WIDTH);
                settings_screen_ui_impl(ui, app_options, keep_open);
            });

        if ui.input_mut(|ui| ui.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) {
            *keep_open = false;
        }
    });
}

fn settings_screen_ui_impl(ui: &mut egui::Ui, app_options: &mut AppOptions, keep_open: &mut bool) {
    //
    // Title
    //

    ui.add_space(40.0);

    ui.horizontal(|ui| {
        ui.add(egui::Label::new(
            egui::RichText::new("Settings")
                .strong()
                .line_height(Some(32.0))
                .text_style(DesignTokens::welcome_screen_h2()),
        ));

        ui.allocate_ui_with_layout(
            egui::Vec2::X * ui.available_width(),
            egui::Layout::right_to_left(egui::Align::Center),
            |ui| {
                if ui
                    .small_icon_button(&re_ui::icons::CLOSE, "Close")
                    .clicked()
                {
                    *keep_open = false;
                }
            },
        )
    });

    //
    // General
    //

    separator_with_some_space(ui);

    ui.strong("General");

    ui.horizontal(|ui| {
        ui.label("Theme");
        egui::global_theme_preference_buttons(ui);
    });

    let AppOptions {
        experimental,
        warn_e2e_latency: _, // not yet exposed
        show_metrics,
        show_notification_toasts,
        include_rerun_examples_button_in_recordings_panel,
        show_picking_debug_overlay: _, // not yet exposed
        inspect_blueprint_timeline: _, // not yet exposed
        blueprint_gc: _,               // not yet exposed
        visualizer_limits_enabled,
        timestamp_format,
        video,
        mapbox_access_token,
        memory_limit,
        max_fetch_stage,

        #[cfg(not(target_arch = "wasm32"))]
            cache_directory: _, // not yet exposed
    } = app_options;

    ui.add_space(8.0);

    egui::Grid::new("prefetcher").num_columns(2).show(ui, |ui| {
        ui.label("Memory budget");
        memory_budget_section_ui(ui, memory_limit);
        ui.help_button(|ui| {
            ui.label("When this limit is reached we start purging data from RAM");
        });
        ui.end_row();

        ui.label("Prefetch");
        prefetch_stage_combo_box_ui(ui, max_fetch_stage);
        ui.help_button(|ui| {
            ui.label(
                "Controls how aggressively we prefetch chunks ahead of what is strictly needed.\n\n\
                • Required: only chunks required to render the current time cursor.\n\
                • Similar: also prefetch chunks on the same component paths as required chunks up to a given real-time duration.\n\
                • Everything: also prefetch every chunk in the recording.",
            );
        });
        ui.end_row();
    });

    ui.add_space(8.0);

    ui.re_checkbox(
        include_rerun_examples_button_in_recordings_panel,
        "Show 'Rerun examples' button",
    );

    ui.re_checkbox(show_metrics, "Show performance metrics")
        .on_hover_text("Show metrics for milliseconds/frame and RAM usage in the top bar");

    ui.re_checkbox(show_notification_toasts, "Show notification toasts")
        .on_hover_text("Show toasts for log messages and other notifications");

    ui.re_checkbox(
        visualizer_limits_enabled,
        "Limit number of primitives in a view",
    )
    .on_hover_text(
        "Caps the number of elements individual visualizers process \
             (e.g. instance caps for 3D shapes, line limits for time series). \
             Disabling this may cause the viewer to become unresponsive \
             with very large data sets.",
    );

    separator_with_some_space(ui);
    ui.collapsing_header("Timestamp format", false, |ui| {
        time_format_section_ui(ui, timestamp_format);
    });

    separator_with_some_space(ui);
    ui.strong("Map view");
    map_view_section_ui(ui, mapbox_access_token);

    separator_with_some_space(ui);
    ui.strong("Video");
    video_section_ui(ui, video);

    {
        let ExperimentalAppOptions {
            table_cards_and_blueprints,
        } = experimental;
        separator_with_some_space(ui);
        ui.strong("Experimental");
        ui.re_checkbox(table_cards_and_blueprints, "Table cards and blueprints")
            .on_hover_text(
                "Enable table blueprints embedded in Arrow schema metadata, plus grid view mode for server supplied tables.\n\n\
                 When enabled, tables can carry inline view definitions for segment previews, and a list/grid toggle appears in the table title bar.",
            );
    }
}

fn memory_budget_section_ui(ui: &mut Ui, memory_limit: &mut MemoryLimit) {
    const BYTES_PER_GIB: u64 = 1024 * 1024 * 1024;
    const UPPER_LIMIT_BYTES: u64 = 1_000 * BYTES_PER_GIB;

    let mut bytes = memory_limit.as_bytes();

    let speed = (0.02 * bytes as f32).clamp(0.01 * BYTES_PER_GIB as f32, BYTES_PER_GIB as f32);

    ui.add(
        egui::DragValue::new(&mut bytes)
            .custom_formatter(|bytes, _| {
                if bytes < UPPER_LIMIT_BYTES as f64 {
                    re_format::format_bytes(bytes)
                } else {
                    "unlimited".to_owned()
                }
            })
            .custom_parser(|s| {
                let s = s.trim();
                if s.chars().all(|c| c.is_numeric()) {
                    // Assume GB
                    Some(BYTES_PER_GIB as f64 * f64::from_str(s).ok()?)
                } else {
                    Some(re_format::parse_bytes(s)? as f64)
                }
            })
            .update_while_editing(false)
            .range(0..=UPPER_LIMIT_BYTES)
            .speed(speed),
    );

    if bytes < UPPER_LIMIT_BYTES {
        *memory_limit = MemoryLimit::from_bytes(bytes);
    } else {
        *memory_limit = MemoryLimit::UNLIMITED;
    }
}

fn prefetch_stage_combo_box_ui(ui: &mut Ui, max_fetch_stage: &mut FetchStage) {
    fn label(stage: FetchStage) -> &'static str {
        match stage {
            FetchStage::Required => "Required",
            FetchStage::Similar(_) => "Similar",
            FetchStage::Everything => "Everything",
        }
    }

    egui::ComboBox::from_id_salt("max_fetch_stage")
        .selected_text(label(*max_fetch_stage))
        .show_ui(ui, |ui| {
            for stage in [
                FetchStage::Required,
                FetchStage::default(),
                FetchStage::Everything,
            ] {
                ui.selectable_value(max_fetch_stage, stage, label(stage));
            }
        });

    /// Maps t in [0, 1] to a log scale value in [min, max],
    /// where t=1.0 maps to `f64::INFINITY`.
    fn log_slider_to_value(t: f64, min: f64, max_finite: f64) -> f64 {
        if t >= 1.0 {
            return f64::INFINITY;
        }
        // Remap t in [0, 1) to log scale over [min, max_finite]
        let log_min = min.log10();
        let log_max = max_finite.log10();
        10f64.powf(log_min + t * (log_max - log_min))
    }

    fn value_to_log_slider(value: f64, min: f64, max_finite: f64) -> f64 {
        if value.is_infinite() {
            return 1.0;
        }
        let log_min = min.log10();
        let log_max = max_finite.log10();
        (value.log10() - log_min) / (log_max - log_min)
    }

    match max_fetch_stage {
        FetchStage::Similar(range) => {
            const MIN: f64 = 1.0;
            const MAX_FINITE: f64 = 600.0;

            let seconds = range.map(|d| d.as_secs_f64()).unwrap_or(f64::INFINITY);

            let mut value = value_to_log_slider(seconds, MIN, MAX_FINITE);
            ui.add(egui::Slider::new(&mut value, 0.0..=1.0).show_value(false));

            *range =
                std::time::Duration::try_from_secs_f64(log_slider_to_value(value, MIN, MAX_FINITE))
                    .ok();

            let label = if let Some(range) = range {
                format!("{}s", range.as_secs())
            } else {
                "∞".to_owned()
            };

            ui.label(label);
        }
        FetchStage::Required | FetchStage::Everything => {}
    }
}

fn time_format_section_ui(ui: &mut Ui, timestamp_format: &mut TimestampFormat) {
    fn timestamp_example_ui(
        ui: &mut egui::Ui,
        timestamp: Timestamp,
        timestamp_format: TimestampFormat,
    ) {
        ui.horizontal(|ui| {
            ui.add_space(ui.spacing().icon_width + ui.spacing().icon_spacing);
            egui::Frame::new()
                .fill(ui.visuals().text_edit_bg_color())
                .corner_radius(2.0)
                .inner_margin(egui::Margin::symmetric(4, 2))
                .show(ui, |ui| {
                    ui.label(
                        SyntaxHighlightedBuilder::primitive(&timestamp.format(timestamp_format))
                            .into_widget_text(ui.style()),
                    );
                });
        });
    }

    let timestamp = re_log_types::Timestamp::from(
        jiff::Timestamp::from_str("2023-02-14 21:47:18Z").expect("the timestamp is valid"),
    );

    ui.re_radio_value(timestamp_format, TimestampFormat::utc(), "UTC");
    timestamp_example_ui(ui, timestamp, TimestampFormat::utc());
    ui.re_radio_value(
        timestamp_format,
        TimestampFormat::local_timezone(),
        "Local (show time zone)",
    );
    timestamp_example_ui(ui, timestamp, TimestampFormat::local_timezone());
    ui.re_radio_value(
        timestamp_format,
        TimestampFormat::local_timezone_implicit(),
        "Local (hide time zone)",
    );
    timestamp_example_ui(ui, timestamp, TimestampFormat::local_timezone_implicit());
    ui.horizontal(|ui| {
        ui.add_space(ui.spacing().icon_width + ui.spacing().icon_spacing);
        ui.label("Note: timestamps without time zone are ambiguous when copied elsewhere.");
    });

    ui.re_radio_value(
        timestamp_format,
        TimestampFormat::unix_epoch(),
        "Seconds since Unix epoch",
    );
    timestamp_example_ui(ui, timestamp, TimestampFormat::unix_epoch());
}

fn map_view_section_ui(ui: &mut Ui, mapbox_access_token: &mut String) {
    ui.horizontal(|ui| {
        // TODO(ab): needed for alignment, we should use egui flex instead
        ui.set_height(19.0);

        ui.label("Mapbox access token:").on_hover_ui(|ui| {
            ui.markdown_ui(
                "This token is used to enable Mapbox-based map view backgrounds.\n\n\
                Note that the token will be saved in clear text in the configuration file. \
                The token can also be set using the `RERUN_MAPBOX_ACCESS_TOKEN` environment \
                variable.",
            );
        });

        ui.add(egui::TextEdit::singleline(mapbox_access_token).password(true));
    });
}

fn video_section_ui(ui: &mut Ui, options: &mut VideoOptions) {
    #[cfg(not(target_arch = "wasm32"))]
    {
        ui.re_checkbox(
            &mut options.override_ffmpeg_path,
            "Override the FFmpeg binary path",
        )
        .on_hover_ui(|ui| {
            ui.markdown_ui(
                "By default, the viewer tries to automatically find a suitable FFmpeg binary in \
                the system's `PATH`. Enabling this option allows you to specify a custom path to \
                the FFmpeg binary.",
            );
        });

        ui.add_enabled_ui(options.override_ffmpeg_path, |ui| {
            ui.horizontal(|ui| {
                // TODO(ab): needed for alignment, we should use egui flex instead
                ui.set_height(19.0);

                ui.label("Path:");

                ui.add(egui::TextEdit::singleline(&mut options.ffmpeg_path));
            });
        });

        ffmpeg_path_status_ui(ui, options);
    }

    // This affects only the web target, so we don't need to show it on native.
    #[cfg(target_arch = "wasm32")]
    {
        use re_video::DecodeHardwareAcceleration;

        let hardware_acceleration = &mut options.hw_acceleration;
        ui.horizontal(|ui| {
            ui.label("Decoder:");
            egui::ComboBox::from_id_salt("video_decoder_hw_acceleration")
                .selected_text(hardware_acceleration.to_string())
                .show_ui(ui, |ui| {
                    ui.selectable_value(
                        hardware_acceleration,
                        DecodeHardwareAcceleration::Auto,
                        DecodeHardwareAcceleration::Auto.to_string(),
                    );
                    ui.selectable_value(
                        hardware_acceleration,
                        DecodeHardwareAcceleration::PreferSoftware,
                        DecodeHardwareAcceleration::PreferSoftware.to_string(),
                    );
                    ui.selectable_value(
                        hardware_acceleration,
                        DecodeHardwareAcceleration::PreferHardware,
                        DecodeHardwareAcceleration::PreferHardware.to_string(),
                    );
                });
            // Note that the setting is part of the video's cache key, so, if it changes, the cache
            // entries outdate automatically.
        });
    }
}

#[cfg(not(target_arch = "wasm32"))]
fn ffmpeg_path_status_ui(ui: &mut Ui, options: &VideoOptions) {
    use std::task::Poll;

    use re_video::{FFmpegVersion, FFmpegVersionParseError};

    let path = options
        .override_ffmpeg_path
        .then(|| std::path::Path::new(&options.ffmpeg_path));

    match FFmpegVersion::for_executable_poll(path) {
        Poll::Pending => {
            ui.loading_indicator("Checking FFmpeg version");
        }

        Poll::Ready(Ok(version)) => {
            if version.is_compatible() {
                ui.success_label(format!("FFmpeg found (version {version})"));
            } else {
                ui.error_label(format!("Incompatible FFmpeg version: {version}"));
            }
        }
        Poll::Ready(Err(FFmpegVersionParseError::ParseVersion { raw_version })) => {
            // We make this one a warning instead of an error because version parsing is flaky, and
            // it might end up still working.
            ui.warning_label(format!(
                "FFmpeg binary found but unable to parse version: {raw_version}"
            ));
        }

        Poll::Ready(Err(FFmpegVersionParseError::FFmpegNotFound(_path))) => {
            ui.error_label("The specified FFmpeg binary path does not exist or is not a file.");
        }

        Poll::Ready(Err(err)) => {
            ui.error_label(err.to_string());
        }
    }
}

fn separator_with_some_space(ui: &mut egui::Ui) {
    ui.add_space(10.0);
    ui.separator();
    ui.add_space(10.0);
}