diff --git a/src/ui/note/contents.rs b/src/ui/note/contents.rs index d0bdc1f..cb55050 100644 --- a/src/ui/note/contents.rs +++ b/src/ui/note/contents.rs @@ -108,7 +108,7 @@ pub fn render_note_preview( .small_pfp(true) .wide(true) .note_previews(false) - .use_more_options_button(true) + .options_button(true) .show(ui); if let Some(selection) = resp.option_selection { diff --git a/src/ui/note/mod.rs b/src/ui/note/mod.rs index cbe5155..6af5b21 100644 --- a/src/ui/note/mod.rs +++ b/src/ui/note/mod.rs @@ -31,7 +31,6 @@ pub struct NoteView<'a> { img_cache: &'a mut ImageCache, note: &'a nostrdb::Note<'a>, flags: NoteOptions, - use_options: bool, } pub struct NoteResponse { @@ -201,7 +200,6 @@ impl<'a> NoteView<'a> { img_cache, note, flags, - use_options: false, } } @@ -240,11 +238,9 @@ impl<'a> NoteView<'a> { self } - pub fn use_more_options_button(self, enable: bool) -> Self { - Self { - use_options: enable, - ..self - } + pub fn options_button(mut self, enable: bool) -> Self { + self.options_mut().set_options_button(enable); + self } pub fn options(&self) -> NoteOptions { @@ -398,7 +394,7 @@ impl<'a> NoteView<'a> { note_cache: &mut NoteCache, note: &Note, profile: &Result, nostrdb::Error>, - use_options_button: bool, + options: NoteOptions, ) -> NoteResponse { let note_key = note.key().unwrap(); @@ -409,7 +405,7 @@ impl<'a> NoteView<'a> { let cached_note = note_cache.cached_note_or_insert_mut(note_key, note); render_reltime(ui, cached_note, true); - if use_options_button { + if options.has_options_button() { ui.with_layout(Layout::right_to_left(Align::Center), |ui| { let more_options_resp = more_options_button(ui, note_key, 8.0); options_context_menu(ui, more_options_resp) @@ -447,7 +443,7 @@ impl<'a> NoteView<'a> { self.note_cache, self.note, &profile, - self.use_options, + self.options(), ) .option_selection; }) @@ -494,7 +490,7 @@ impl<'a> NoteView<'a> { self.note_cache, self.note, &profile, - self.use_options, + self.options(), ) .option_selection; ui.horizontal(|ui| { diff --git a/src/ui/note/options.rs b/src/ui/note/options.rs index 371e8b4..12cf04f 100644 --- a/src/ui/note/options.rs +++ b/src/ui/note/options.rs @@ -5,14 +5,15 @@ 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; - const selectable_text = 0b00100000; - const textmode = 0b01000000; + 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; } } @@ -36,6 +37,8 @@ impl NoteOptions { create_setter!(set_selectable_text, selectable_text); create_setter!(set_textmode, textmode); create_setter!(set_actionbar, actionbar); + create_setter!(set_wide, wide); + create_setter!(set_options_button, options_button); #[inline] pub fn has_actionbar(self) -> bool { @@ -67,6 +70,16 @@ impl NoteOptions { (self & NoteOptions::medium_pfp) == NoteOptions::medium_pfp } + #[inline] + pub fn has_wide(self) -> bool { + (self & NoteOptions::wide) == NoteOptions::wide + } + + #[inline] + pub fn has_options_button(self) -> bool { + (self & NoteOptions::options_button) == NoteOptions::options_button + } + pub fn pfp_size(&self) -> f32 { if self.has_small_pfp() { ProfilePic::small_size() @@ -76,18 +89,4 @@ impl NoteOptions { 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; - } - } } diff --git a/src/ui/note/reply.rs b/src/ui/note/reply.rs index c2ed606..c34d140 100644 --- a/src/ui/note/reply.rs +++ b/src/ui/note/reply.rs @@ -67,7 +67,7 @@ impl<'a> PostReplyView<'a> { ui::NoteView::new(self.ndb, self.note_cache, self.img_cache, self.note) .actionbar(false) .medium_pfp(true) - .use_more_options_button(true) + .options_button(true) .show(ui); }); diff --git a/src/ui/thread.rs b/src/ui/thread.rs index 6376e8a..76ca581 100644 --- a/src/ui/thread.rs +++ b/src/ui/thread.rs @@ -119,7 +119,7 @@ impl<'a> ThreadView<'a> { ui::NoteView::new(self.ndb, self.note_cache, self.img_cache, ¬e) .note_previews(!self.textmode) .textmode(self.textmode) - .use_more_options_button(!self.textmode) + .options_button(!self.textmode) .show(ui); if let Some(bar_action) = note_response.action { action = Some(bar_action); diff --git a/src/ui/timeline.rs b/src/ui/timeline.rs index 8aad4a4..bbea0a5 100644 --- a/src/ui/timeline.rs +++ b/src/ui/timeline.rs @@ -149,7 +149,7 @@ fn timeline_ui( let resp = ui::NoteView::new(ndb, note_cache, img_cache, ¬e) .note_previews(!textmode) .selectable_text(false) - .use_more_options_button(true) + .options_button(true) .show(ui); if let Some(ba) = resp.action {