mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-19 01:24:21 +01:00
use DragSwitch to allow dragging anywhere in navigation
instead of just the top header when there is a vertical scroll Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ use crate::{
|
|||||||
column::ColumnsAction,
|
column::ColumnsAction,
|
||||||
deck_state::DeckState,
|
deck_state::DeckState,
|
||||||
decks::{Deck, DecksAction, DecksCache},
|
decks::{Deck, DecksAction, DecksCache},
|
||||||
|
drag::{get_drag_id, get_drag_id_through_frame},
|
||||||
options::AppOptions,
|
options::AppOptions,
|
||||||
profile::{ProfileAction, SaveProfileChanges},
|
profile::{ProfileAction, SaveProfileChanges},
|
||||||
route::{Route, Router, SingletonRouter},
|
route::{Route, Router, SingletonRouter},
|
||||||
@@ -954,47 +955,90 @@ pub fn render_nav(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let nav_response = Nav::new(
|
let routes = app
|
||||||
&app.columns(ctx.accounts)
|
.columns(ctx.accounts)
|
||||||
.column(col)
|
.column(col)
|
||||||
.router()
|
.router()
|
||||||
.routes()
|
.routes()
|
||||||
.clone(),
|
.clone();
|
||||||
)
|
let nav = Nav::new(&routes).id_source(egui::Id::new(("nav", col)));
|
||||||
.navigating(
|
|
||||||
app.columns_mut(ctx.i18n, ctx.accounts)
|
|
||||||
.column_mut(col)
|
|
||||||
.router_mut()
|
|
||||||
.navigating,
|
|
||||||
)
|
|
||||||
.returning(
|
|
||||||
app.columns_mut(ctx.i18n, ctx.accounts)
|
|
||||||
.column_mut(col)
|
|
||||||
.router_mut()
|
|
||||||
.returning,
|
|
||||||
)
|
|
||||||
.id_source(egui::Id::new(("nav", col)))
|
|
||||||
.show_mut(ui, |ui, render_type, nav| match render_type {
|
|
||||||
NavUiType::Title => NavTitle::new(
|
|
||||||
ctx.ndb,
|
|
||||||
ctx.img_cache,
|
|
||||||
get_active_columns_mut(ctx.i18n, ctx.accounts, &mut app.decks_cache),
|
|
||||||
nav.routes(),
|
|
||||||
col,
|
|
||||||
ctx.i18n,
|
|
||||||
)
|
|
||||||
.show_move_button(!narrow)
|
|
||||||
.show_delete_button(!narrow)
|
|
||||||
.show(ui),
|
|
||||||
|
|
||||||
NavUiType::Body => {
|
let drag_ids = 's: {
|
||||||
if let Some(top) = nav.routes().last() {
|
let Some(top_route) = &routes.last().cloned() else {
|
||||||
render_nav_body(ui, app, ctx, top, nav.routes().len(), col, inner_rect)
|
break 's None;
|
||||||
} else {
|
};
|
||||||
None
|
|
||||||
|
let Some(scroll_id) = get_scroll_id(
|
||||||
|
top_route,
|
||||||
|
app.columns(ctx.accounts)
|
||||||
|
.column(col)
|
||||||
|
.router()
|
||||||
|
.routes()
|
||||||
|
.len(),
|
||||||
|
&app.timeline_cache,
|
||||||
|
col,
|
||||||
|
) else {
|
||||||
|
break 's None;
|
||||||
|
};
|
||||||
|
|
||||||
|
let vertical_drag_id = if route_uses_frame(top_route) {
|
||||||
|
get_drag_id_through_frame(ui, scroll_id)
|
||||||
|
} else {
|
||||||
|
get_drag_id(ui, scroll_id)
|
||||||
|
};
|
||||||
|
|
||||||
|
let horizontal_drag_id = nav.drag_id(ui);
|
||||||
|
|
||||||
|
let drag = &mut get_active_columns_mut(ctx.i18n, ctx.accounts, &mut app.decks_cache)
|
||||||
|
.column_mut(col)
|
||||||
|
.drag;
|
||||||
|
|
||||||
|
drag.update(horizontal_drag_id, vertical_drag_id, ui.ctx());
|
||||||
|
|
||||||
|
Some((horizontal_drag_id, vertical_drag_id))
|
||||||
|
};
|
||||||
|
|
||||||
|
let nav_response = nav
|
||||||
|
.navigating(
|
||||||
|
app.columns_mut(ctx.i18n, ctx.accounts)
|
||||||
|
.column_mut(col)
|
||||||
|
.router_mut()
|
||||||
|
.navigating,
|
||||||
|
)
|
||||||
|
.returning(
|
||||||
|
app.columns_mut(ctx.i18n, ctx.accounts)
|
||||||
|
.column_mut(col)
|
||||||
|
.router_mut()
|
||||||
|
.returning,
|
||||||
|
)
|
||||||
|
.show_mut(ui, |ui, render_type, nav| match render_type {
|
||||||
|
NavUiType::Title => NavTitle::new(
|
||||||
|
ctx.ndb,
|
||||||
|
ctx.img_cache,
|
||||||
|
get_active_columns_mut(ctx.i18n, ctx.accounts, &mut app.decks_cache),
|
||||||
|
nav.routes(),
|
||||||
|
col,
|
||||||
|
ctx.i18n,
|
||||||
|
)
|
||||||
|
.show_move_button(!narrow)
|
||||||
|
.show_delete_button(!narrow)
|
||||||
|
.show(ui),
|
||||||
|
|
||||||
|
NavUiType::Body => {
|
||||||
|
if let Some(top) = nav.routes().last() {
|
||||||
|
render_nav_body(ui, app, ctx, top, nav.routes().len(), col, inner_rect)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
if let Some((horizontal_drag_id, vertical_drag_id)) = drag_ids {
|
||||||
|
let drag = &mut get_active_columns_mut(ctx.i18n, ctx.accounts, &mut app.decks_cache)
|
||||||
|
.column_mut(col)
|
||||||
|
.drag;
|
||||||
|
drag.check_for_drag_start(ui.ctx(), horizontal_drag_id, vertical_drag_id);
|
||||||
|
}
|
||||||
|
|
||||||
RenderNavResponse::new(col, NotedeckNavResponse::Nav(Box::new(nav_response)))
|
RenderNavResponse::new(col, NotedeckNavResponse::Nav(Box::new(nav_response)))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user