notedeck

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

edit_deck.rs (2212B)


      1 use egui::Widget;
      2 
      3 use crate::deck_state::DeckState;
      4 
      5 use super::{
      6     configure_deck::{ConfigureDeckResponse, ConfigureDeckView},
      7     padding,
      8 };
      9 
     10 pub struct EditDeckView<'a> {
     11     config_view: ConfigureDeckView<'a>,
     12 }
     13 
     14 static EDIT_TEXT: &str = "Edit Deck";
     15 
     16 pub enum EditDeckResponse {
     17     Edit(ConfigureDeckResponse),
     18     Delete,
     19 }
     20 
     21 impl<'a> EditDeckView<'a> {
     22     pub fn new(state: &'a mut DeckState) -> Self {
     23         let config_view = ConfigureDeckView::new(state).with_create_text(EDIT_TEXT);
     24         Self { config_view }
     25     }
     26 
     27     pub fn ui(&mut self, ui: &mut egui::Ui) -> Option<EditDeckResponse> {
     28         let mut edit_deck_resp = None;
     29 
     30         padding(egui::Margin::symmetric(16.0, 4.0), ui, |ui| {
     31             if ui.add(delete_button()).clicked() {
     32                 edit_deck_resp = Some(EditDeckResponse::Delete);
     33             }
     34         });
     35 
     36         if let Some(config_resp) = self.config_view.ui(ui) {
     37             edit_deck_resp = Some(EditDeckResponse::Edit(config_resp))
     38         }
     39 
     40         edit_deck_resp
     41     }
     42 }
     43 
     44 fn delete_button() -> impl Widget {
     45     |ui: &mut egui::Ui| {
     46         let size = egui::vec2(108.0, 40.0);
     47         ui.allocate_ui_with_layout(size, egui::Layout::top_down(egui::Align::Center), |ui| {
     48             ui.add(
     49                 egui::Button::new("Delete Deck")
     50                     .fill(ui.visuals().error_fg_color)
     51                     .min_size(size),
     52             )
     53         })
     54         .inner
     55     }
     56 }
     57 
     58 mod preview {
     59     use crate::{
     60         deck_state::DeckState,
     61         ui::{Preview, PreviewConfig},
     62     };
     63 
     64     use super::EditDeckView;
     65     use notedeck::{App, AppContext};
     66 
     67     pub struct EditDeckPreview {
     68         state: DeckState,
     69     }
     70 
     71     impl EditDeckPreview {
     72         fn new() -> Self {
     73             let state = DeckState::default();
     74 
     75             EditDeckPreview { state }
     76         }
     77     }
     78 
     79     impl App for EditDeckPreview {
     80         fn update(&mut self, _app_ctx: &mut AppContext<'_>, ui: &mut egui::Ui) {
     81             EditDeckView::new(&mut self.state).ui(ui);
     82         }
     83     }
     84 
     85     impl Preview for EditDeckView<'_> {
     86         type Prev = EditDeckPreview;
     87 
     88         fn preview(_cfg: PreviewConfig) -> Self::Prev {
     89             EditDeckPreview::new()
     90         }
     91     }
     92 }