Skip to content

Commit

Permalink
refactor options
Browse files Browse the repository at this point in the history
  • Loading branch information
jprochazk committed May 23, 2024
1 parent 7908758 commit 4cb6c96
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
9 changes: 7 additions & 2 deletions crates/re_viewer/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ impl WebHandle {
}
}

// TODO(jprochazk): figure out a way to auto-generate these types on JS side

// Keep in sync with the `Panel` typedef in `rerun_js/web-viewer/index.js`
#[derive(Clone, Deserialize, strum_macros::EnumString)]
#[strum(serialize_all = "snake_case")]
enum Panel {
Expand All @@ -258,6 +261,7 @@ enum Panel {
Time,
}

// Keep in sync with the `PanelState` typedef in `rerun_js/web-viewer/index.js`
#[derive(Clone, Deserialize, strum_macros::EnumString)]
#[strum(serialize_all = "snake_case")]
enum PanelState {
Expand All @@ -277,13 +281,14 @@ impl From<PanelState> for re_types::blueprint::components::PanelState {
}
}

// Keep in sync with the `AppOptions` typedef in `rerun_js/web-viewer/index.js`
#[derive(Clone, Default, Deserialize)]
pub struct AppOptions {
url: Option<String>,
manifest_url: Option<String>,
render_backend: Option<String>,
hide_welcome_screen: Option<bool>,
panel_states: Option<PanelStateOverrides>,
panel_state_overrides: Option<PanelStateOverrides>,
}

#[derive(Clone, Default, Deserialize)]
Expand Down Expand Up @@ -326,7 +331,7 @@ fn create_app(cc: &eframe::CreationContext<'_>, app_options: AppOptions) -> crat
expect_data_soon: None,
force_wgpu_backend: None,
hide_welcome_screen: app_options.hide_welcome_screen.unwrap_or(false),
panel_state_overrides: app_options.panel_states.unwrap_or_default().into(),
panel_state_overrides: app_options.panel_state_overrides.unwrap_or_default().into(),
};
let re_ui = crate::customize_eframe_and_setup_renderer(cc);

Expand Down
25 changes: 18 additions & 7 deletions rerun_js/web-viewer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ function randomId() {
.join("");
}

/**
* @typedef {"top" | "blueprint" | "selection" | "time"} Panel
* @typedef {"hidden" | "collapsed" | "expanded"} PanelState
* @typedef {"webgpu" | "webgl"} Backend
*/

/**
* @typedef WebViewerOptions
* @property {string} [manifest_url] Use a different example manifest.
* @property {Backend} [render_backend] Force the viewer to use a specific rendering backend.
* @property {boolean} [hide_welcome_screen] Whether to hide the welcome screen in favor of a simpler one.
*/

Expand Down Expand Up @@ -53,12 +61,15 @@ export class WebViewer {
parent.append(this.#canvas);

/**
* @typedef {{
* hide_welcome_screen?: boolean
* }} AppOptions
* @typedef AppOptions
* @property {string} [url]
* @property {string} [manifest_url]
* @property {Backend} [render_backend]
* @property {Partial<{[K in Panel]: PanelState}>} [panel_state_overrides]
* @property {boolean} [hide_welcome_screen]
*/
/** @typedef {(typeof import("./re_viewer.js").WebHandle)} _WebHandleConstructor */
/** @typedef {_WebHandleConstructor & { new(options?: AppOptions): WebHandle }} WebHandleConstructor */
/** @typedef {(import("./re_viewer.js").WebHandle)} _WebHandle */
/** @typedef {{ new(app_options?: AppOptions): _WebHandle }} WebHandleConstructor */

let WebHandle_class = /** @type {WebHandleConstructor} */ (await load());
if (this.#state !== "starting") return;
Expand Down Expand Up @@ -189,8 +200,8 @@ export class WebViewer {
}

/**
* @param {"top" | "blueprint" | "selection" | "time"} panel
* @param {"hidden" | "collapsed" | "expanded"} state
* @param {Panel} panel
* @param {PanelState} state
*/
override_panel_state(panel, state) {
if (!this.#handle) {
Expand Down

0 comments on commit 4cb6c96

Please sign in to comment.