notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

preview.rs (682B)


      1 use crate::ui::View;
      2 
      3 pub struct PreviewConfig {
      4     pub is_mobile: bool,
      5 }
      6 
      7 pub trait Preview {
      8     type Prev: View;
      9 
     10     fn preview(cfg: PreviewConfig) -> Self::Prev;
     11 }
     12 
     13 pub struct PreviewApp {
     14     view: Box<dyn View>,
     15 }
     16 
     17 impl<V> From<V> for PreviewApp
     18 where
     19     V: View + 'static,
     20 {
     21     fn from(v: V) -> Self {
     22         PreviewApp::new(v)
     23     }
     24 }
     25 
     26 impl PreviewApp {
     27     pub fn new(view: impl View + 'static) -> PreviewApp {
     28         let view = Box::new(view);
     29         Self { view }
     30     }
     31 }
     32 
     33 impl eframe::App for PreviewApp {
     34     fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
     35         egui::CentralPanel::default().show(ctx, |ui| self.view.ui(ui));
     36     }
     37 }