use std::hash::Hash;
use re_log_types::EntityPath;
use crate::{ContainerId, SpaceViewId};
#[derive(Debug, Clone, Copy, Hash)]
pub enum CollapseScope {
StreamsTree,
BlueprintTree,
}
impl CollapseScope {
const ALL: [Self; 2] = [Self::StreamsTree, Self::BlueprintTree];
pub fn container(self, container_id: ContainerId) -> CollapsedId {
CollapsedId {
item: CollapseItem::Container(container_id),
scope: self,
}
}
pub fn space_view(self, space_view_id: SpaceViewId) -> CollapsedId {
CollapsedId {
item: CollapseItem::SpaceView(space_view_id),
scope: self,
}
}
pub fn data_result(self, space_view_id: SpaceViewId, entity_path: EntityPath) -> CollapsedId {
CollapsedId {
item: CollapseItem::DataResult(space_view_id, entity_path),
scope: self,
}
}
pub fn entity(self, entity_path: EntityPath) -> CollapsedId {
CollapsedId {
item: CollapseItem::Entity(entity_path),
scope: self,
}
}
}
#[derive(Debug, Clone, Hash)]
pub enum CollapseItem {
Container(ContainerId),
SpaceView(SpaceViewId),
DataResult(SpaceViewId, EntityPath),
Entity(EntityPath),
}
impl CollapseItem {
pub fn set_open_all(&self, ctx: &egui::Context, open: bool) {
for scope in CollapseScope::ALL {
let id = CollapsedId {
item: self.clone(),
scope,
};
id.set_open(ctx, open);
}
}
}
#[derive(Debug, Clone, Hash)]
pub struct CollapsedId {
item: CollapseItem,
scope: CollapseScope,
}
impl From<CollapsedId> for egui::Id {
fn from(id: CollapsedId) -> Self {
Self::new(id)
}
}
impl CollapsedId {
pub fn egui_id(&self) -> egui::Id {
self.clone().into()
}
pub fn is_open(&self, ctx: &egui::Context) -> Option<bool> {
egui::collapsing_header::CollapsingState::load(ctx, self.egui_id())
.map(|state| state.is_open())
}
pub fn set_open(&self, ctx: &egui::Context, open: bool) {
let mut collapsing_state = egui::collapsing_header::CollapsingState::load_with_default_open(
ctx,
self.egui_id(),
false,
);
collapsing_state.set_open(open);
collapsing_state.store(ctx);
}
}