context.rs (2128B)
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 ) -> Option<ProfileContextSelection> { 32 let mut context_selection: Option<ProfileContextSelection> = None; 33 34 stationary_arbitrary_menu_button(ui, button_response, |ui| { 35 ui.set_max_width(100.0); 36 37 if ui 38 .button(tr!( 39 i18n, 40 "Add as column", 41 "Add new column to current deck from profile context menu" 42 )) 43 .clicked() 44 { 45 context_selection = Some(ProfileContextSelection::AddProfileColumn); 46 ui.close_menu(); 47 } 48 49 if ui 50 .button(tr!(i18n, "View as", "Switch active user to this profile")) 51 .clicked() 52 { 53 context_selection = Some(ProfileContextSelection::ViewAs); 54 ui.close_menu(); 55 } 56 57 if ui 58 .button(tr!( 59 i18n, 60 "Copy Link", 61 "Copy a damus.io link to the author's profile to keyboard" 62 )) 63 .clicked() 64 { 65 context_selection = Some(ProfileContextSelection::CopyLink); 66 ui.close_menu(); 67 } 68 }); 69 70 context_selection 71 } 72 }