options.rs (2630B)
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 /// Scramble text so that its not distracting during development 20 const scramble_text = 0b0000001000000000; 21 } 22 } 23 24 impl Default for NoteOptions { 25 fn default() -> NoteOptions { 26 NoteOptions::options_button | NoteOptions::note_previews | NoteOptions::actionbar 27 } 28 } 29 30 macro_rules! create_bit_methods { 31 ($fn_name:ident, $has_name:ident, $option:ident) => { 32 #[inline] 33 pub fn $fn_name(&mut self, enable: bool) { 34 if enable { 35 *self |= NoteOptions::$option; 36 } else { 37 *self &= !NoteOptions::$option; 38 } 39 } 40 41 #[inline] 42 pub fn $has_name(self) -> bool { 43 (self & NoteOptions::$option) == NoteOptions::$option 44 } 45 }; 46 } 47 48 impl NoteOptions { 49 create_bit_methods!(set_small_pfp, has_small_pfp, small_pfp); 50 create_bit_methods!(set_medium_pfp, has_medium_pfp, medium_pfp); 51 create_bit_methods!(set_note_previews, has_note_previews, note_previews); 52 create_bit_methods!(set_selectable_text, has_selectable_text, selectable_text); 53 create_bit_methods!(set_textmode, has_textmode, textmode); 54 create_bit_methods!(set_actionbar, has_actionbar, actionbar); 55 create_bit_methods!(set_wide, has_wide, wide); 56 create_bit_methods!(set_options_button, has_options_button, options_button); 57 create_bit_methods!(set_hide_media, has_hide_media, hide_media); 58 create_bit_methods!(set_scramble_text, has_scramble_text, scramble_text); 59 60 pub fn new(is_universe_timeline: bool) -> Self { 61 let mut options = NoteOptions::default(); 62 options.set_hide_media(is_universe_timeline); 63 options 64 } 65 66 pub fn pfp_size(&self) -> f32 { 67 if self.has_small_pfp() { 68 ProfilePic::small_size() 69 } else if self.has_medium_pfp() { 70 ProfilePic::medium_size() 71 } else { 72 ProfilePic::default_size() 73 } 74 } 75 }