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,

View File

@@ -76,8 +76,11 @@ impl<'a> NoteView<'a> {
note_cache: &'a mut NoteCache,
img_cache: &'a mut ImageCache,
note: &'a nostrdb::Note<'a>,
mut flags: NoteOptions,
) -> Self {
let flags = NoteOptions::actionbar | NoteOptions::note_previews;
flags.set_actionbar(true);
flags.set_note_previews(true);
let parent: Option<NoteKey> = None;
Self {
ndb,
@@ -89,11 +92,6 @@ impl<'a> NoteView<'a> {
}
}
pub fn note_options(mut self, options: NoteOptions) -> Self {
*self.options_mut() = options;
self
}
pub fn textmode(mut self, enable: bool) -> Self {
self.options_mut().set_textmode(enable);
self
@@ -287,7 +285,14 @@ impl<'a> NoteView<'a> {
.text_style(style.text_style()),
);
});
NoteView::new(self.ndb, self.note_cache, self.img_cache, &note_to_repost).show(ui)
NoteView::new(
self.ndb,
self.note_cache,
self.img_cache,
&note_to_repost,
self.flags,
)
.show(ui)
} else {
self.show_standard(ui)
}
@@ -393,6 +398,7 @@ impl<'a> NoteView<'a> {
self.ndb,
self.img_cache,
self.note_cache,
self.flags,
)
})
.inner;
@@ -464,6 +470,7 @@ impl<'a> NoteView<'a> {
self.ndb,
self.img_cache,
self.note_cache,
self.flags,
);
if action.is_some() {

View File

@@ -15,6 +15,9 @@ bitflags! {
const textmode = 0b0000000001000000;
const options_button = 0b0000000010000000;
const hide_media = 0b0000000100000000;
/// Scramble text so that its not distracting during development
const scramble_text = 0b0000001000000000;
}
}
@@ -52,6 +55,7 @@ impl NoteOptions {
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();

View File

@@ -4,7 +4,7 @@ use crate::media_upload::{nostrbuild_nip96_upload, MediaPath};
use crate::post::{downcast_post_buffer, MentionType, NewPost};
use crate::profile::get_display_name;
use crate::ui::search_results::SearchResultsView;
use crate::ui::{self, Preview, PreviewConfig};
use crate::ui::{self, note::NoteOptions, Preview, PreviewConfig};
use crate::Result;
use egui::text::{CCursorRange, LayoutJob};
use egui::text_edit::TextEditOutput;
@@ -27,6 +27,7 @@ pub struct PostView<'a> {
poster: FilledKeypair<'a>,
id_source: Option<egui::Id>,
inner_rect: egui::Rect,
note_options: NoteOptions,
}
#[derive(Clone)]
@@ -82,6 +83,7 @@ pub struct PostResponse {
}
impl<'a> PostView<'a> {
#[allow(clippy::too_many_arguments)]
pub fn new(
ndb: &'a Ndb,
draft: &'a mut Draft,
@@ -90,6 +92,7 @@ impl<'a> PostView<'a> {
note_cache: &'a mut NoteCache,
poster: FilledKeypair<'a>,
inner_rect: egui::Rect,
note_options: NoteOptions,
) -> Self {
let id_source: Option<egui::Id> = None;
PostView {
@@ -101,6 +104,7 @@ impl<'a> PostView<'a> {
id_source,
post_type,
inner_rect,
note_options,
}
}
@@ -302,6 +306,7 @@ impl<'a> PostView<'a> {
txn,
id.bytes(),
nostrdb::NoteKey::new(0),
self.note_options,
);
});
});
@@ -686,6 +691,7 @@ mod preview {
app.note_cache,
self.poster.to_filled(),
ui.available_rect_before_wrap(),
NoteOptions::default(),
)
.ui(&txn, ui);
}

View File

