notedeck

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

options.rs (2801B)


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