weird actionbar experiment

This commit is contained in:
William Casarin
2024-03-12 10:11:27 +00:00
parent d4879aefe9
commit 08fad55773
4 changed files with 64 additions and 16 deletions

BIN
assets/icons/reply.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

1
assets/icons/reply.svg Normal file
View File

@@ -0,0 +1 @@
<svg width="14" height="15" viewBox="0 0 14 15" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M1 4.2C1 3.07989 1 2.51984 1.21799 2.09202C1.40973 1.71569 1.71569 1.40973 2.09202 1.21799C2.51984 1 3.07989 1 4.2 1H9.8C10.9201 1 11.4801 1 11.908 1.21799C12.2843 1.40973 12.5903 1.71569 12.782 2.09202C13 2.51984 13 3.07989 13 4.2V7.8C13 8.92013 13 9.48013 12.782 9.908C12.5903 10.2843 12.2843 10.5903 11.908 10.782C11.4801 11 10.9201 11 9.8 11H8.12247C7.70647 11 7.49847 11 7.29947 11.0409C7.12293 11.0771 6.95213 11.137 6.79167 11.219C6.6108 11.3114 6.44833 11.4413 6.12347 11.7012L4.53317 12.9735C4.25578 13.1954 4.11709 13.3063 4.00036 13.3065C3.89885 13.3066 3.80281 13.2604 3.73949 13.1811C3.66667 13.0899 3.66667 12.9123 3.66667 12.557V11C3.04669 11 2.73669 11 2.48236 10.9319C1.79218 10.7469 1.25308 10.2078 1.06815 9.51767C1 9.26333 1 8.95333 1 8.33333V4.2V4.2Z" stroke="white" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> </svg>

After

Width:  |  Height:  |  Size: 969 B

View File

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

View File

@@ -4,6 +4,7 @@ use std::time::Duration;
pub struct NoteCache {
reltime: TimeCached<String>,
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 {