-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setting custom names to container (#5626)
### What As the title say ☝🏻 Decisions: - Keep "Viewport" in the name of the root container (see screenshot below). - Refactor some stuff: - moved `Contents` to re_viewer_contex (I actually been meaning to do that for a while but can't remember why now) - moved/renamed `SpaceViewName` to `ContentsName` in re_viewer_context⚠️ review commit by commit https://github.com/rerun-io/rerun/assets/49431240/cac22100-c0fb-4ff8-9fe0-195607c222a4 ```python import rerun as rr import rerun.blueprint as rrb rr.init( "rerun_example_demo", blueprint=rrb.Horizontal( rrb.Vertical( rrb.Spatial3DView(origin="/point3d"), rrb.Spatial3DView(origin="/point3d"), name="First Vertical", ), rrb.Vertical( rrb.Spatial3DView(origin="/point3d"), rrb.Spatial3DView(origin="/point3d"), name="Second Vertical", ), name="Top-Level", ), ) rr.connect() rr.log("point3d", rr.Points3D([0, 1, 2])) ``` <img width="263" alt="image" src="https://github.com/rerun-io/rerun/assets/49431240/7ca42f6c-209e-4fec-b5df-1a2ab2558e48"> ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using newly built examples: [app.rerun.io](https://app.rerun.io/pr/5626/index.html) * Using examples from latest `main` build: [app.rerun.io](https://app.rerun.io/pr/5626/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [app.rerun.io](https://app.rerun.io/pr/5626/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! - [PR Build Summary](https://build.rerun.io/pr/5626) - [Docs preview](https://rerun.io/preview/df3fd74ffb59adfb22bfa15b1b28fea2e916d2b5/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/df3fd74ffb59adfb22bfa15b1b28fea2e916d2b5/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
- Loading branch information
Showing
18 changed files
with
338 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
use std::convert::{TryFrom, TryInto}; | ||
|
||
use egui_tiles::TileId; | ||
|
||
use re_log_types::EntityPath; | ||
|
||
use crate::item::Item; | ||
use crate::{BlueprintId, BlueprintIdRegistry, ContainerId, SpaceViewId}; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
pub enum Contents { | ||
Container(ContainerId), | ||
SpaceView(SpaceViewId), | ||
} | ||
|
||
impl Contents { | ||
pub fn try_from(path: &EntityPath) -> Option<Self> { | ||
if path.starts_with(SpaceViewId::registry()) { | ||
Some(Self::SpaceView(SpaceViewId::from_entity_path(path))) | ||
} else if path.starts_with(ContainerId::registry()) { | ||
Some(Self::Container(ContainerId::from_entity_path(path))) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn as_entity_path(&self) -> EntityPath { | ||
match self { | ||
Self::Container(id) => id.as_entity_path(), | ||
Self::SpaceView(id) => id.as_entity_path(), | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn as_tile_id(&self) -> TileId { | ||
match self { | ||
Self::Container(id) => blueprint_id_to_tile_id(id), | ||
Self::SpaceView(id) => blueprint_id_to_tile_id(id), | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn as_item(&self) -> Item { | ||
match self { | ||
Contents::Container(container_id) => Item::Container(*container_id), | ||
Contents::SpaceView(space_view_id) => Item::SpaceView(*space_view_id), | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn as_container_id(&self) -> Option<ContainerId> { | ||
match self { | ||
Self::Container(id) => Some(*id), | ||
Self::SpaceView(_) => None, | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn as_space_view_id(&self) -> Option<SpaceViewId> { | ||
match self { | ||
Self::SpaceView(id) => Some(*id), | ||
Self::Container(_) => None, | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<Item> for Contents { | ||
type Error = (); | ||
|
||
fn try_from(item: Item) -> Result<Self, Self::Error> { | ||
(&item).try_into() | ||
} | ||
} | ||
|
||
impl TryFrom<&Item> for Contents { | ||
type Error = (); | ||
|
||
fn try_from(item: &Item) -> Result<Self, Self::Error> { | ||
match item { | ||
Item::Container(id) => Ok(Self::Container(*id)), | ||
Item::SpaceView(id) => Ok(Self::SpaceView(*id)), | ||
_ => Err(()), | ||
} | ||
} | ||
} | ||
|
||
impl From<SpaceViewId> for Contents { | ||
#[inline] | ||
fn from(id: SpaceViewId) -> Self { | ||
Self::SpaceView(id) | ||
} | ||
} | ||
|
||
impl From<ContainerId> for Contents { | ||
#[inline] | ||
fn from(id: ContainerId) -> Self { | ||
Self::Container(id) | ||
} | ||
} | ||
|
||
/// The name of a [`Contents`]. | ||
#[derive(Clone, Debug)] | ||
pub enum ContentsName { | ||
/// This [`Contents`] has been given a name by the user. | ||
Named(String), | ||
|
||
/// This [`Contents`] is unnamed and should be displayed with this placeholder name. | ||
Placeholder(String), | ||
} | ||
|
||
impl AsRef<str> for ContentsName { | ||
#[inline] | ||
fn as_ref(&self) -> &str { | ||
match self { | ||
ContentsName::Named(name) | ContentsName::Placeholder(name) => name, | ||
} | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn blueprint_id_to_tile_id<T: BlueprintIdRegistry>(id: &BlueprintId<T>) -> TileId { | ||
TileId::from_u64(id.hash()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.