#[cfg(target_arch = "wasm32")]
mod browser;
mod memory;
#[cfg(target_arch = "wasm32")]
pub use browser::{BrowserHistory, HistoryMode};
pub use memory::MemoryHistory;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct EntryKey(pub u64);
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HistoryEntry {
pub url: String,
pub key: EntryKey,
}
pub trait History {
fn current(&self) -> HistoryEntry;
fn push(&mut self, url: &str) -> EntryKey;
fn replace(&mut self, url: &str);
fn back(&mut self);
fn forward(&mut self);
fn can_go_back(&self) -> bool;
fn can_go_forward(&self) -> bool;
fn poll(&mut self, ctx: &egui::Context) -> Option<HistoryEntry>;
fn shows_links(&self) -> bool {
false
}
fn hover_link(&mut self, _url: Option<&str>) {}
}
impl<H: History + ?Sized> History for Box<H> {
fn current(&self) -> HistoryEntry {
(**self).current()
}
fn push(&mut self, url: &str) -> EntryKey {
(**self).push(url)
}
fn replace(&mut self, url: &str) {
(**self).replace(url);
}
fn back(&mut self) {
(**self).back();
}
fn forward(&mut self) {
(**self).forward();
}
fn can_go_back(&self) -> bool {
(**self).can_go_back()
}
fn can_go_forward(&self) -> bool {
(**self).can_go_forward()
}
fn poll(&mut self, ctx: &egui::Context) -> Option<HistoryEntry> {
(**self).poll(ctx)
}
fn shows_links(&self) -> bool {
(**self).shows_links()
}
fn hover_link(&mut self, url: Option<&str>) {
(**self).hover_link(url);
}
}
pub fn default_history() -> impl History {
#[cfg(target_arch = "wasm32")]
{
BrowserHistory::new(HistoryMode::Path)
}
#[cfg(not(target_arch = "wasm32"))]
{
MemoryHistory::new("/")
}
}