use re_viewer_context::DisplayMode;
pub(crate) struct Navigation {
history: Vec<DisplayMode>,
start_mode: DisplayMode,
}
impl Default for Navigation {
fn default() -> Self {
Self {
history: Default::default(),
start_mode: DisplayMode::RedapServer(re_redap_browser::EXAMPLES_ORIGIN.clone()),
}
}
}
impl Navigation {
pub fn push(&mut self, display_mode: DisplayMode) {
re_log::debug!("Pushed display mode `{:?}`", display_mode);
self.history.push(display_mode);
}
pub fn push_start_mode(&mut self) {
self.push(self.start_mode.clone());
}
pub fn replace(&mut self, new_mode: DisplayMode) -> Option<DisplayMode> {
let previous = self.history.pop();
if previous.as_ref().is_none_or(|prev| prev != &new_mode) {
re_log::trace!("Navigated from {previous:?} to {new_mode:?}");
}
self.history.push(new_mode);
previous
}
pub fn pop(&mut self) -> Option<DisplayMode> {
let previous = self.history.pop();
re_log::debug!("Popped display mode `{:?}`", previous);
previous
}
pub fn peek(&self) -> &DisplayMode {
self.history.last().unwrap_or(&self.start_mode)
}
}