notedeck

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

tos.rs (3912B)


      1 use egui::{vec2, Button, Label, Layout, RichText, ScrollArea};
      2 use notedeck::{tr, Localization, NotedeckTextStyle};
      3 use notedeck_ui::padding;
      4 
      5 const EULA_TEXT: &str = include_str!("../../../../docs/EULA.md");
      6 
      7 pub enum TosAcceptanceResponse {
      8     Accept,
      9 }
     10 
     11 pub struct TosAcceptanceView<'a> {
     12     i18n: &'a mut Localization,
     13     age_confirmed: &'a mut bool,
     14     tos_confirmed: &'a mut bool,
     15 }
     16 
     17 impl<'a> TosAcceptanceView<'a> {
     18     pub fn new(
     19         i18n: &'a mut Localization,
     20         age_confirmed: &'a mut bool,
     21         tos_confirmed: &'a mut bool,
     22     ) -> Self {
     23         Self {
     24             i18n,
     25             age_confirmed,
     26             tos_confirmed,
     27         }
     28     }
     29 
     30     pub fn show(&mut self, ui: &mut egui::Ui) -> Option<TosAcceptanceResponse> {
     31         let mut response = None;
     32 
     33         padding(16.0, ui, |ui| {
     34             ui.spacing_mut().item_spacing = vec2(0.0, 12.0);
     35 
     36             ui.add(Label::new(
     37                 RichText::new(tr!(
     38                     self.i18n,
     39                     "Terms of Service",
     40                     "TOS acceptance screen title"
     41                 ))
     42                 .text_style(NotedeckTextStyle::Heading2.text_style()),
     43             ));
     44 
     45             ui.add(Label::new(
     46                 RichText::new(tr!(
     47                     self.i18n,
     48                     "Please read and accept the following terms to continue.",
     49                     "TOS acceptance instruction text"
     50                 ))
     51                 .text_style(NotedeckTextStyle::Body.text_style()),
     52             ));
     53 
     54             let available = ui.available_height() - 120.0;
     55             let scroll_height = available.max(200.0);
     56 
     57             egui::Frame::group(ui.style())
     58                 .fill(ui.style().visuals.extreme_bg_color)
     59                 .inner_margin(12.0)
     60                 .show(ui, |ui| {
     61                     ScrollArea::vertical()
     62                         .max_height(scroll_height)
     63                         .show(ui, |ui| {
     64                             ui.add(
     65                                 Label::new(
     66                                     RichText::new(EULA_TEXT)
     67                                         .text_style(NotedeckTextStyle::Body.text_style()),
     68                                 )
     69                                 .wrap(),
     70                             );
     71                         });
     72                 });
     73 
     74             ui.checkbox(
     75                 self.age_confirmed,
     76                 tr!(
     77                     self.i18n,
     78                     "I confirm that I am at least 17 years old",
     79                     "Age verification checkbox label"
     80                 ),
     81             );
     82 
     83             ui.checkbox(
     84                 self.tos_confirmed,
     85                 tr!(
     86                     self.i18n,
     87                     "I have read and agree to the Terms of Service",
     88                     "TOS agreement checkbox label"
     89                 ),
     90             );
     91 
     92             let can_accept = *self.age_confirmed && *self.tos_confirmed;
     93             let button_size = vec2(200.0, 40.0);
     94 
     95             ui.allocate_ui_with_layout(button_size, Layout::top_down(egui::Align::Center), |ui| {
     96                 let font_size = notedeck::fonts::get_font_size(ui.ctx(), &NotedeckTextStyle::Body);
     97                 let button = Button::new(
     98                     RichText::new(tr!(
     99                         self.i18n,
    100                         "Accept and Continue",
    101                         "Button to accept TOS and continue using the app"
    102                     ))
    103                     .size(font_size),
    104                 )
    105                 .min_size(button_size);
    106 
    107                 let button = if can_accept {
    108                     button.fill(notedeck_ui::colors::PINK)
    109                 } else {
    110                     button
    111                 };
    112 
    113                 if ui.add_enabled(can_accept, button).clicked() {
    114                     response = Some(TosAcceptanceResponse::Accept);
    115                 }
    116             });
    117         });
    118 
    119         response
    120     }
    121 }