use crate::Ui;
pub trait App {
fn ui(&mut self, ui: &mut Ui, backend: &mut dyn Backend);
fn on_exit(&mut self, _storage: &mut dyn Storage) {}
}
pub struct WebInfo {
pub web_location_hash: String,
}
pub trait Backend {
fn web_info(&self) -> Option<WebInfo> {
None
}
fn cpu_usage(&self) -> Option<f32>;
fn seconds_since_midnight(&self) -> Option<f64> {
None
}
fn quit(&mut self) {}
fn new_texture_srgba_premultiplied(
&mut self,
size: (usize, usize),
pixels: &[crate::Srgba],
) -> crate::TextureId;
}
pub trait Storage {
fn get_string(&self, key: &str) -> Option<&str>;
fn set_string(&mut self, key: &str, value: String);
}
#[cfg(feature = "serde_json")]
pub fn get_value<T: serde::de::DeserializeOwned>(storage: &dyn Storage, key: &str) -> Option<T> {
storage
.get_string(key)
.and_then(|value| serde_json::from_str(value).ok())
}
#[cfg(feature = "serde_json")]
pub fn set_value<T: serde::Serialize>(storage: &mut dyn Storage, key: &str, value: &T) {
storage.set_string(key, serde_json::to_string(value).unwrap());
}
pub const APP_KEY: &str = "app";