fix postbox design

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-06-20 13:43:22 -07:00
parent bb6c68e05c
commit 18d5d95ef9
3 changed files with 62 additions and 51 deletions

View File

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

View File

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

View File

@@ -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;
ui.vertical(|ui| {
ui.horizontal(|ui| {
self.editbox(txn, ui);
});
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.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);
}
}