notedeck

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

context.rs (3037B)


      1 use enostr::Pubkey;
      2 use notedeck::{tr, Localization, ProfileContextSelection};
      3 
      4 use crate::context_menu::{context_button, stationary_arbitrary_menu_button};
      5 
      6 pub struct ProfileContextWidget {
      7     place_at: egui::Rect,
      8 }
      9 
     10 impl ProfileContextWidget {
     11     pub fn new(place_at: egui::Rect) -> Self {
     12         Self { place_at }
     13     }
     14 
     15     pub fn context_button(&self, ui: &mut egui::Ui, pubkey: &Pubkey) -> egui::Response {
     16         let painter = ui.painter_at(self.place_at);
     17 
     18         painter.circle_filled(
     19             self.place_at.center(),
     20             self.place_at.width() / 2.0,
     21             ui.visuals().window_fill,
     22         );
     23 
     24         context_button(ui, ui.id().with(pubkey), self.place_at.shrink(4.0))
     25     }
     26 
     27     pub fn context_menu(
     28         ui: &mut egui::Ui,
     29         i18n: &mut Localization,
     30         button_response: egui::Response,
     31         can_sign: bool,
     32         is_muted: bool,
     33     ) -> Option<ProfileContextSelection> {
     34         let mut context_selection: Option<ProfileContextSelection> = None;
     35 
     36         stationary_arbitrary_menu_button(ui, button_response, |ui| {
     37             ui.set_max_width(100.0);
     38 
     39             if ui
     40                 .button(tr!(
     41                     i18n,
     42                     "Add as column",
     43                     "Add new column to current deck from profile context menu"
     44                 ))
     45                 .clicked()
     46             {
     47                 context_selection = Some(ProfileContextSelection::AddProfileColumn);
     48                 ui.close_menu();
     49             }
     50 
     51             if ui
     52                 .button(tr!(i18n, "View as", "Switch active user to this profile"))
     53                 .clicked()
     54             {
     55                 context_selection = Some(ProfileContextSelection::ViewAs);
     56                 ui.close_menu();
     57             }
     58 
     59             if ui
     60                 .button(tr!(
     61                     i18n,
     62                     "Copy Link",
     63                     "Copy a damus.io link to the author's profile to keyboard"
     64                 ))
     65                 .clicked()
     66             {
     67                 context_selection = Some(ProfileContextSelection::CopyLink);
     68                 ui.close_menu();
     69             }
     70 
     71             if can_sign {
     72                 let label = if is_muted {
     73                     tr!(i18n, "Unmute User", "Unmute this user's content")
     74                 } else {
     75                     tr!(i18n, "Mute User", "Mute this user's content")
     76                 };
     77                 if ui.button(label).clicked() {
     78                     context_selection = Some(ProfileContextSelection::MuteUser);
     79                     ui.close_menu();
     80                 }
     81 
     82                 if ui
     83                     .button(tr!(
     84                         i18n,
     85                         "Report User",
     86                         "Report this user for objectionable content"
     87                     ))
     88                     .clicked()
     89                 {
     90                     context_selection = Some(ProfileContextSelection::ReportUser);
     91                     ui.close_menu();
     92                 }
     93             }
     94         });
     95 
     96         context_selection
     97     }
     98 }