@@ -2,7 +2,10 @@ use enostr::{FilledKeypair, NoteId};
use nostrdb::Ndb;
use notedeck::{ImageCache, NoteCache};
use crate::{draft::Draft, ui};
use crate::{
draft::Draft,
ui::{self, note::NoteOptions},
};
use super::{PostResponse, PostType};
@@ -15,9 +18,11 @@ pub struct QuoteRepostView<'a> {
quoting_note: &'a nostrdb::Note<'a>,
id_source: Option<egui::Id>,
inner_rect: egui::Rect,
note_options: NoteOptions,
}
impl<'a> QuoteRepostView<'a> {
#[allow(clippy::too_many_arguments)]
pub fn new(
ndb: &'a Ndb,
poster: FilledKeypair<'a>,
@@ -26,6 +31,7 @@ impl<'a> QuoteRepostView<'a> {
draft: &'a mut Draft,
quoting_note: &'a nostrdb::Note<'a>,
inner_rect: egui::Rect,
note_options: NoteOptions,
) -> Self {
let id_source: Option<egui::Id> = None;
QuoteRepostView {
@@ -37,6 +43,7 @@ impl<'a> QuoteRepostView<'a> {
quoting_note,
id_source,
inner_rect,
note_options,
}
}
@@ -52,6 +59,7 @@ impl<'a> QuoteRepostView<'a> {
self.note_cache,
self.poster,
self.inner_rect,
self.note_options,
)
.id_source(id)
.ui(self.quoting_note.txn().unwrap(), ui)

View File

@@ -1,6 +1,6 @@
use crate::draft::Draft;
use crate::ui;
use crate::ui::note::{PostResponse, PostType};
use crate::ui::note::{NoteOptions, PostResponse, PostType};
use enostr::{FilledKeypair, NoteId};
use nostrdb::Ndb;
@@ -15,9 +15,11 @@ pub struct PostReplyView<'a> {
note: &'a nostrdb::Note<'a>,
id_source: Option<egui::Id>,
inner_rect: egui::Rect,
note_options: NoteOptions,
}
impl<'a> PostReplyView<'a> {
#[allow(clippy::too_many_arguments)]
pub fn new(
ndb: &'a Ndb,
poster: FilledKeypair<'a>,
@@ -26,6 +28,7 @@ impl<'a> PostReplyView<'a> {
img_cache: &'a mut ImageCache,
note: &'a nostrdb::Note<'a>,
inner_rect: egui::Rect,
note_options: NoteOptions,
) -> Self {
let id_source: Option<egui::Id> = None;
PostReplyView {
@@ -37,6 +40,7 @@ impl<'a> PostReplyView<'a> {
img_cache,
id_source,
inner_rect,
note_options,
}
}
@@ -67,11 +71,17 @@ impl<'a> PostReplyView<'a> {
egui::Frame::none()
.outer_margin(egui::Margin::same(note_offset))
.show(ui, |ui| {
ui::NoteView::new(self.ndb, self.note_cache, self.img_cache, self.note)
.actionbar(false)
.medium_pfp(true)
.options_button(true)
.show(ui);
ui::NoteView::new(
self.ndb,
self.note_cache,
self.img_cache,
self.note,
self.note_options,
)
.actionbar(false)
.medium_pfp(true)
.options_button(true)
.show(ui);
});
let id = self.id();
@@ -87,6 +97,7 @@ impl<'a> PostReplyView<'a> {
self.note_cache,
self.poster,
self.inner_rect,
self.note_options,
)
.id_source(id)
.ui(self.note.txn().unwrap(), ui)

View File

@@ -1,4 +1,7 @@
use crate::{actionbar::NoteAction, ui};
use crate::{
actionbar::NoteAction,
ui::{self, note::NoteOptions},
};
use egui::{Label, RichText, Sense};
use nostrdb::{Ndb, Note, NoteReply, Transaction};
use notedeck::{ImageCache, NoteCache};
@@ -11,6 +14,7 @@ pub fn reply_desc(
ndb: &Ndb,
img_cache: &mut ImageCache,
note_cache: &mut NoteCache,
note_options: NoteOptions,
) -> Option<NoteAction> {
#[cfg(feature = "profiling")]
puffin::profile_function!();
@@ -41,7 +45,7 @@ pub fn reply_desc(
if r.hovered() {
r.on_hover_ui_at_pointer(|ui| {
ui.set_max_width(400.0);
ui::NoteView::new(ndb, note_cache, img_cache, note)
ui::NoteView::new(ndb, note_cache, img_cache, note, note_options)
.actionbar(false)
.wide(true)
.show(ui);