Files
notedeck/crates/notedeck_columns/src/ui/note/options.rs
William Casarin bd352f76d4 feat: add scramble flag for development text scrambling
This commit introduces a new scramble option to help reduce distractions
during development by scrambling text using rot13. When enabled via the
new `--scramble` flag, text displayed in various views is transformed,
making it easier to focus on layout and behavior without reading the
actual content.

App & Args Updates

  - Added a `scramble: bool` field to the main application state (in `app.rs`).

  - Extended argument parsing (in `args.rs`) to recognize the `--scramble` flag.

NoteOptions Enhancement

  - Introduced a new bit flag `scramble_text` in `NoteOptions` with
    corresponding setter/getter methods.

UI Adjustments

  - Propagated the scramble flag through note rendering functions across
    navigation, timeline, and note view modules.

  - Updated several UI components (e.g., in `nav.rs`, `route.rs`, and
    `contents.rs`) to accept and apply the new note options.

Rot13 Implementation

  - Implemented a helper function (`rot13`) to scramble text
    conditionally when the scramble option is enabled.

This feature is intended for development builds only, offering a way to
obscure text content during UI tweaks and testing.

Signed-off-by: William Casarin <jb55@jb55.com>
2025-02-22 14:30:38 -08:00

76 lines
2.6 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: u64 {
const actionbar = 0b0000000000000001;
const note_previews = 0b0000000000000010;
const small_pfp = 0b0000000000000100;
const medium_pfp = 0b0000000000001000;
const wide = 0b0000000000010000;
const selectable_text = 0b0000000000100000;
const textmode = 0b0000000001000000;
const options_button = 0b0000000010000000;
const hide_media = 0b0000000100000000;
/// Scramble text so that its not distracting during development
const scramble_text = 0b0000001000000000;
}
}
impl Default for NoteOptions {
fn default() -> NoteOptions {
NoteOptions::options_button | NoteOptions::note_previews | NoteOptions::actionbar
}
}
macro_rules! create_bit_methods {
($fn_name:ident, $has_name:ident, $option:ident) => {
#[inline]
pub fn $fn_name(&mut self, enable: bool) {
if enable {
*self |= NoteOptions::$option;
} else {
*self &= !NoteOptions::$option;
}
}
#[inline]
pub fn $has_name(self) -> bool {
(self & NoteOptions::$option) == NoteOptions::$option
}
};
}
impl NoteOptions {
create_bit_methods!(set_small_pfp, has_small_pfp, small_pfp);
create_bit_methods!(set_medium_pfp, has_medium_pfp, medium_pfp);
create_bit_methods!(set_note_previews, has_note_previews, note_previews);
create_bit_methods!(set_selectable_text, has_selectable_text, selectable_text);
create_bit_methods!(set_textmode, has_textmode, textmode);
create_bit_methods!(set_actionbar, has_actionbar, actionbar);
create_bit_methods!(set_wide, has_wide, wide);
create_bit_methods!(set_options_button, has_options_button, options_button);
create_bit_methods!(set_hide_media, has_hide_media, hide_media);
create_bit_methods!(set_scramble_text, has_scramble_text, scramble_text);
pub fn new(is_universe_timeline: bool) -> Self {
let mut options = NoteOptions::default();
options.set_hide_media(is_universe_timeline);
options
}
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()
}
}
}