mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-23 11:14:19 +01:00
columns: clean up flags, refactor content rendering
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -592,12 +592,12 @@ fn get_note_options(args: ColumnsArgs, settings_handler: &mut SettingsHandler) -
|
|||||||
args.is_flag_set(ColumnsFlag::NoMedia),
|
args.is_flag_set(ColumnsFlag::NoMedia),
|
||||||
);
|
);
|
||||||
note_options.set(
|
note_options.set(
|
||||||
NoteOptions::ShowNoteClientTop,
|
NoteOptions::ClientNameTop,
|
||||||
ShowSourceClientOption::Top == settings_handler.show_source_client().into()
|
ShowSourceClientOption::Top == settings_handler.show_source_client().into()
|
||||||
|| args.is_flag_set(ColumnsFlag::ShowNoteClientTop),
|
|| args.is_flag_set(ColumnsFlag::ShowNoteClientTop),
|
||||||
);
|
);
|
||||||
note_options.set(
|
note_options.set(
|
||||||
NoteOptions::ShowNoteClientBottom,
|
NoteOptions::ClientNameBottom,
|
||||||
ShowSourceClientOption::Bottom == settings_handler.show_source_client().into()
|
ShowSourceClientOption::Bottom == settings_handler.show_source_client().into()
|
||||||
|| args.is_flag_set(ColumnsFlag::ShowNoteClientBottom),
|
|| args.is_flag_set(ColumnsFlag::ShowNoteClientBottom),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ impl From<ShowSourceClientOption> for String {
|
|||||||
|
|
||||||
impl From<NoteOptions> for ShowSourceClientOption {
|
impl From<NoteOptions> for ShowSourceClientOption {
|
||||||
fn from(note_options: NoteOptions) -> Self {
|
fn from(note_options: NoteOptions) -> Self {
|
||||||
if note_options.contains(NoteOptions::ShowNoteClientTop) {
|
if note_options.contains(NoteOptions::ClientNameTop) {
|
||||||
ShowSourceClientOption::Top
|
ShowSourceClientOption::Top
|
||||||
} else if note_options.contains(NoteOptions::ShowNoteClientBottom) {
|
} else if note_options.contains(NoteOptions::ClientNameBottom) {
|
||||||
ShowSourceClientOption::Bottom
|
ShowSourceClientOption::Bottom
|
||||||
} else {
|
} else {
|
||||||
ShowSourceClientOption::Hide
|
ShowSourceClientOption::Hide
|
||||||
@@ -68,16 +68,16 @@ impl ShowSourceClientOption {
|
|||||||
pub fn set_note_options(self, note_options: &mut NoteOptions) {
|
pub fn set_note_options(self, note_options: &mut NoteOptions) {
|
||||||
match self {
|
match self {
|
||||||
Self::Hide => {
|
Self::Hide => {
|
||||||
note_options.set(NoteOptions::ShowNoteClientTop, false);
|
note_options.set(NoteOptions::ClientNameTop, false);
|
||||||
note_options.set(NoteOptions::ShowNoteClientBottom, false);
|
note_options.set(NoteOptions::ClientNameBottom, false);
|
||||||
}
|
}
|
||||||
Self::Bottom => {
|
Self::Bottom => {
|
||||||
note_options.set(NoteOptions::ShowNoteClientTop, false);
|
note_options.set(NoteOptions::ClientNameTop, false);
|
||||||
note_options.set(NoteOptions::ShowNoteClientBottom, true);
|
note_options.set(NoteOptions::ClientNameBottom, true);
|
||||||
}
|
}
|
||||||
Self::Top => {
|
Self::Top => {
|
||||||
note_options.set(NoteOptions::ShowNoteClientTop, true);
|
note_options.set(NoteOptions::ClientNameTop, true);
|
||||||
note_options.set(NoteOptions::ShowNoteClientBottom, false);
|
note_options.set(NoteOptions::ClientNameBottom, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -292,12 +292,12 @@ struct ThreadNote<'a> {
|
|||||||
|
|
||||||
impl<'a> ThreadNote<'a> {
|
impl<'a> ThreadNote<'a> {
|
||||||
fn options(&self, mut cur_options: NoteOptions) -> NoteOptions {
|
fn options(&self, mut cur_options: NoteOptions) -> NoteOptions {
|
||||||
cur_options.set(NoteOptions::ShowCreatedAtBottom, true);
|
|
||||||
match self.note_type {
|
match self.note_type {
|
||||||
ThreadNoteType::Chain { root: _ } => cur_options,
|
ThreadNoteType::Chain { root: _ } => cur_options,
|
||||||
ThreadNoteType::Selected { root: _ } => {
|
ThreadNoteType::Selected { root: _ } => {
|
||||||
cur_options.set(NoteOptions::Wide, true);
|
cur_options.set(NoteOptions::Wide, true);
|
||||||
cur_options.set(NoteOptions::SelectableText, true);
|
cur_options.set(NoteOptions::SelectableText, true);
|
||||||
|
cur_options.set(NoteOptions::FullCreatedDate, true);
|
||||||
cur_options
|
cur_options
|
||||||
}
|
}
|
||||||
ThreadNoteType::Reply => cur_options,
|
ThreadNoteType::Reply => cur_options,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use egui::{Color32, Hyperlink, Label, RichText};
|
use egui::{Color32, Hyperlink, Label, RichText};
|
||||||
use nostrdb::{BlockType, Mention, Note, NoteKey, Transaction};
|
use nostrdb::{BlockType, Mention, Note, NoteKey, Transaction};
|
||||||
|
use notedeck::Localization;
|
||||||
use notedeck::{
|
use notedeck::{
|
||||||
time_format, update_imeta_blurhashes, IsFollowing, NoteCache, NoteContext, NotedeckTextStyle,
|
time_format, update_imeta_blurhashes, IsFollowing, NoteCache, NoteContext, NotedeckTextStyle,
|
||||||
};
|
};
|
||||||
@@ -42,14 +43,6 @@ impl<'a, 'd> NoteContents<'a, 'd> {
|
|||||||
|
|
||||||
impl egui::Widget for &mut NoteContents<'_, '_> {
|
impl egui::Widget for &mut NoteContents<'_, '_> {
|
||||||
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
|
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
|
||||||
let create_at_bottom = self.options.contains(NoteOptions::ShowCreatedAtBottom);
|
|
||||||
if self.options.contains(NoteOptions::ShowNoteClientTop) {
|
|
||||||
render_client(ui, self.note_context.note_cache, self.note, false);
|
|
||||||
}
|
|
||||||
// bottom created at only on selected note
|
|
||||||
if create_at_bottom {
|
|
||||||
self.options.set(NoteOptions::ShowCreatedAtBottom, false);
|
|
||||||
}
|
|
||||||
let result = render_note_contents(
|
let result = render_note_contents(
|
||||||
ui,
|
ui,
|
||||||
self.note_context,
|
self.note_context,
|
||||||
@@ -58,44 +51,27 @@ impl egui::Widget for &mut NoteContents<'_, '_> {
|
|||||||
self.options,
|
self.options,
|
||||||
self.jobs,
|
self.jobs,
|
||||||
);
|
);
|
||||||
ui.horizontal(|ui| {
|
|
||||||
if create_at_bottom {
|
|
||||||
secondary_label(
|
|
||||||
ui,
|
|
||||||
time_format(self.note_context.i18n, self.note.created_at()),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.options.contains(NoteOptions::ShowNoteClientBottom) {
|
|
||||||
render_client(
|
|
||||||
ui,
|
|
||||||
self.note_context.note_cache,
|
|
||||||
self.note,
|
|
||||||
create_at_bottom,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
self.action = result.action;
|
self.action = result.action;
|
||||||
result.response
|
result.response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[profiling::function]
|
fn render_client_name(ui: &mut egui::Ui, note_cache: &mut NoteCache, note: &Note, before: bool) {
|
||||||
fn render_client(ui: &mut egui::Ui, note_cache: &mut NoteCache, note: &Note, before: bool) {
|
|
||||||
let cached_note = note_cache.cached_note_or_insert_mut(note.key().unwrap(), note);
|
let cached_note = note_cache.cached_note_or_insert_mut(note.key().unwrap(), note);
|
||||||
|
|
||||||
match cached_note.client.as_deref() {
|
let Some(client) = cached_note.client.as_ref() else {
|
||||||
Some(client) if !client.is_empty() => {
|
return;
|
||||||
ui.horizontal(|ui| {
|
};
|
||||||
|
|
||||||
|
if client.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if before {
|
if before {
|
||||||
secondary_label(ui, "⋅");
|
secondary_label(ui, "⋅");
|
||||||
}
|
}
|
||||||
|
|
||||||
secondary_label(ui, format!("via {client}"));
|
secondary_label(ui, format!("via {client}"));
|
||||||
});
|
|
||||||
}
|
|
||||||
_ => return,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Render an inline note preview with a border. These are used when
|
/// Render an inline note preview with a border. These are used when
|
||||||
@@ -144,9 +120,57 @@ pub fn render_note_preview(
|
|||||||
.show(ui)
|
.show(ui)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Render note contents and surrounding info (client name, full date timestamp)
|
||||||
|
fn render_note_contents(
|
||||||
|
ui: &mut egui::Ui,
|
||||||
|
note_context: &mut NoteContext,
|
||||||
|
txn: &Transaction,
|
||||||
|
note: &Note,
|
||||||
|
options: NoteOptions,
|
||||||
|
jobs: &mut JobsCache,
|
||||||
|
) -> NoteResponse {
|
||||||
|
if options.contains(NoteOptions::ClientNameTop) {
|
||||||
|
let before_date = false;
|
||||||
|
render_client_name(ui, note_context.note_cache, note, before_date);
|
||||||
|
}
|
||||||
|
|
||||||
|
let response = render_undecorated_note_contents(ui, note_context, txn, note, options, jobs);
|
||||||
|
|
||||||
|
ui.horizontal_wrapped(|ui| {
|
||||||
|
note_bottom_metadata_ui(
|
||||||
|
ui,
|
||||||
|
note_context.i18n,
|
||||||
|
note_context.note_cache,
|
||||||
|
note,
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
response
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Client name, full timestamp, etc
|
||||||
|
fn note_bottom_metadata_ui(
|
||||||
|
ui: &mut egui::Ui,
|
||||||
|
i18n: &mut Localization,
|
||||||
|
note_cache: &mut NoteCache,
|
||||||
|
note: &Note,
|
||||||
|
options: NoteOptions,
|
||||||
|
) {
|
||||||
|
let show_full_date = options.contains(NoteOptions::FullCreatedDate);
|
||||||
|
|
||||||
|
if show_full_date {
|
||||||
|
secondary_label(ui, time_format(i18n, note.created_at()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.contains(NoteOptions::ClientNameBottom) {
|
||||||
|
render_client_name(ui, note_cache, note, show_full_date);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
#[profiling::function]
|
#[profiling::function]
|
||||||
pub fn render_note_contents<'a>(
|
fn render_undecorated_note_contents<'a>(
|
||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
note_context: &mut NoteContext,
|
note_context: &mut NoteContext,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use crate::{
|
|||||||
PulseAlpha, Username,
|
PulseAlpha, Username,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use contents::{render_note_contents, render_note_preview, NoteContents};
|
pub use contents::{render_note_preview, NoteContents};
|
||||||
pub use context::NoteContextButton;
|
pub use context::NoteContextButton;
|
||||||
use notedeck::get_current_wallet;
|
use notedeck::get_current_wallet;
|
||||||
use notedeck::note::ZapTargetAmount;
|
use notedeck::note::ZapTargetAmount;
|
||||||
@@ -366,11 +366,11 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
flags: NoteOptions,
|
flags: NoteOptions,
|
||||||
) {
|
) {
|
||||||
let horiz_resp = ui
|
let horiz_resp = ui
|
||||||
.horizontal(|ui| {
|
.horizontal_wrapped(|ui| {
|
||||||
ui.spacing_mut().item_spacing.x = if is_narrow(ui.ctx()) { 1.0 } else { 2.0 };
|
ui.spacing_mut().item_spacing.x = if is_narrow(ui.ctx()) { 1.0 } else { 2.0 };
|
||||||
let response = ui
|
let response = ui
|
||||||
.add(Username::new(i18n, profile.as_ref().ok(), note.pubkey()).abbreviated(20));
|
.add(Username::new(i18n, profile.as_ref().ok(), note.pubkey()).abbreviated(20));
|
||||||
if !flags.contains(NoteOptions::ShowCreatedAtBottom) {
|
if !flags.contains(NoteOptions::FullCreatedDate) {
|
||||||
return render_notetime(ui, i18n, note.created_at(), true).response;
|
return render_notetime(ui, i18n, note.created_at(), true).response;
|
||||||
}
|
}
|
||||||
response
|
response
|
||||||
@@ -508,8 +508,6 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
let pfp_rect = pfp_resp.bounding_rect;
|
let pfp_rect = pfp_resp.bounding_rect;
|
||||||
let mut note_action: Option<NoteAction> = pfp_resp.into_action(self.note.pubkey());
|
let mut note_action: Option<NoteAction> = pfp_resp.into_action(self.note.pubkey());
|
||||||
|
|
||||||
self.flags.set(NoteOptions::ShowCreatedAtBottom, false);
|
|
||||||
|
|
||||||
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
|
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
|
||||||
NoteView::note_header(
|
NoteView::note_header(
|
||||||
ui,
|
ui,
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ bitflags! {
|
|||||||
/// will end with a ... and a "Show more" button.
|
/// will end with a ... and a "Show more" button.
|
||||||
const Truncate = 1 << 11;
|
const Truncate = 1 << 11;
|
||||||
/// Show note's client in the note content
|
/// Show note's client in the note content
|
||||||
const ShowNoteClientTop = 1 << 12;
|
const ClientNameTop = 1 << 12;
|
||||||
const ShowNoteClientBottom = 1 << 13;
|
const ClientNameBottom = 1 << 13;
|
||||||
|
|
||||||
const RepliesNewestFirst = 1 << 14;
|
const RepliesNewestFirst = 1 << 14;
|
||||||
|
|
||||||
// Show note's created at note bottom
|
/// Show note's full created at date at the bottom
|
||||||
const ShowCreatedAtBottom = 1 << 15;
|
const FullCreatedDate = 1 << 15;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user