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

Add example for extending the viewer with custom callbacks #8284

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

oxkitsune
Copy link
Contributor

What

control_panel.mp4

This adds an example on how to control an app using an extended version of Rerun.

@oxkitsune oxkitsune force-pushed the gijs/re_control_example branch from aaaae09 to b1bc2de Compare December 2, 2024 17:52
@teh-cmc teh-cmc added 🦀 Rust API Rust logging API examples Issues relating to the Rerun examples include in changelog labels Dec 4, 2024
@Wumpf Wumpf self-requested a review December 4, 2024 13:02
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like it a lot!

Feels a little bit thin on code docs but I think that's fine for the most part.

We also should add a small chapter on https://rerun.io/docs/howto/visualization/extend-ui for this

Comment on lines +24 to +30
re_crash_handler = { path = "../../../crates/utils/re_crash_handler" }
re_sdk_comms = { path = "../../../crates/store/re_sdk_comms", features = [
"server",
] }
re_viewer = { path = "../../../crates/viewer/re_viewer", default-features = false }
re_log = { path = "../../../crates/utils/re_log" }
re_error = { path = "../../../crates/utils/re_error" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have re-exports for all of those in rerun - we should use those when possible instead of depending on more crates. That likely requires adding some features to rerun

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ I feel strongly about this. External users building Rerun extensions should never have to import anything but rerun.

Rerun is complicated enough without having to try and understand its internal architecture and dependencies 😬

thumbnail_dimensions = [480, 291]
-->

Example showing how to control an app with the Rerun viewer, by extending the viewer UI.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the important part here is the communcation back. we have other examples that already talk about viewer extension in extend_viewer_ui. So maybe let's stress that a bit more:

Suggested change
Example showing how to control an app with the Rerun viewer, by extending the viewer UI.
Advanced example showing how to control an external application from the Rerun viewer, by extending the viewer UI.

Comment on lines +22 to +24
This example is divided into two parts:

The example is divided into two parts:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pick one ;-)

Similar to the [`extend_viewer_ui`](../extend_viewer_ui/) example, the `viewer` is wrapped in an `eframe` app, which allows us to handle the extra communication logic and define our own contorl UI using [`egui`](https://github.com/emilk/egui).

The communication between the `viewer` and the `app` is implemented in the [`comms`](src/comms/) module. It defines a simple protocol to send messages between the `viewer` and the `app` using [`bincode`](https://github.com/bincode-org/bincode).
The protocol supports really basic commands that the `viewer` can send to the `app`, such as logging a [`Boxes3D`](https://www.rerun.io/docs/reference/types/archetypes/boxes3d) or [`Point3D`](https://www.rerun.io/docs/reference/types/archetypes/points3d) to an entity, or changing the radius of a set of points that is being logged.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The protocol supports really basic commands that the `viewer` can send to the `app`, such as logging a [`Boxes3D`](https://www.rerun.io/docs/reference/types/archetypes/boxes3d) or [`Point3D`](https://www.rerun.io/docs/reference/types/archetypes/points3d) to an entity, or changing the radius of a set of points that is being logged.
The protocol supports basic commands that the `viewer` can send to the `app`, such as logging a [`Boxes3D`](https://www.rerun.io/docs/reference/types/archetypes/boxes3d) or [`Point3D`](https://www.rerun.io/docs/reference/types/archetypes/points3d) to an entity, or changing the radius of a set of points that is being logged.

The communication between the `viewer` and the `app` is implemented in the [`comms`](src/comms/) module. It defines a simple protocol to send messages between the `viewer` and the `app` using [`bincode`](https://github.com/bincode-org/bincode).
The protocol supports really basic commands that the `viewer` can send to the `app`, such as logging a [`Boxes3D`](https://www.rerun.io/docs/reference/types/archetypes/boxes3d) or [`Point3D`](https://www.rerun.io/docs/reference/types/archetypes/points3d) to an entity, or changing the radius of a set of points that is being logged.

## Testing it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a test really

Suggested change
## Testing it
## Usage

.. and yes I see that extend_viewer_ui did the same (can you plz fix that as well? thx :))

@@ -0,0 +1,116 @@
//! The example from our Getting Started page.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c&p mistake.
Recap instead what the app does and how it is expected to behave

}

let num_spheres =
((std::f32::consts::PI * current_offset) / current_radius.max(f32::EPSILON)).max(1.);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: a bit arbitrary what constants are imported and which ones aren't

pub fn add_handler(
&self,
handler: HandlerFn,
) -> std::result::Result<(), Box<dyn std::error::Error>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::result:: and std::error:: seems a bit overzealous

use super::protocol::Message;

#[derive(Debug)]
pub struct ControlViewer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to leave some doc strings for these key blocks of the example

Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(uh sorry that was meant to be request changes)

@Wumpf
Copy link
Member

Wumpf commented Dec 4, 2024

@rerun-bot approve

@Wumpf Wumpf changed the title Add custom callback example Add example for extending the viewer with custom callbacks Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples Issues relating to the Rerun examples include in changelog 🦀 Rust API Rust logging API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants