use re_chunk::{Timeline, TimelineName};
use re_entity_db::EntityDb;
use crate::{AppContext, AppOptions, Cache, StoreCache, TimeControl};
#[derive(Clone)]
pub struct StoreViewContext<'a> {
pub app_ctx: &'a AppContext<'a>,
pub db: &'a EntityDb,
pub time_ctrl: &'a TimeControl,
pub caches: &'a StoreCache,
}
impl<'a> std::ops::Deref for StoreViewContext<'a> {
type Target = AppContext<'a>;
#[inline]
fn deref(&self) -> &Self::Target {
self.app_ctx
}
}
impl<'a> StoreViewContext<'a> {
#[must_use]
pub fn with_time_ctrl(&self, time_ctrl: &'a TimeControl) -> Self {
Self {
time_ctrl,
..self.clone()
}
}
pub fn query(&self) -> re_chunk_store::LatestAtQuery {
self.time_ctrl.current_query()
}
pub fn timeline_name(&self) -> TimelineName {
self.query().timeline()
}
pub fn timeline(&self) -> Timeline {
let name = self.timeline_name();
let typ = self.db.timeline_type(&name);
Timeline::new(name, typ)
}
pub fn render_ctx(&self) -> &re_renderer::RenderContext {
self.app_ctx.render_ctx
}
pub fn app_options(&self) -> &AppOptions {
self.app_ctx.app_options
}
pub fn component_ui_registry(&self) -> &crate::ComponentUiRegistry {
self.app_ctx.component_ui_registry
}
pub fn command_sender(&self) -> &crate::CommandSender {
self.app_ctx.command_sender
}
pub fn memoizer<C: Cache + Default, R>(&self, f: impl FnOnce(&mut C) -> R) -> R {
self.caches.memoizer(f)
}
}