notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

options.rs (1828B)


      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 header
     26         const ShowNoteClientTop  = 1 << 12;
     27         const ShowNoteClientBottom  = 1 << 13;
     28     }
     29 }
     30 
     31 impl Default for NoteOptions {
     32     fn default() -> NoteOptions {
     33         NoteOptions::OptionsButton
     34             | NoteOptions::HasNotePreviews
     35             | NoteOptions::ActionBar
     36             | NoteOptions::Truncate
     37     }
     38 }
     39 
     40 impl NoteOptions {
     41     pub fn new(is_universe_timeline: bool) -> Self {
     42         let mut options = NoteOptions::default();
     43         options.set(NoteOptions::HideMedia, is_universe_timeline);
     44         options
     45     }
     46 
     47     pub fn pfp_size(&self) -> i8 {
     48         if self.contains(NoteOptions::SmallPfp) {
     49             ProfilePic::small_size()
     50         } else if self.contains(NoteOptions::MediumPfp) {
     51             ProfilePic::medium_size()
     52         } else {
     53             ProfilePic::default_size()
     54         }
     55     }
     56 }