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>
This commit is contained in:
William Casarin
2025-02-22 14:25:46 -08:00
parent 32c7f83bd7
commit bd352f76d4
13 changed files with 125 additions and 43 deletions

View File

@@ -67,6 +67,7 @@ impl egui::Widget for &mut NoteContents<'_> {
/// Render an inline note preview with a border. These are used when
/// notes are references within a note
#[allow(clippy::too_many_arguments)]
pub fn render_note_preview(
ui: &mut egui::Ui,
ndb: &Ndb,
@@ -75,6 +76,7 @@ pub fn render_note_preview(
txn: &Transaction,
id: &[u8; 32],
parent: NoteKey,
note_options: NoteOptions,
) -> NoteResponse {
#[cfg(feature = "profiling")]
puffin::profile_function!();
@@ -112,7 +114,7 @@ pub fn render_note_preview(
ui.visuals().noninteractive().bg_stroke.color,
))
.show(ui, |ui| {
ui::NoteView::new(ndb, note_cache, img_cache, &note)
ui::NoteView::new(ndb, note_cache, img_cache, &note, note_options)
.actionbar(false)
.small_pfp(true)
.wide(true)
@@ -225,7 +227,11 @@ fn render_note_contents(
BlockType::Text => {
#[cfg(feature = "profiling")]
puffin::profile_scope!("text contents");
ui.add(egui::Label::new(block.as_str()).selectable(selectable));
if options.has_scramble_text() {
ui.add(egui::Label::new(rot13(block.as_str())).selectable(selectable));
} else {
ui.add(egui::Label::new(block.as_str()).selectable(selectable));
}
}
_ => {
@@ -236,7 +242,7 @@ fn render_note_contents(
});
let preview_note_action = if let Some((id, _block_str)) = inline_note {
render_note_preview(ui, ndb, note_cache, img_cache, txn, id, note_key).action
render_note_preview(ui, ndb, note_cache, img_cache, txn, id, note_key, options).action
} else {
None
};
@@ -253,6 +259,24 @@ fn render_note_contents(
NoteResponse::new(response.response).with_action(note_action)
}
fn rot13(input: &str) -> String {
input
.chars()
.map(|c| {
if c.is_ascii_lowercase() {
// Rotate lowercase letters
(((c as u8 - b'a' + 13) % 26) + b'a') as char
} else if c.is_ascii_uppercase() {
// Rotate uppercase letters
(((c as u8 - b'A' + 13) % 26) + b'A') as char
} else {
// Leave other characters unchanged
c
}
})
.collect()
}
fn image_carousel(
ui: &mut egui::Ui,
img_cache: &mut ImageCache,