refactor: make options_button a NoteOptions

No reason why this needs to be a standalone bool

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-09-26 09:31:11 -07:00
parent 1a94c21d96
commit a9cb734ef6
6 changed files with 32 additions and 37 deletions

View File

@@ -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 {

View File

@@ -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::ProfileRecord<'_>, 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| {

View File

@@ -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;
}
}
}

View File

@@ -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);
});

View File

@@ -119,7 +119,7 @@ impl<'a> ThreadView<'a> {
ui::NoteView::new(self.ndb, self.note_cache, self.img_cache, &note)
.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);

View File

@@ -149,7 +149,7 @@ fn timeline_ui(
let resp = ui::NoteView::new(ndb, note_cache, img_cache, &note)
.note_previews(!textmode)
.selectable_text(false)
.use_more_options_button(true)
.options_button(true)
.show(ui);
if let Some(ba) = resp.action {