options.rs (3262B)
1 use crate::ui::ProfilePic; 2 use bitflags::bitflags; 3 4 bitflags! { 5 // Attributes can be applied to flags types 6 #[repr(transparent)] 7 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 8 pub struct NoteOptions: u64 { 9 const actionbar = 0b0000000000000001; 10 const note_previews = 0b0000000000000010; 11 const small_pfp = 0b0000000000000100; 12 const medium_pfp = 0b0000000000001000; 13 const wide = 0b0000000000010000; 14 const selectable_text = 0b0000000000100000; 15 const textmode = 0b0000000001000000; 16 const options_button = 0b0000000010000000; 17 const hide_media = 0b0000000100000000; 18 } 19 } 20 21 impl Default for NoteOptions { 22 fn default() -> NoteOptions { 23 NoteOptions::options_button | NoteOptions::note_previews | NoteOptions::actionbar 24 } 25 } 26 27 macro_rules! create_setter { 28 ($fn_name:ident, $option:ident) => { 29 #[inline] 30 pub fn $fn_name(&mut self, enable: bool) { 31 if enable { 32 *self |= NoteOptions::$option; 33 } else { 34 *self &= !NoteOptions::$option; 35 } 36 } 37 }; 38 } 39 40 impl NoteOptions { 41 create_setter!(set_small_pfp, small_pfp); 42 create_setter!(set_medium_pfp, medium_pfp); 43 create_setter!(set_note_previews, note_previews); 44 create_setter!(set_selectable_text, selectable_text); 45 create_setter!(set_textmode, textmode); 46 create_setter!(set_actionbar, actionbar); 47 create_setter!(set_wide, wide); 48 create_setter!(set_options_button, options_button); 49 create_setter!(set_hide_media, hide_media); 50 51 pub fn new(is_universe_timeline: bool) -> Self { 52 let mut options = NoteOptions::default(); 53 options.set_hide_media(is_universe_timeline); 54 options 55 } 56 57 #[inline] 58 pub fn has_actionbar(self) -> bool { 59 (self & NoteOptions::actionbar) == NoteOptions::actionbar 60 } 61 62 #[inline] 63 pub fn has_hide_media(self) -> bool { 64 (self & NoteOptions::hide_media) == NoteOptions::hide_media 65 } 66 67 #[inline] 68 pub fn has_selectable_text(self) -> bool { 69 (self & NoteOptions::selectable_text) == NoteOptions::selectable_text 70 } 71 72 #[inline] 73 pub fn has_textmode(self) -> bool { 74 (self & NoteOptions::textmode) == NoteOptions::textmode 75 } 76 77 #[inline] 78 pub fn has_note_previews(self) -> bool { 79 (self & NoteOptions::note_previews) == NoteOptions::note_previews 80 } 81 82 #[inline] 83 pub fn has_small_pfp(self) -> bool { 84 (self & NoteOptions::small_pfp) == NoteOptions::small_pfp 85 } 86 87 #[inline] 88 pub fn has_medium_pfp(self) -> bool { 89 (self & NoteOptions::medium_pfp) == NoteOptions::medium_pfp 90 } 91 92 #[inline] 93 pub fn has_wide(self) -> bool { 94 (self & NoteOptions::wide) == NoteOptions::wide 95 } 96 97 #[inline] 98 pub fn has_options_button(self) -> bool { 99 (self & NoteOptions::options_button) == NoteOptions::options_button 100 } 101 102 pub fn pfp_size(&self) -> f32 { 103 if self.has_small_pfp() { 104 ProfilePic::small_size() 105 } else if self.has_medium_pfp() { 106 ProfilePic::medium_size() 107 } else { 108 ProfilePic::default_size() 109 } 110 } 111 }