From 08fad55773c0912a1292bc0b6a387fd88b7263a7 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Tue, 12 Mar 2024 10:11:27 +0000 Subject: [PATCH] weird actionbar experiment --- assets/icons/reply.png | Bin 0 -> 1205 bytes assets/icons/reply.svg | 1 + src/app.rs | 75 ++++++++++++++++++++++++++++++++--------- src/notecache.rs | 4 ++- 4 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 assets/icons/reply.png create mode 100644 assets/icons/reply.svg diff --git a/assets/icons/reply.png b/assets/icons/reply.png new file mode 100644 index 0000000000000000000000000000000000000000..d85a55e0e107d9755c5b8db68467ee7cbee7aa3e GIT binary patch literal 1205 zcmV;m1WNmfP)r3 zqGe?+B#6`~iZC|?6-Jh*l@cU{QQk7&SDzMV#&h23JX9$eqWjw3(Ea_Lq@G4%!c%yML0p?*NR`lGpa@mYW za3s62QGjXqz|;%A&WE@UC+i!|YG|<5)D0f)!Asc<*$lV>-(q^nPL<6#u2q{DvlHA4 z;=v!rdThfU>1k+8!?-Guc~YNe;Zod$rzNNE$rzQK*;bKez&sql+?<_uN`}V%Zg^b+ z7hwyQpCI0W0JO|F^*k9`;FmK9pmhE4i>cJqa$2boRQz3ck)hycV%9B^6+C zq~WLC@~8qni`XtB6<|T6;m=)jr+i|*pGzvhj7YZz=RAq69t%%0kM1jlM!3L6Pv##2yn(S6rgGcs%9ua)ecn6 zP=Kl(sG6YwRXb2MLjkIGplXH!RP8|337%~70I^cB zk*>K@J}nDyD$;PO3UGo{fY^i2*f{EUS{5Mo^mJy|+$o=!?-Pc=fk?xJU2~^=E{xdz zA{Ah7q~WbybEkZkM{K)E1=t;F_?)DKX3&_A)e-xTqylV?G`tualvfAb4d&oI`9ok_ zQcFw-q5jz(;(Q-Mcrb)8GqX>>eHMif9t$DtY!b_s`aan@!8=c@5+~p{X_?$9Nj=V+ zHPu^X6u00uT#gHB|6E?N)@00;zS?i6TKx`u42=qIXrf#*R=4mkO%EZg2_fw7@K{B8 zC+kn6bLWH*e(0d{Lm`COAwT$KA%qz+2MQC1vvwu9wVJ6AAh0Iub&7GK8?V z%{03v)5m!sgl*l(-Gb~2A*>3KIVo?&NS0CDE?G9SM3UmM%j0GE2G?N|7Pb9cdZ4wqyM=aRlFRIM z;tyncN-qRxCHUX*Fh1|W@!O(`6=7fF0ew<|Ui6`8(el~1aicy7p5g+WXtVuEticn~ zRi1r8(IN0_8*LBbQG8PHSUsg^2DEb5NU}0(xjqe^;sSgjS(FsxUCHI=PX&)r3Z1+e zdPovvBM0#e9yb7sEs9 diff --git a/src/app.rs b/src/app.rs index 687ccc2..da8dc43 100644 --- a/src/app.rs +++ b/src/app.rs @@ -722,17 +722,39 @@ fn render_reltime(ui: &mut egui::Ui, note_cache: &mut NoteCache) { )); } -fn render_note(ui: &mut egui::Ui, damus: &mut Damus, note_key: NoteKey) -> Result<()> { +fn circle_icon(ui: &mut egui::Ui, openness: f32, response: &egui::Response) { + let stroke = ui.style().interact(&response).fg_stroke; + let radius = egui::lerp(2.0..=3.0, openness); + ui.painter() + .circle_filled(response.rect.center(), radius, stroke.color); +} + +#[derive(Hash, Clone, Copy)] +struct NoteTimelineKey { + timeline: usize, + note_key: NoteKey, +} + +fn render_note( + ui: &mut egui::Ui, + damus: &mut Damus, + note_key: NoteKey, + timeline: usize, +) -> Result<()> { #[cfg(feature = "profiling")] puffin::profile_function!(); let txn = Transaction::new(&damus.ndb)?; let note = damus.ndb.get_note_by_key(&txn, note_key)?; + let id = egui::Id::new(NoteTimelineKey { note_key, timeline }); ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| { let profile = damus.ndb.get_profile_by_pubkey(&txn, note.pubkey()); - padding(6.0, ui, |ui| { + let mut collapse_state = + egui::collapsing_header::CollapsingState::load_with_default_open(ui.ctx(), id, false); + + let inner_resp = padding(6.0, ui, |ui| { match profile .as_ref() .ok() @@ -756,36 +778,59 @@ fn render_note(ui: &mut egui::Ui, damus: &mut Damus, note_key: NoteKey) -> Resul render_note_contents(ui, damus, &txn, ¬e, note_key); - render_note_actionbar(ui); - }) + //let header_res = ui.horizontal(|ui| {}); + + collapse_state.show_body_unindented(ui, |ui| render_note_actionbar(ui)); + }); }); + + let resp = ui.interact(inner_resp.response.rect, id, Sense::hover()); + + if resp.hovered() ^ collapse_state.is_open() { + info!("clicked {:?}, {}", note_key, collapse_state.is_open()); + collapse_state.toggle(ui); + collapse_state.store(ui.ctx()); + } }); Ok(()) } -fn render_note_actionbar(ui: &mut egui::Ui) { +fn render_note_actionbar(ui: &mut egui::Ui) -> egui::InnerResponse<()> { ui.horizontal(|ui| { - if ui.button("reply").clicked() {} + if ui + .add( + egui::Button::image(egui::Image::new(egui::include_image!( + "../assets/icons/reply.png" + ))) + .fill(ui.style().visuals.panel_fill), + ) + .clicked() + {} - if ui.button("like").clicked() {} - }); + //if ui.add(egui::Button::new("like")).clicked() {} + }) } -fn render_notes(ui: &mut egui::Ui, damus: &mut Damus, timeline: usize) { +fn render_notes(ui: &mut egui::Ui, damus: &mut Damus, timeline: usize, test_panel_id: usize) { #[cfg(feature = "profiling")] puffin::profile_function!(); let num_notes = damus.timelines[timeline].notes.len(); for i in 0..num_notes { - let _ = render_note(ui, damus, damus.timelines[timeline].notes[i].key); + let _ = render_note( + ui, + damus, + damus.timelines[timeline].notes[i].key, + test_panel_id, + ); ui.separator(); } } -fn timeline_view(ui: &mut egui::Ui, app: &mut Damus, timeline: usize) { +fn timeline_view(ui: &mut egui::Ui, app: &mut Damus, timeline: usize, test_panel_id: usize) { padding(4.0, ui, |ui| ui.heading("Notifications")); /* @@ -802,7 +847,7 @@ fn timeline_view(ui: &mut egui::Ui, app: &mut Damus, timeline: usize) { }); */ .show(ui, |ui| { - render_notes(ui, app, timeline); + render_notes(ui, app, timeline, test_panel_id); }); } @@ -888,7 +933,7 @@ fn render_damus_mobile(ctx: &egui::Context, app: &mut Damus) { main_panel(&ctx.style()).show(ctx, |ui| { timeline_panel(ui, panel_width, 0, |ui| { - timeline_view(ui, app, 0); + timeline_view(ui, app, 0, 0); }); }); } @@ -921,7 +966,7 @@ fn render_damus_desktop(ctx: &egui::Context, app: &mut Damus) { main_panel(&ctx.style()).show(ctx, |ui| { timeline_panel(ui, panel_width, 0, |ui| { //postbox(ui, app); - timeline_view(ui, app, 0); + timeline_view(ui, app, 0, 0); }); }); @@ -938,7 +983,7 @@ fn render_damus_desktop(ctx: &egui::Context, app: &mut Damus) { } timeline_panel(ui, panel_width, ind, |ui| { // TODO: add new timeline to each panel - timeline_view(ui, app, 0); + timeline_view(ui, app, 0, ind as usize); }); } }); diff --git a/src/notecache.rs b/src/notecache.rs index 391425d..7cf28aa 100644 --- a/src/notecache.rs +++ b/src/notecache.rs @@ -4,6 +4,7 @@ use std::time::Duration; pub struct NoteCache { reltime: TimeCached, + pub bar_open: bool, } impl NoteCache { @@ -12,7 +13,8 @@ impl NoteCache { Duration::from_secs(1), Box::new(move || time_ago_since(created_at)), ); - NoteCache { reltime } + let bar_open = false; + NoteCache { reltime, bar_open } } pub fn reltime_str(&mut self) -> &str {