notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 18d5d95ef92a6119dd918264e13d5440db380d1c
parent bb6c68e05cc332cadbe4b6bac35ec13171e034d4
Author: William Casarin <jb55@jb55.com>
Date:   Thu, 20 Jun 2024 13:43:22 -0700

fix postbox design

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/app.rs | 2+-
Msrc/colors.rs | 2+-
Msrc/ui/note/post.rs | 111+++++++++++++++++++++++++++++++++++++++++++------------------------------------
3 files changed, 63 insertions(+), 52 deletions(-)

diff --git a/src/app.rs b/src/app.rs @@ -931,7 +931,7 @@ fn render_nav(routes: Vec<Route>, timeline_ind: usize, app: &mut Damus, ui: &mut .unwrap_or(0); let replying_to = note.pubkey(); - let _r = ui::PostView::new(&mut app, poster, replying_to).ui(&txn, ui); + ui::PostView::new(&mut app, poster, replying_to).ui(&txn, ui); } }); diff --git a/src/colors.rs b/src/colors.rs @@ -89,7 +89,7 @@ pub fn light_color_theme() -> ColorTheme { ColorTheme { // VISUALS panel_fill: Color32::WHITE, - extreme_bg_color: EVEN_DARKER_GRAY, + extreme_bg_color: LIGHTER_GRAY, text_color: BLACK, err_fg_color: RED_700, warn_fg_color: ORANGE_700, diff --git a/src/ui/note/post.rs b/src/ui/note/post.rs @@ -1,8 +1,9 @@ use crate::app::Damus; +use crate::ui; use crate::ui::{Preview, PreviewConfig, View}; -use crate::{ui, Error}; use egui::widgets::text_edit::TextEdit; use nostrdb::Transaction; +use tracing::info; pub struct PostView<'app, 'p> { app: &'app mut Damus, @@ -20,60 +21,70 @@ impl<'app, 'p> PostView<'app, 'p> { } } - pub fn ui(&mut self, txn: &nostrdb::Transaction, ui: &mut egui::Ui) -> Result<(), Error> { + fn editbox(&mut self, txn: &nostrdb::Transaction, ui: &mut egui::Ui) { + ui.spacing_mut().item_spacing.x = 12.0; + + let pfp_size = 24.0; + + let poster_pubkey = self + .app + .account_manager + .get_account(self.poster) + .map(|acc| acc.pubkey.bytes()) + .unwrap_or(crate::test_data::test_pubkey()); + + // TODO: refactor pfp control to do all of this for us + let poster_pfp = self + .app + .ndb + .get_profile_by_pubkey(txn, poster_pubkey) + .as_ref() + .ok() + .and_then(|p| { + Some(ui::ProfilePic::from_profile(&mut self.app.img_cache, p)?.size(pfp_size)) + }); + + if let Some(pfp) = poster_pfp { + ui.add(pfp); + } else { + ui.add( + ui::ProfilePic::new(&mut self.app.img_cache, ui::ProfilePic::no_pfp_url()) + .size(pfp_size), + ); + } + + let draft = self + .app + .drafts + .entry(enostr::NoteId::new(*self.replying_to)) + .or_default(); + + ui.add(TextEdit::multiline(&mut draft.buffer).frame(false)); + } + + pub fn ui(&mut self, txn: &nostrdb::Transaction, ui: &mut egui::Ui) { egui::Frame::default() .inner_margin(egui::Margin::same(12.0)) - .inner_margin(egui::Margin::same(12.0)) + .outer_margin(egui::Margin::same(12.0)) .fill(ui.visuals().extreme_bg_color) .stroke(ui.visuals().noninteractive().bg_stroke) .rounding(12.0) .show(ui, |ui| { - ui.horizontal(|ui| { - ui.spacing_mut().item_spacing.x = 12.0; - - let pfp_size = 24.0; - - let poster_pubkey = self - .app - .account_manager - .get_account(self.poster) - .map(|acc| acc.pubkey.bytes()) - .unwrap_or(crate::test_data::test_pubkey()); - - // TODO: refactor pfp control to do all of this for us - let poster_pfp = self - .app - .ndb - .get_profile_by_pubkey(txn, poster_pubkey) - .as_ref() - .ok() - .and_then(|p| ui::ProfilePic::from_profile(&mut self.app.img_cache, p)); - - if let Some(pfp) = poster_pfp { - ui.add(pfp); - } else { - ui.add( - ui::ProfilePic::new( - &mut self.app.img_cache, - ui::ProfilePic::no_pfp_url(), - ) - .size(pfp_size), - ); - } - - let draft = self - .app - .drafts - .entry(enostr::NoteId::new(*self.replying_to)) - .or_default(); - - ui.add(TextEdit::multiline(&mut draft.buffer).frame(false)); - - Ok(()) - }) - .inner - }) - .inner + ui.vertical(|ui| { + ui.horizontal(|ui| { + self.editbox(txn, ui); + }); + + ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| { + if ui + .add_sized([91.0, 32.0], egui::Button::new("Post now")) + .clicked() + { + info!("Post clicked"); + } + }); + }); + }); } } @@ -97,7 +108,7 @@ mod preview { fn ui(&mut self, ui: &mut egui::Ui) { let test_note_id = test_data::test_pubkey(); let txn = Transaction::new(&self.app.ndb).unwrap(); - let _r = PostView::new(&mut self.app, 0, test_note_id).ui(&txn, ui); + PostView::new(&mut self.app, 0, test_note_id).ui(&txn, ui); } }