Description
Background
The current ViewerContext
is way too specific in terms of current recording/blueprint and visualisation thereof to be meaningfully used in for the upcoming "Redap browser". However, it does contain stuff of general usefulness that the Redap browser requires, such as the registry of component UI.
Proposal
Let's split it!
We currently already have a hierarchy of increasingly specific context structure:
ViewerContext -> ViewContext -> QueryContext
We propose to extend this hierarchy:
GlobalContext -> ViewerContext -> ViewContext -> QueryContext
|
v
RedapBrowserContext
Some subsystems, such as re_data_ui
and re_component_ui
, should be available globally (because we display stuff everywhere), but benefit from more specific context when available. For example a ClassId
component might be able to display the corresponding color if, and only if, a datastore and a latest-at query are known, enabling an AnnotationContext
to be queried. The ClassId
should also be correctly displayed (albeit without color) if there is no such knowledge.
To address that, we further propose to update these api to accept an enum of any of these contexts:
pub enum AnyContext<'a> {
Global(GlobalContext<'a>),
RedapBrowser(RedapBrowserContext<'a>),
Viewer(ViewerContext<'a>),
View(crate::ViewContext<'a>),
Query(crate::QueryContext<'a>),
}
Some code to get started
//TODO: Step 2
/// This is what we pass to `DataUi` and friends, which should do their best effort at displaying
/// stuff to the extent permitted by the actually provided context.
pub enum AnyContext<'a> {
Global(GlobalContext<'a>),
RedapBrowser(RedapBrowserContext<'a>),
Viewer(ViewerContext<'a>),
View(crate::ViewContext<'a>),
Query(crate::QueryContext<'a>),
}
//TODO: Step 1
/// This is application-wide context that applies to the whole Rerun viewer app (namely both the
/// local viewer and redap browser).
pub struct GlobalContext<'a> {
/// Global options for the whole viewer.
pub app_options: &'a AppOptions,
/// Runtime info about components and archetypes.
///
/// The component placeholder values for components are to be used when [`crate::ComponentFallbackProvider::try_provide_fallback`]
/// is not able to provide a value.
///
/// ⚠️ In almost all cases you should not use this directly, but instead use the currently best fitting
/// [`crate::ComponentFallbackProvider`] and call [`crate::ComponentFallbackProvider::fallback_for`] instead.
pub reflection: &'a re_types_core::reflection::Reflection,
/// How to display components.
pub component_ui_registry: &'a ComponentUiRegistry,
/// Registry of all known classes of views.
pub view_class_registry: &'a ViewClassRegistry,
/// The [`egui::Context`].
pub egui_ctx: &'a egui::Context,
/// The global `re_renderer` context, holds on to all GPU resources.
pub render_ctx: &'a re_renderer::RenderContext,
/// Interface for sending commands back to the app
pub command_sender: &'a CommandSender,
}
// TODO: Future truth?
pub struct RedapBrowserContext<'a> {
pub global_context: &'a GlobalContext<'a>,
/* probably more stuff later */
}
/// Common things needed by many parts of the viewer.
pub struct ViewerContext<'a> {
pub global_context: GlobalContext<'a>,
//TODO: step 0: use the one in store_context instead
pub cache: &'a Caches,
/// The current view of the store
pub store_context: &'a StoreContext<'a>,
/// Mapping from class and system to entities for the store
///
/// TODO(andreas): This should have a generation id, allowing to update heuristics(?)/visualizable entities etc.
pub maybe_visualizable_entities_per_visualizer: &'a PerVisualizer<MaybeVisualizableEntities>,
/// For each visualizer, the set of entities that have at least one matching indicator component.
///
/// TODO(andreas): Should we always do the intersection with `maybe_visualizable_entities_per_visualizer`
/// or are we ever interested in a (definitely-)non-visualizable but indicator-matching entity?
pub indicated_entities_per_visualizer: &'a PerVisualizer<IndicatedEntities>,
/// All the query results for this frame.
pub query_results: &'a HashMap<ViewId, DataQueryResult>,
/// UI config for the current recording (found in [`EntityDb`]).
pub rec_cfg: &'a RecordingConfig,
/// UI config for the current blueprint.
pub blueprint_cfg: &'a RecordingConfig,
/// The blueprint query used for resolving blueprint in this frame
pub blueprint_query: &'a LatestAtQuery,
/// Selection & hovering state.
// Note: for now, this remains here. We may decide to use this in the Redap browser as well.
pub selection_state: &'a ApplicationSelectionState,
/// Item that got focused on the last frame if any.
///
/// The focused item is cleared every frame, but views may react with side-effects
/// that last several frames.
pub focused_item: &'a Option<crate::Item>,
/// Helper object to manage drag-and-drop operations.
pub drag_and_drop_manager: &'a DragAndDropManager,
}
Activity