Skip to content

Commit

Permalink
Merge remote-tracking branch 'pr/107'
Browse files Browse the repository at this point in the history
  • Loading branch information
jb55 committed Jun 25, 2024
2 parents 8ef6534 + f8c8e48 commit a685686
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 56 deletions.
17 changes: 6 additions & 11 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,17 +930,12 @@ fn render_nav(routes: Vec<Route>, timeline_ind: usize, app: &mut Damus, ui: &mut
return;
};

let note_key = note.key().unwrap();

let poster = app
.account_manager
.get_selected_account_index()
.unwrap_or(0);

let replying_to = note.pubkey();
ui::PostView::new(&mut app, poster, replying_to)
.id_source(("post", timeline_ind, note_key))
.ui(&txn, ui);
let id = egui::Id::new(("post", timeline_ind, note.key().unwrap()));
egui::ScrollArea::vertical().show(ui, |ui| {
ui::PostReplyView::new(&mut app, &note)
.id_source(id)
.show(ui);
});
}
});

Expand Down
8 changes: 4 additions & 4 deletions src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub const PINK: Color32 = Color32::from_rgb(0xE4, 0x5A, 0xC9);
pub const GRAY_SECONDARY: Color32 = Color32::from_rgb(0x8A, 0x8A, 0x8A);
const BLACK: Color32 = Color32::from_rgb(0x00, 0x00, 0x00);
const RED_700: Color32 = Color32::from_rgb(0xC7, 0x37, 0x5A);
const ORANGE_700: Color32 = Color32::from_rgb(0xF6, 0xB1, 0x4A);
//const ORANGE_700: Color32 = Color32::from_rgb(0xF6, 0xB1, 0x4A);

