Add forward navigation animation

Also fix a few nav clipping bugs

From egui-nav:

William Casarin (5):
      add forward nav support
      fix body overlapping header
      fix transition clipping when in a smaller container
      fix forward nav clipping in small containers
      fix background layer having the wrong UI id

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-06-13 11:57:59 -07:00
parent c4e0c710c9
commit d17b5e0703
4 changed files with 54 additions and 43 deletions

View File

@@ -869,57 +869,63 @@ fn render_panel(ctx: &egui::Context, app: &mut Damus, timeline_ind: usize) {
}
fn render_nav(routes: Vec<Route>, timeline_ind: usize, app: &mut Damus, ui: &mut egui::Ui) {
let navigating = app.timelines[timeline_ind].navigating;
let app_ctx = Rc::new(RefCell::new(app));
let nav_response = Nav::new(routes).show(ui, |ui, nav| match nav.top() {
Route::Timeline(_n) => {
timeline::timeline_view(ui, &mut app_ctx.borrow_mut(), timeline_ind);
}
let nav_response =
Nav::new(routes)
.navigating(navigating)
.show(ui, |ui, nav| match nav.top() {
Route::Timeline(_n) => {
timeline::timeline_view(ui, &mut app_ctx.borrow_mut(), timeline_ind);
}
Route::ManageAccount => {
ui.label("account management view");
}
Route::ManageAccount => {
ui.label("account management view");
}
Route::Thread(_key) => {
ui.label("thread view");
}
Route::Thread(_key) => {
ui.label("thread view");
}
Route::Relays => {
let pool = &mut app_ctx.borrow_mut().pool;
let manager = RelayPoolManager::new(pool);
RelayView::new(manager).ui(ui);
}
Route::Relays => {
let pool = &mut app_ctx.borrow_mut().pool;
let manager = RelayPoolManager::new(pool);
RelayView::new(manager).ui(ui);
}
Route::Reply(id) => {
let app = app_ctx.borrow();
let txn = if let Ok(txn) = Transaction::new(&app.ndb) {
txn
} else {
ui.label("Reply to unknown note");
return;
};
Route::Reply(id) => {
let app = app_ctx.borrow();
let txn = if let Ok(txn) = Transaction::new(&app.ndb) {
txn
} else {
ui.label("Reply to unknown note");
return;
};
let note = if let Ok(note) = app.ndb.get_note_by_id(&txn, id.bytes()) {
note
} else {
ui.label("Reply to unknown note");
return;
};
let note = if let Ok(note) = app.ndb.get_note_by_id(&txn, id.bytes()) {
note
} else {
ui.label("Reply to unknown note");
return;
};
ui.label(format!(
"Replying to note by {}",
app.ndb
.get_profile_by_pubkey(&txn, note.pubkey())
.as_ref()
.ok()
.and_then(|pr| Some(crate::profile::get_profile_name(pr)?.username()))
.unwrap_or("??")
));
}
});
ui.label(format!(
"Replying to note by {}",
app.ndb
.get_profile_by_pubkey(&txn, note.pubkey())
.as_ref()
.ok()
.and_then(|pr| Some(crate::profile::get_profile_name(pr)?.username()))
.unwrap_or("??")
));
}
});
if let Some(NavAction::Returned) = nav_response.action {
app_ctx.borrow_mut().timelines[timeline_ind].routes.pop();
} else if let Some(NavAction::Navigated) = nav_response.action {
app_ctx.borrow_mut().timelines[timeline_ind].navigating = false;
}
}

View File

@@ -126,6 +126,7 @@ pub struct Timeline {
pub views: Vec<TimelineView>,
pub selected_view: i32,
pub routes: Vec<Route>,
pub navigating: bool,
/// Our nostrdb subscription
pub subscription: Option<Subscription>,
@@ -139,8 +140,10 @@ impl Timeline {
let views = vec![notes, replies];
let selected_view = 0;
let routes = vec![Route::Timeline("Timeline".to_string())];
let navigating = false;
Timeline {
navigating,
filter,
views,
subscription,
@@ -309,9 +312,11 @@ pub fn timeline_view(ui: &mut egui::Ui, app: &mut Damus, timeline: usize) {
debug!("bar action: {:?}", action);
match action {
BarAction::Reply => {
app.timelines[timeline]
let timeline = &mut app.timelines[timeline];
timeline
.routes
.push(Route::Reply(NoteId::new(note.id().to_owned())));
timeline.navigating = true;
}
}
}