options.rs (2426B)
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_bit_methods { 28 ($fn_name:ident, $has_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 #[inline] 39 pub fn $has_name(self) -> bool { 40 (self & NoteOptions::$option) == NoteOptions::$option 41 } 42 }; 43 } 44 45 impl NoteOptions { 46 create_bit_methods!(set_small_pfp, has_small_pfp, small_pfp); 47 create_bit_methods!(set_medium_pfp, has_medium_pfp, medium_pfp); 48 create_bit_methods!(set_note_previews, has_note_previews, note_previews); 49 create_bit_methods!(set_selectable_text, has_selectable_text, selectable_text); 50 create_bit_methods!(set_textmode, has_textmode, textmode); 51 create_bit_methods!(set_actionbar, has_actionbar, actionbar); 52 create_bit_methods!(set_wide, has_wide, wide); 53 create_bit_methods!(set_options_button, has_options_button, options_button); 54 create_bit_methods!(set_hide_media, has_hide_media, hide_media); 55 56 pub fn new(is_universe_timeline: bool) -> Self { 57 let mut options = NoteOptions::default(); 58 options.set_hide_media(is_universe_timeline); 59 options 60 } 61 62 pub fn pfp_size(&self) -> f32 { 63 if self.has_small_pfp() { 64 ProfilePic::small_size() 65 } else if self.has_medium_pfp() { 66 ProfilePic::medium_size() 67 } else { 68 ProfilePic::default_size() 69 } 70 } 71 }