previews: run previews as notedeck apps
This allows ./preview to be a notedeck app runner. I am currently using it for the ProfilePic app (which will because notedeck_viz) Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -1,37 +1,26 @@
|
||||
use crate::ui::View;
|
||||
|
||||
pub struct PreviewConfig {
|
||||
pub is_mobile: bool,
|
||||
}
|
||||
|
||||
pub trait Preview {
|
||||
type Prev: View;
|
||||
type Prev: notedeck::App;
|
||||
|
||||
fn preview(cfg: PreviewConfig) -> Self::Prev;
|
||||
}
|
||||
|
||||
pub struct PreviewApp {
|
||||
view: Box<dyn View>,
|
||||
}
|
||||
|
||||
impl<V> From<V> for PreviewApp
|
||||
where
|
||||
V: View + 'static,
|
||||
{
|
||||
fn from(v: V) -> Self {
|
||||
PreviewApp::new(v)
|
||||
}
|
||||
view: Box<dyn notedeck::App>,
|
||||
}
|
||||
|
||||
impl PreviewApp {
|
||||
pub fn new(view: impl View + 'static) -> PreviewApp {
|
||||
pub fn new(view: impl notedeck::App + 'static) -> PreviewApp {
|
||||
let view = Box::new(view);
|
||||
Self { view }
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for PreviewApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| self.view.ui(ui));
|
||||
impl notedeck::App for PreviewApp {
|
||||
fn update(&mut self, app_ctx: &mut notedeck::AppContext<'_>, ui: &mut egui::Ui) {
|
||||
self.view.update(app_ctx, ui);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user