options.rs (1968B)
1 use crate::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 = 1 << 0; 10 const HasNotePreviews = 1 << 1; 11 const SmallPfp = 1 << 2; 12 const MediumPfp = 1 << 3; 13 const Wide = 1 << 4; 14 const SelectableText = 1 << 5; 15 const Textmode = 1 << 6; 16 const OptionsButton = 1 << 7; 17 const HideMedia = 1 << 8; 18 /// Scramble text so that its not distracting during development 19 const ScrambleText = 1 << 9; 20 /// Is this a note preview? 21 const IsPreview = 1 << 10; 22 /// Is the content truncated? If the length is over a certain size it 23 /// will end with a ... and a "Show more" button. 24 const Truncate = 1 << 11; 25 /// Show note's client in the note content 26 const ClientNameTop = 1 << 12; 27 const ClientNameBottom = 1 << 13; 28 29 const RepliesNewestFirst = 1 << 14; 30 31 /// Show note's full created at date at the bottom 32 const FullCreatedDate = 1 << 15; 33 } 34 } 35 36 impl Default for NoteOptions { 37 fn default() -> NoteOptions { 38 NoteOptions::OptionsButton 39 | NoteOptions::HasNotePreviews 40 | NoteOptions::ActionBar 41 | NoteOptions::Truncate 42 } 43 } 44 45 impl NoteOptions { 46 pub fn new(is_universe_timeline: bool) -> Self { 47 let mut options = NoteOptions::default(); 48 options.set(NoteOptions::HideMedia, is_universe_timeline); 49 options 50 } 51 52 pub fn pfp_size(&self) -> i8 { 53 if self.contains(NoteOptions::SmallPfp) { 54 ProfilePic::small_size() 55 } else if self.contains(NoteOptions::MediumPfp) { 56 ProfilePic::medium_size() 57 } else { 58 ProfilePic::default_size() 59 } 60 } 61 }