-
Notifications
You must be signed in to change notification settings - Fork 373
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
Typename cleanup in SpaceViewClass framework #2321
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
107 changes: 107 additions & 0 deletions
107
crates/re_viewer_context/src/space_view/dyn_space_view_class.rs
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,107 @@ | ||
use nohash_hasher::IntSet; | ||
use re_data_store::EntityPropertyMap; | ||
use re_log_types::{ComponentName, EntityPath}; | ||
|
||
use crate::{Scene, SpaceViewId, ViewerContext}; | ||
|
||
/// First element is the primary component, all others are optional. | ||
/// | ||
/// TODO(andreas/clement): More formal definition of an archetype. | ||
pub type ArchetypeDefinition = vec1::Vec1<ComponentName>; | ||
|
||
re_string_interner::declare_new_type!( | ||
/// The unique name of a space view type. | ||
#[derive(serde::Deserialize, serde::Serialize)] | ||
pub struct SpaceViewClassName; | ||
); | ||
|
||
/// Defines a class of space view without any concrete types making it suitable for storage and interfacing. | ||
/// | ||
/// Implemented by [`crate::SpaceViewClass`]. | ||
/// | ||
/// Each Space View in the viewer's viewport has a single class assigned immutable at its creation time. | ||
/// The class defines all aspects of its behavior. | ||
/// It determines which entities are queried, how they are rendered, and how the user can interact with them. | ||
pub trait DynSpaceViewClass { | ||
/// Name of this space view class. | ||
/// | ||
/// Used for both ui display and identification. | ||
/// Must be unique within a viewer session. | ||
fn name(&self) -> SpaceViewClassName; | ||
|
||
/// Icon used to identify this space view class. | ||
fn icon(&self) -> &'static re_ui::Icon; | ||
|
||
/// Help text describing how to interact with this space view in the ui. | ||
fn help_text(&self, re_ui: &re_ui::ReUi, state: &dyn SpaceViewState) -> egui::WidgetText; | ||
|
||
/// Called once for every new space view instance of this class. | ||
/// | ||
/// The state is *not* persisted across viewer sessions, only shared frame-to-frame. | ||
fn new_state(&self) -> Box<dyn SpaceViewState>; | ||
|
||
/// Returns a new scene for this space view class. | ||
/// | ||
/// Called both to determine the supported archetypes and | ||
/// to populate a scene every frame. | ||
fn new_scene(&self) -> Box<dyn Scene>; | ||
|
||
/// Optional archetype of the Space View's blueprint properties. | ||
/// | ||
/// Blueprint components that only apply to the space view itself, not to the entities it displays. | ||
fn blueprint_archetype(&self) -> Option<ArchetypeDefinition>; | ||
|
||
/// Preferred aspect ratio for the ui tiles of this space view. | ||
fn preferred_tile_aspect_ratio(&self, state: &dyn SpaceViewState) -> Option<f32>; | ||
|
||
/// Executed before the scene is populated, can be use for heuristic & state updates before populating the scene. | ||
/// | ||
/// Is only allowed to access archetypes defined by [`Self::blueprint_archetype`] | ||
/// Passed entity properties are individual properties without propagated values. | ||
fn prepare_populate( | ||
&self, | ||
ctx: &mut ViewerContext<'_>, | ||
state: &mut dyn SpaceViewState, | ||
entity_paths: &IntSet<EntityPath>, | ||
entity_properties: &mut EntityPropertyMap, | ||
); | ||
|
||
/// Ui shown when the user selects a space view of this class. | ||
/// | ||
/// TODO(andreas): Should this be instead implemented via a registered `data_ui` of all blueprint relevant types? | ||
fn selection_ui( | ||
&self, | ||
ctx: &mut ViewerContext<'_>, | ||
ui: &mut egui::Ui, | ||
state: &mut dyn SpaceViewState, | ||
space_origin: &EntityPath, | ||
space_view_id: SpaceViewId, | ||
); | ||
|
||
/// Draws the ui for this space view type and handles ui events. | ||
/// | ||
/// The scene passed in was previously created by [`Self::new_scene`] and got populated by the time it is passed. | ||
/// The state passed in was previously created by [`Self::new_state`] and is kept frame-to-frame. | ||
fn ui( | ||
&self, | ||
ctx: &mut ViewerContext<'_>, | ||
ui: &mut egui::Ui, | ||
state: &mut dyn SpaceViewState, | ||
scene: Box<dyn Scene>, | ||
space_origin: &EntityPath, | ||
space_view_id: SpaceViewId, | ||
); | ||
} | ||
|
||
/// Unserialized frame to frame state of a space view. | ||
/// | ||
/// For any state that should be persisted, use the Blueprint! | ||
/// This state is used for transient state, such as animation or uncommitted ui state like dragging a camera. | ||
/// (on mouse release, the camera would be committed to the blueprint). | ||
pub trait SpaceViewState: std::any::Any { | ||
/// Converts itself to a reference of [`std::any::Any`], which enables downcasting to concrete types. | ||
fn as_any(&self) -> &dyn std::any::Any; | ||
|
||
/// Converts itself to a reference of [`std::any::Any`], which enables downcasting to concrete types. | ||
fn as_any_mut(&mut self) -> &mut dyn std::any::Any; | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
rather impressive that git didn't see this move