notedeck

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

report.rs (2515B)


      1 use egui::{vec2, Margin, RichText, Sense};
      2 use notedeck::{fonts::get_font_size, NotedeckTextStyle, ReportType};
      3 use notedeck_ui::galley_centered_pos;
      4 
      5 pub struct ReportView<'a> {
      6     selected: &'a mut Option<ReportType>,
      7 }
      8 
      9 impl<'a> ReportView<'a> {
     10     pub fn new(selected: &'a mut Option<ReportType>) -> Self {
     11         Self { selected }
     12     }
     13 
     14     pub fn show(&mut self, ui: &mut egui::Ui) -> Option<ReportType> {
     15         let mut action = None;
     16 
     17         egui::Frame::new()
     18             .inner_margin(Margin::symmetric(48, 24))
     19             .show(ui, |ui| {
     20                 ui.spacing_mut().item_spacing = vec2(0.0, 8.0);
     21 
     22                 ui.add(egui::Label::new(
     23                     RichText::new("Report")
     24                         .size(get_font_size(ui.ctx(), &NotedeckTextStyle::Heading3)),
     25                 ));
     26 
     27                 ui.add_space(4.0);
     28 
     29                 for report_type in ReportType::ALL {
     30                     let is_selected = *self.selected == Some(*report_type);
     31                     if ui
     32                         .radio(is_selected, report_type.label())
     33                         .on_hover_cursor(egui::CursorIcon::PointingHand)
     34                         .clicked()
     35                     {
     36                         *self.selected = Some(*report_type);
     37                     }
     38                 }
     39 
     40                 ui.add_space(8.0);
     41 
     42                 let can_submit = self.selected.is_some();
     43 
     44                 let resp = ui.allocate_response(vec2(ui.available_width(), 40.0), Sense::click());
     45 
     46                 let fill = if !can_submit {
     47                     ui.visuals().widgets.inactive.bg_fill
     48                 } else if resp.hovered() {
     49                     notedeck_ui::colors::PINK.gamma_multiply(0.8)
     50                 } else {
     51                     notedeck_ui::colors::PINK
     52                 };
     53 
     54                 let painter = ui.painter_at(resp.rect);
     55                 painter.rect_filled(resp.rect, egui::CornerRadius::same(20), fill);
     56 
     57                 let galley = painter.layout_no_wrap(
     58                     "Submit Report".to_owned(),
     59                     NotedeckTextStyle::Body.get_font_id(ui.ctx()),
     60                     egui::Color32::WHITE,
     61                 );
     62 
     63                 painter.galley(
     64                     galley_centered_pos(&galley, resp.rect.center()),
     65                     galley,
     66                     egui::Color32::WHITE,
     67                 );
     68 
     69                 if can_submit && resp.clicked() {
     70                     action = *self.selected;
     71                 }
     72             });
     73 
     74         action
     75     }
     76 }