notedeck

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

welcome.rs (4191B)


      1 use egui::{vec2, Button, Label, Layout, RichText};
      2 use notedeck::{tr, Localization, NotedeckTextStyle};
      3 use notedeck_ui::padding;
      4 
      5 pub enum WelcomeResponse {
      6     CreateAccount,
      7     Login,
      8     Browse,
      9 }
     10 
     11 pub struct WelcomeView<'a> {
     12     i18n: &'a mut Localization,
     13 }
     14 
     15 impl<'a> WelcomeView<'a> {
     16     pub fn new(i18n: &'a mut Localization) -> Self {
     17         Self { i18n }
     18     }
     19 
     20     pub fn show(&mut self, ui: &mut egui::Ui) -> Option<WelcomeResponse> {
     21         let mut response = None;
     22 
     23         padding(16.0, ui, |ui| {
     24             ui.spacing_mut().item_spacing = vec2(0.0, 16.0);
     25 
     26             ui.with_layout(Layout::top_down(egui::Align::Center), |ui| {
     27                 ui.add_space(48.0);
     28 
     29                 ui.add(Label::new(
     30                     RichText::new(tr!(
     31                         self.i18n,
     32                         "Welcome to Notedeck",
     33                         "Welcome screen title"
     34                     ))
     35                     .text_style(NotedeckTextStyle::Heading2.text_style()),
     36                 ));
     37 
     38                 ui.add_space(8.0);
     39 
     40                 let max_width: f32 = 400.0;
     41                 ui.allocate_ui(vec2(max_width.min(ui.available_width()), 0.0), |ui| {
     42                     ui.add(
     43                         Label::new(
     44                             RichText::new(tr!(
     45                                 self.i18n,
     46                                 "Notedeck is a client for Nostr, an open protocol for decentralized social networking. Unlike traditional platforms, no single company controls your feed, your identity, or your data. Your account is a cryptographic key pair \u{2014} no emails, no passwords, no phone numbers.",
     47                                 "Welcome screen body text explaining what Notedeck and Nostr are"
     48                             ))
     49                             .text_style(NotedeckTextStyle::Body.text_style()),
     50                         )
     51                         .wrap(),
     52                     );
     53                 });
     54 
     55                 ui.add_space(24.0);
     56 
     57                 let button_size = vec2(200.0, 40.0);
     58                 let font_size =
     59                     notedeck::fonts::get_font_size(ui.ctx(), &NotedeckTextStyle::Body);
     60 
     61                 if ui
     62                     .add(
     63                         Button::new(
     64                             RichText::new(tr!(
     65                                 self.i18n,
     66                                 "Create Account",
     67                                 "Button to create a new Nostr account"
     68                             ))
     69                             .size(font_size),
     70                         )
     71                         .fill(notedeck_ui::colors::PINK)
     72                         .min_size(button_size),
     73                     )
     74                     .clicked()
     75                 {
     76                     response = Some(WelcomeResponse::CreateAccount);
     77                 }
     78 
     79                 ui.add_space(4.0);
     80 
     81                 if ui
     82                     .add(
     83                         Button::new(
     84                             RichText::new(tr!(
     85                                 self.i18n,
     86                                 "I have a Nostr key",
     87                                 "Button for existing Nostr users to log in with their key"
     88                             ))
     89                             .size(font_size),
     90                         )
     91                         .min_size(button_size),
     92                     )
     93                     .clicked()
     94                 {
     95                     response = Some(WelcomeResponse::Login);
     96                 }
     97 
     98                 ui.add_space(4.0);
     99 
    100                 if ui
    101                     .add(
    102                         Button::new(
    103                             RichText::new(tr!(
    104                                 self.i18n,
    105                                 "Just browsing",
    106                                 "Button to dismiss welcome and browse the app without an account"
    107                             ))
    108                             .size(font_size),
    109                         )
    110                         .frame(false),
    111                     )
    112                     .clicked()
    113                 {
    114                     response = Some(WelcomeResponse::Browse);
    115                 }
    116             });
    117         });
    118 
    119         response
    120     }
    121 }