// BACKGROUNDS
const SEMI_DARKER_BG: Color32 = Color32::from_rgb(0x39, 0x39, 0x39);
Expand All @@ -29,7 +29,7 @@ pub struct ColorTheme {
pub extreme_bg_color: Color32,
pub text_color: Color32,
pub err_fg_color: Color32,
pub warn_fg_color: Color32,
//pub warn_fg_color: Color32,
pub hyperlink_color: Color32,
pub selection_color: Color32,

Expand All @@ -56,7 +56,7 @@ pub fn desktop_dark_color_theme() -> ColorTheme {
extreme_bg_color: DARK_ISH_BG,
text_color: Color32::WHITE,
err_fg_color: RED_700,
warn_fg_color: ORANGE_700,
//warn_fg_color: ORANGE_700,
hyperlink_color: PURPLE,
selection_color: PURPLE_ALT,

Expand Down Expand Up @@ -92,7 +92,7 @@ pub fn light_color_theme() -> ColorTheme {
extreme_bg_color: LIGHTER_GRAY,
text_color: BLACK,
err_fg_color: RED_700,
warn_fg_color: ORANGE_700,
//warn_fg_color: ORANGE_700,
hyperlink_color: PURPLE,
selection_color: PURPLE_ALT,

Expand Down
6 changes: 1 addition & 5 deletions src/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,7 @@ fn tabs_ui(timeline: &mut Timeline, ui: &mut egui::Ui) {
//ui.add_space(0.5);
ui::hline(ui);

let sel = if let Some(sel) = tab_res.selected() {
sel
} else {
0
};
let sel = tab_res.selected().unwrap_or_default();

// fun animation
timeline.selected_view = sel;
Expand Down
4 changes: 2 additions & 2 deletions src/ui/account_login_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<'a> View for AccountLoginView<'a> {
if self.is_mobile {
self.show_mobile(ui);
} else {
self.show(ui);
self.ui(ui);
}
}
}
Expand All @@ -44,7 +44,7 @@ impl<'a> AccountLoginView<'a> {
}
}

fn show(&mut self, ui: &mut egui::Ui) -> egui::Response {
fn ui(&mut self, ui: &mut egui::Ui) -> egui::Response {
let screen_width = ui.ctx().screen_rect().max.x;
let screen_height = ui.ctx().screen_rect().max.y;

Expand Down
2 changes: 1 addition & 1 deletion src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use account_switcher::AccountSelectionWidget;
pub use fixed_window::{FixedWindow, FixedWindowResponse};
pub use global_popup::DesktopGlobalPopup;
pub use mention::Mention;
pub use note::{BarAction, Note, NoteResponse, PostView};
pub use note::{BarAction, Note, NoteResponse, PostReplyView, PostView};
pub use preview::{Preview, PreviewApp, PreviewConfig};
pub use profile::{profile_preview_controller, ProfilePic, ProfilePreview};
pub use relay::RelayView;
Expand Down
18 changes: 15 additions & 3 deletions src/ui/note/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
pub mod contents;
pub mod options;
pub mod post;
pub mod reply;

pub use contents::NoteContents;
pub use options::NoteOptions;
pub use post::PostView;
pub use reply::PostReplyView;

use crate::{colors, notecache::CachedNote, ui, ui::View, Damus};
use egui::{Label, RichText, Sense};
Expand Down Expand Up @@ -128,6 +130,11 @@ impl<'a> Note<'a> {
self
}

pub fn medium_pfp(mut self, enable: bool) -> Self {
self.options_mut().set_medium_pfp(enable);
self
}

pub fn note_previews(mut self, enable: bool) -> Self {
self.options_mut().set_note_previews(enable);
self
Expand Down Expand Up @@ -179,6 +186,10 @@ impl<'a> Note<'a> {
.response
}

pub fn expand_size() -> f32 {
5.0
}

fn pfp(
&mut self,
note_key: NoteKey,
Expand All @@ -188,7 +199,9 @@ impl<'a> Note<'a> {
ui.spacing_mut().item_spacing.x = 16.0;

let pfp_size = if self.options().has_small_pfp() {
24.0
ui::ProfilePic::small_size()
} else if self.options().has_medium_pfp() {
ui::ProfilePic::medium_size()
} else {
ui::ProfilePic::default_size()
};
Expand All @@ -201,7 +214,6 @@ impl<'a> Note<'a> {
// these have different lifetimes and types,
// so the calls must be separate
Some(pic) => {
let expand_size = 5.0;
let anim_speed = 0.05;
let profile_key = profile.as_ref().unwrap().record().note_key();
let note_key = note_key.as_u64();
Expand All @@ -213,7 +225,7 @@ impl<'a> Note<'a> {
ui,
egui::Id::new((profile_key, note_key)),
pfp_size,
expand_size,
ui::Note::expand_size(),
anim_speed,
);

Expand Down
18 changes: 17 additions & 1 deletion src/ui/note/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ bitflags! {
const actionbar = 0b00000001;
const note_previews = 0b00000010;
const small_pfp = 0b00000100;
const wide = 0b00001000;
const medium_pfp = 0b00001000;
const wide = 0b00010000;
}
}

Expand All @@ -28,6 +29,11 @@ impl NoteOptions {
(self & NoteOptions::small_pfp) == NoteOptions::small_pfp
}

#[inline]
pub fn has_medium_pfp(self) -> bool {
(self & NoteOptions::medium_pfp) == NoteOptions::medium_pfp
}

#[inline]
pub fn has_wide(self) -> bool {
(self & NoteOptions::wide) == NoteOptions::wide
Expand All @@ -41,6 +47,16 @@ impl NoteOptions {
*self &= !NoteOptions::small_pfp;
}
}

#[inline]
pub fn set_medium_pfp(&mut self, enable: bool) {
if enable {
*self |= NoteOptions::medium_pfp;
} else {
*self &= !NoteOptions::medium_pfp;
}
}

#[inline]
pub fn set_note_previews(&mut self, enable: bool) {
if enable {
Expand Down
94 changes: 66 additions & 28 deletions src/ui/note/post.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::app::Damus;
use crate::draft::Draft;
use crate::ui;
use crate::ui::{Preview, PreviewConfig, View};
use egui::widgets::text_edit::TextEdit;
use nostrdb::Transaction;
use tracing::info;

pub struct PostView<'app, 'p> {
app: &'app mut Damus,
Expand All @@ -13,6 +13,20 @@ pub struct PostView<'app, 'p> {
replying_to: &'p [u8; 32],
}

pub struct NewPost {
pub content: String,
pub account: usize,
}

pub enum PostAction {
Post(NewPost),
}

pub struct PostResponse {
pub action: Option<PostAction>,
pub edit_response: egui::Response,
}

impl<'app, 'p> PostView<'app, 'p> {
pub fn new(app: &'app mut Damus, poster: usize, replying_to: &'p [u8; 32]) -> Self {
let id_source: Option<egui::Id> = None;
Expand All @@ -29,7 +43,14 @@ impl<'app, 'p> PostView<'app, 'p> {
self
}

fn editbox(&mut self, txn: &nostrdb::Transaction, ui: &mut egui::Ui) {
fn draft(&mut self) -> &mut Draft {
self.app
.drafts
.entry(enostr::NoteId::new(*self.replying_to))
.or_default()
}

fn editbox(&mut self, txn: &nostrdb::Transaction, ui: &mut egui::Ui) -> egui::Response {
ui.spacing_mut().item_spacing.x = 12.0;

let pfp_size = 24.0;
Expand Down Expand Up @@ -61,17 +82,13 @@ impl<'app, 'p> PostView<'app, 'p> {
);
}

let draft = self
.app
.drafts
.entry(enostr::NoteId::new(*self.replying_to))
.or_default();
let response = ui.add(TextEdit::multiline(&mut self.draft().buffer).frame(false));

let focused = ui
.add(TextEdit::multiline(&mut draft.buffer).frame(false))
.has_focus();
let focused = response.has_focus();

ui.ctx().data_mut(|d| d.insert_temp(self.id(), focused));

response
}

fn focused(&self, ui: &egui::Ui) -> bool {
Expand All @@ -83,7 +100,15 @@ impl<'app, 'p> PostView<'app, 'p> {
self.id_source.unwrap_or_else(|| egui::Id::new("post"))
}

pub fn ui(&mut self, txn: &nostrdb::Transaction, ui: &mut egui::Ui) {
pub fn outer_margin() -> f32 {
16.0
}

pub fn inner_margin() -> f32 {
12.0
}

pub fn ui(&mut self, txn: &nostrdb::Transaction, ui: &mut egui::Ui) -> PostResponse {
let focused = self.focused(ui);
let stroke = if focused {
ui.visuals().selection.stroke
Expand All @@ -93,8 +118,8 @@ impl<'app, 'p> PostView<'app, 'p> {
};

let mut frame = egui::Frame::default()
.inner_margin(egui::Margin::same(12.0))
.outer_margin(egui::Margin::same(12.0))
.inner_margin(egui::Margin::same(PostView::inner_margin()))
.outer_margin(egui::Margin::same(PostView::outer_margin()))
.fill(ui.visuals().extreme_bg_color)
.stroke(stroke)
.rounding(12.0);
Expand All @@ -108,22 +133,35 @@ impl<'app, 'p> PostView<'app, 'p> {
});
}

frame.show(ui, |ui| {
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");
frame
.show(ui, |ui| {
ui.vertical(|ui| {
let edit_response = ui.horizontal(|ui| self.editbox(txn, ui)).inner;

let action = 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()
{
Some(PostAction::Post(NewPost {
content: self.draft().buffer.clone(),
account: self.poster,
}))
} else {
None
}
})
.inner;

PostResponse {
action,
edit_response,
}
});
});
});
})
.inner
})
.inner
}
}

Expand Down
Loading

0 comments on commit a685686

Please sign in to comment.