Files
notedeck/src/ui/note/options.rs
William Casarin af8d7d222c Add note wide mode for reposts
This adds a 'wide' note design for note previews. This is a mode
where the note contents does not have padding at the start. This makes
notes previews a bit nicer.

Screenshot: https://cdn.jb55.com/s/84271f386d564c34.png
Signed-off-by: William Casarin <jb55@jb55.com>
2024-07-10 10:56:15 -07:00

98 lines
2.4 KiB
Rust

use crate::ui::ProfilePic;
use bitflags::bitflags;
bitflags! {
// Attributes can be applied to flags types
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NoteOptions: u32 {
const actionbar = 0b00000001;
const note_previews = 0b00000010;
const small_pfp = 0b00000100;
const medium_pfp = 0b00001000;
const wide = 0b00010000;
}
}
impl NoteOptions {
#[inline]
pub fn has_actionbar(self) -> bool {
(self & NoteOptions::actionbar) == NoteOptions::actionbar
}
#[inline]
pub fn has_note_previews(self) -> bool {
(self & NoteOptions::note_previews) == NoteOptions::note_previews
}
#[inline]
pub fn has_small_pfp(self) -> bool {
(self & NoteOptions::small_pfp) == NoteOptions::small_pfp
}
#[inline]
pub fn has_medium_pfp(self) -> bool {
(self & NoteOptions::medium_pfp) == NoteOptions::medium_pfp
}
pub fn pfp_size(&self) -> f32 {
if self.has_small_pfp() {
ProfilePic::small_size()
} else if self.has_medium_pfp() {
ProfilePic::medium_size()
} else {
ProfilePic::default_size()
}
}
#[inline]
pub fn has_wide(self) -> bool {
(self & NoteOptions::wide) == NoteOptions::wide
}
#[inline]
pub fn set_wide(&mut self, enable: bool) {
if enable {
*self |= NoteOptions::wide;
} else {
*self &= !NoteOptions::wide;
}
}
#[inline]
pub fn set_small_pfp(&mut self, enable: bool) {
if enable {
*self |= NoteOptions::small_pfp;
} else {
*self &= !NoteOptions::small_pfp;
}
}
#[inline]
pub fn set_medium_pfp(&mut self, enable: bool) {
if enable {
*self |= NoteOptions::medium_pfp;
} else {
*self &= !NoteOptions::medium_pfp;
}
}
#[inline]
pub fn set_note_previews(&mut self, enable: bool) {
if enable {
*self |= NoteOptions::note_previews;
} else {
*self &= !NoteOptions::note_previews;
}
}
#[inline]
pub fn set_actionbar(&mut self, enable: bool) {
if enable {
*self |= NoteOptions::actionbar;
} else {
*self &= !NoteOptions::actionbar;
}
}
}