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:
@@ -108,7 +108,7 @@ pub fn render_note_preview(
|
|||||||
.small_pfp(true)
|
.small_pfp(true)
|
||||||
.wide(true)
|
.wide(true)
|
||||||
.note_previews(false)
|
.note_previews(false)
|
||||||
.use_more_options_button(true)
|
.options_button(true)
|
||||||
.show(ui);
|
.show(ui);
|
||||||
|
|
||||||
if let Some(selection) = resp.option_selection {
|
if let Some(selection) = resp.option_selection {
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ pub struct NoteView<'a> {
|
|||||||
img_cache: &'a mut ImageCache,
|
img_cache: &'a mut ImageCache,
|
||||||
note: &'a nostrdb::Note<'a>,
|
note: &'a nostrdb::Note<'a>,
|
||||||
flags: NoteOptions,
|
flags: NoteOptions,
|
||||||
use_options: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct NoteResponse {
|
pub struct NoteResponse {
|
||||||
@@ -201,7 +200,6 @@ impl<'a> NoteView<'a> {
|
|||||||
img_cache,
|
img_cache,
|
||||||
note,
|
note,
|
||||||
flags,
|
flags,
|
||||||
use_options: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,11 +238,9 @@ impl<'a> NoteView<'a> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn use_more_options_button(self, enable: bool) -> Self {
|
pub fn options_button(mut self, enable: bool) -> Self {
|
||||||
Self {
|
self.options_mut().set_options_button(enable);
|
||||||
use_options: enable,
|
self
|
||||||
..self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn options(&self) -> NoteOptions {
|
pub fn options(&self) -> NoteOptions {
|
||||||
@@ -398,7 +394,7 @@ impl<'a> NoteView<'a> {
|
|||||||
note_cache: &mut NoteCache,
|
note_cache: &mut NoteCache,
|
||||||
note: &Note,
|
note: &Note,
|
||||||
profile: &Result<nostrdb::ProfileRecord<'_>, nostrdb::Error>,
|
profile: &Result<nostrdb::ProfileRecord<'_>, nostrdb::Error>,
|
||||||
use_options_button: bool,
|
options: NoteOptions,
|
||||||
) -> NoteResponse {
|
) -> NoteResponse {
|
||||||
let note_key = note.key().unwrap();
|
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);
|
let cached_note = note_cache.cached_note_or_insert_mut(note_key, note);
|
||||||
render_reltime(ui, cached_note, true);
|
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| {
|
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
||||||
let more_options_resp = more_options_button(ui, note_key, 8.0);
|
let more_options_resp = more_options_button(ui, note_key, 8.0);
|
||||||
options_context_menu(ui, more_options_resp)
|
options_context_menu(ui, more_options_resp)
|
||||||
@@ -447,7 +443,7 @@ impl<'a> NoteView<'a> {
|
|||||||
self.note_cache,
|
self.note_cache,
|
||||||
self.note,
|
self.note,
|
||||||
&profile,
|
&profile,
|
||||||
self.use_options,
|
self.options(),
|
||||||
)
|
)
|
||||||
.option_selection;
|
.option_selection;
|
||||||
})
|
})
|
||||||
@@ -494,7 +490,7 @@ impl<'a> NoteView<'a> {
|
|||||||
self.note_cache,
|
self.note_cache,
|
||||||
self.note,
|
self.note,
|
||||||
&profile,
|
&profile,
|
||||||
self.use_options,
|
self.options(),
|
||||||
)
|
)
|
||||||
.option_selection;
|
.option_selection;
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
|
|||||||
@@ -5,14 +5,15 @@ bitflags! {
|
|||||||
// Attributes can be applied to flags types
|
// Attributes can be applied to flags types
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct NoteOptions: u32 {
|
pub struct NoteOptions: u64 {
|
||||||
const actionbar = 0b00000001;
|
const actionbar = 0b0000000000000001;
|
||||||
const note_previews = 0b00000010;
|
const note_previews = 0b0000000000000010;
|
||||||
const small_pfp = 0b00000100;
|
const small_pfp = 0b0000000000000100;
|
||||||
const medium_pfp = 0b00001000;
|
const medium_pfp = 0b0000000000001000;
|
||||||
const wide = 0b00010000;
|
const wide = 0b0000000000010000;
|
||||||
const selectable_text = 0b00100000;
|
const selectable_text = 0b0000000000100000;
|
||||||
const textmode = 0b01000000;
|
const textmode = 0b0000000001000000;
|
||||||
|
const options_button = 0b0000000010000000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +37,8 @@ impl NoteOptions {
|
|||||||
create_setter!(set_selectable_text, selectable_text);
|
create_setter!(set_selectable_text, selectable_text);
|
||||||
create_setter!(set_textmode, textmode);
|
create_setter!(set_textmode, textmode);
|
||||||
create_setter!(set_actionbar, actionbar);
|
create_setter!(set_actionbar, actionbar);
|
||||||
|
create_setter!(set_wide, wide);
|
||||||
|
create_setter!(set_options_button, options_button);
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn has_actionbar(self) -> bool {
|
pub fn has_actionbar(self) -> bool {
|
||||||
@@ -67,6 +70,16 @@ impl NoteOptions {
|
|||||||
(self & NoteOptions::medium_pfp) == NoteOptions::medium_pfp
|
(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 {
|
pub fn pfp_size(&self) -> f32 {
|
||||||
if self.has_small_pfp() {
|
if self.has_small_pfp() {
|
||||||
ProfilePic::small_size()
|
ProfilePic::small_size()
|
||||||
@@ -76,18 +89,4 @@ impl NoteOptions {
|
|||||||
ProfilePic::default_size()
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ impl<'a> PostReplyView<'a> {
|
|||||||
ui::NoteView::new(self.ndb, self.note_cache, self.img_cache, self.note)
|
ui::NoteView::new(self.ndb, self.note_cache, self.img_cache, self.note)
|
||||||
.actionbar(false)
|
.actionbar(false)
|
||||||
.medium_pfp(true)
|
.medium_pfp(true)
|
||||||
.use_more_options_button(true)
|
.options_button(true)
|
||||||
.show(ui);
|
.show(ui);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ impl<'a> ThreadView<'a> {
|
|||||||
ui::NoteView::new(self.ndb, self.note_cache, self.img_cache, ¬e)
|
ui::NoteView::new(self.ndb, self.note_cache, self.img_cache, ¬e)
|
||||||
.note_previews(!self.textmode)
|
.note_previews(!self.textmode)
|
||||||
.textmode(self.textmode)
|
.textmode(self.textmode)
|
||||||
.use_more_options_button(!self.textmode)
|
.options_button(!self.textmode)
|
||||||
.show(ui);
|
.show(ui);
|
||||||
if let Some(bar_action) = note_response.action {
|
if let Some(bar_action) = note_response.action {
|
||||||
action = Some(bar_action);
|
action = Some(bar_action);
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ fn timeline_ui(
|
|||||||
let resp = ui::NoteView::new(ndb, note_cache, img_cache, ¬e)
|
let resp = ui::NoteView::new(ndb, note_cache, img_cache, ¬e)
|
||||||
.note_previews(!textmode)
|
.note_previews(!textmode)
|
||||||
.selectable_text(false)
|
.selectable_text(false)
|
||||||
.use_more_options_button(true)
|
.options_button(true)
|
||||||
.show(ui);
|
.show(ui);
|
||||||
|
|
||||||
if let Some(ba) = resp.action {
|
if let Some(ba) = resp.action {
|
||||||
|
|||||||
Reference in New Issue
Block a user