-
Notifications
You must be signed in to change notification settings - Fork 369
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
base: main
Are you sure you want to change the base?
Conversation
aaaae09
to
b1bc2de
Compare
There was a problem hiding this 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
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" } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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:
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. |
This example is divided into two parts: | ||
|
||
The example is divided into two parts: |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
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
## 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. |
There was a problem hiding this comment.
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.); |
There was a problem hiding this comment.
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>> { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this 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
)
@rerun-bot approve |
What
control_panel.mp4
This adds an example on how to control an app using an extended version of Rerun.