notedeck

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

global_popup.rs (1573B)


      1 use std::{cell::RefCell, rc::Rc};
      2 
      3 use egui::Sense;
      4 use egui_nav::{Nav, NavAction};
      5 
      6 use crate::{route::Route, ui, Damus};
      7 
      8 static MARGIN: f32 = 200.0;
      9 
     10 pub struct DesktopGlobalPopup {}
     11 
     12 impl DesktopGlobalPopup {
     13     pub fn show(routes: Vec<Route>, app: &mut Damus, ui: &mut egui::Ui) {
     14         if routes.is_empty() || !app.show_global_popup {
     15             return;
     16         }
     17 
     18         let rect = ui.ctx().screen_rect().shrink(MARGIN);
     19 
     20         let title = routes.last().map(|r| r.title());
     21 
     22         let app_ctx = Rc::new(RefCell::new(app));
     23 
     24         let resp = ui::FixedWindow::maybe_with_title(title).show(ui, rect, |ui| {
     25             let nav_response =
     26                 Nav::new(routes)
     27                     .title(false)
     28                     .navigating(false)
     29                     .show(ui, |ui, nav| {
     30                         if let Some(resp) =
     31                             nav.top().show_global_popup(&mut app_ctx.borrow_mut(), ui)
     32                         {
     33                             ui.allocate_rect(resp.rect, Sense::hover())
     34                         } else {
     35                             ui.label("") // TODO(kernelkind): not a great practice
     36                         }
     37                     });
     38 
     39             if let Some(NavAction::Returned) = nav_response.action {
     40                 app_ctx.borrow_mut().global_nav.pop();
     41             }
     42 
     43             nav_response.inner
     44         });
     45 
     46         let mut app = app_ctx.borrow_mut();
     47 
     48         if resp == ui::FixedWindowResponse::Closed {
     49             app.global_nav.pop();
     50             app.show_global_popup = false;
     51         }
     52     }
     53 }