notedeck

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

options.rs (2687B)


      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     }
     18 }
     19 
     20 macro_rules! create_setter {
     21     ($fn_name:ident, $option:ident) => {
     22         #[inline]
     23         pub fn $fn_name(&mut self, enable: bool) {
     24             if enable {
     25                 *self |= NoteOptions::$option;
     26             } else {
     27                 *self &= !NoteOptions::$option;
     28             }
     29         }
     30     };
     31 }
     32 
     33 impl NoteOptions {
     34     create_setter!(set_small_pfp, small_pfp);
     35     create_setter!(set_medium_pfp, medium_pfp);
     36     create_setter!(set_note_previews, note_previews);
     37     create_setter!(set_selectable_text, selectable_text);
     38     create_setter!(set_textmode, textmode);
     39     create_setter!(set_actionbar, actionbar);
     40     create_setter!(set_wide, wide);
     41     create_setter!(set_options_button, options_button);
     42 
     43     #[inline]
     44     pub fn has_actionbar(self) -> bool {
     45         (self & NoteOptions::actionbar) == NoteOptions::actionbar
     46     }
     47 
     48     #[inline]
     49     pub fn has_selectable_text(self) -> bool {
     50         (self & NoteOptions::selectable_text) == NoteOptions::selectable_text
     51     }
     52 
     53     #[inline]
     54     pub fn has_textmode(self) -> bool {
     55         (self & NoteOptions::textmode) == NoteOptions::textmode
     56     }
     57 
     58     #[inline]
     59     pub fn has_note_previews(self) -> bool {
     60         (self & NoteOptions::note_previews) == NoteOptions::note_previews
     61     }
     62 
     63     #[inline]
     64     pub fn has_small_pfp(self) -> bool {
     65         (self & NoteOptions::small_pfp) == NoteOptions::small_pfp
     66     }
     67 
     68     #[inline]
     69     pub fn has_medium_pfp(self) -> bool {
     70         (self & NoteOptions::medium_pfp) == NoteOptions::medium_pfp
     71     }
     72 
     73     #[inline]
     74     pub fn has_wide(self) -> bool {
     75         (self & NoteOptions::wide) == NoteOptions::wide
     76     }
     77 
     78     #[inline]
     79     pub fn has_options_button(self) -> bool {
     80         (self & NoteOptions::options_button) == NoteOptions::options_button
     81     }
     82 
     83     pub fn pfp_size(&self) -> f32 {
     84         if self.has_small_pfp() {
     85             ProfilePic::small_size()
     86         } else if self.has_medium_pfp() {
     87             ProfilePic::medium_size()
     88         } else {
     89             ProfilePic::default_size()
     90         }
     91     }
     92 }