notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 2533448180d0a501e03aac3547051ee5d2dc4021
parent c4eccf0a8ea5ee750894afeb866cd3ebc9000058
Author: kernelkind <kernelkind@gmail.com>
Date:   Sun, 28 Sep 2025 21:49:21 -0400

remove unnecessary `DragSwitch`

Signed-off-by: kernelkind <kernelkind@gmail.com>

Diffstat:
Mcrates/notedeck_columns/src/column.rs | 3---
Dcrates/notedeck_columns/src/drag.rs | 103-------------------------------------------------------------------------------
Mcrates/notedeck_columns/src/lib.rs | 1-
Mcrates/notedeck_columns/src/nav.rs | 130++-----------------------------------------------------------------------------
4 files changed, 3 insertions(+), 234 deletions(-)

diff --git a/crates/notedeck_columns/src/column.rs b/crates/notedeck_columns/src/column.rs @@ -1,6 +1,5 @@ use crate::{ actionbar::TimelineOpenResult, - drag::DragSwitch, route::{Route, Router, SingletonRouter}, timeline::{Timeline, TimelineCache, TimelineKind}, }; @@ -14,7 +13,6 @@ use tracing::warn; pub struct Column { pub router: Router<Route>, pub sheet_router: SingletonRouter<Route>, - pub drag: DragSwitch, } impl Column { @@ -23,7 +21,6 @@ impl Column { Column { router, sheet_router: SingletonRouter::default(), - drag: DragSwitch::default(), } } diff --git a/crates/notedeck_columns/src/drag.rs b/crates/notedeck_columns/src/drag.rs @@ -1,103 +0,0 @@ -#[derive(Default, Clone, Debug)] -pub struct DragSwitch { - state: Option<DragState>, -} - -#[derive(Clone, Debug)] -struct DragState { - start_pos: egui::Pos2, - cur_direction: DragDirection, -} - -impl DragSwitch { - /// should call BEFORE both drag directions get rendered - pub fn update(&mut self, horizontal: egui::Id, vertical: egui::Id, ctx: &egui::Context) { - let horiz_being_dragged = ctx.is_being_dragged(horizontal); - let vert_being_dragged = ctx.is_being_dragged(vertical); - - if !horiz_being_dragged && !vert_being_dragged { - self.state = None; - return; - } - - let Some(state) = &mut self.state else { - return; - }; - - let Some(cur_pos) = ctx.pointer_interact_pos() else { - return; - }; - - let dx = (state.start_pos.x - cur_pos.x).abs(); - let dy = (state.start_pos.y - cur_pos.y).abs(); - - let new_direction = if dx > dy { - DragDirection::Horizontal - } else { - DragDirection::Vertical - }; - - if new_direction == DragDirection::Horizontal - && state.cur_direction == DragDirection::Vertical - { - // drag is occuring mostly in the horizontal direction - ctx.set_dragged_id(horizontal); - let new_dir = DragDirection::Horizontal; - state.cur_direction = new_dir; - } else if new_direction == DragDirection::Vertical - && state.cur_direction == DragDirection::Horizontal - { - // drag is occuring mostly in the vertical direction - let new_dir = DragDirection::Vertical; - state.cur_direction = new_dir; - ctx.set_dragged_id(vertical); - } - } - - /// should call AFTER both drag directions rendered - pub fn check_for_drag_start( - &mut self, - ctx: &egui::Context, - horizontal: egui::Id, - vertical: egui::Id, - ) { - let Some(drag_id) = ctx.drag_started_id() else { - return; - }; - - let cur_direction = if drag_id == horizontal { - DragDirection::Horizontal - } else if drag_id == vertical { - DragDirection::Vertical - } else { - return; - }; - - let Some(cur_pos) = ctx.pointer_interact_pos() else { - return; - }; - - self.state = Some(DragState { - start_pos: cur_pos, - cur_direction, - }); - } -} - -#[derive(Debug, PartialEq, Clone)] -enum DragDirection { - Horizontal, - Vertical, -} - -pub fn get_drag_id(ui: &egui::Ui, scroll_id: egui::Id) -> egui::Id { - ui.id().with(egui::Id::new(scroll_id)).with("area") -} - -// unfortunately a Frame makes a new id for the Ui -pub fn get_drag_id_through_frame(ui: &egui::Ui, scroll_id: egui::Id) -> egui::Id { - ui.id() - .with(egui::Id::new("child")) - .with(egui::Id::new(scroll_id)) - .with("area") -} diff --git a/crates/notedeck_columns/src/lib.rs b/crates/notedeck_columns/src/lib.rs @@ -12,7 +12,6 @@ pub mod column; mod deck_state; mod decks; mod draft; -mod drag; mod key_parsing; pub mod login_manager; mod media_upload; diff --git a/crates/notedeck_columns/src/nav.rs b/crates/notedeck_columns/src/nav.rs @@ -4,7 +4,6 @@ use crate::{ column::ColumnsAction, deck_state::DeckState, decks::{Deck, DecksAction, DecksCache}, - drag::{get_drag_id, get_drag_id_through_frame}, options::AppOptions, profile::{ProfileAction, SaveProfileChanges}, route::{Route, Router, SingletonRouter}, @@ -16,19 +15,17 @@ use crate::{ }, ui::{ self, - add_column::{render_add_column_routes, AddColumnView}, + add_column::render_add_column_routes, column::NavTitle, configure_deck::ConfigureDeckView, edit_deck::{EditDeckResponse, EditDeckView}, - note::{custom_zap::CustomZapView, NewPostAction, PostAction, PostType, QuoteRepostView}, - onboarding::FollowPackOnboardingView, + note::{custom_zap::CustomZapView, NewPostAction, PostAction, PostType}, profile::EditProfileView, search::{FocusState, SearchView}, settings::SettingsAction, support::SupportView, wallet::{get_default_zap_state, WalletAction, WalletState, WalletView}, - AccountsView, PostReplyView, PostView, ProfileView, RelayView, SettingsView, ThreadView, - TimelineView, + RelayView, SettingsView, }, Damus, }; @@ -1079,41 +1076,6 @@ pub fn render_nav( .clone(); let nav = Nav::new(&routes).id_source(egui::Id::new(("nav", col))); - let drag_ids = 's: { - let Some(top_route) = &routes.last().cloned() else { - break 's 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) @@ -1160,91 +1122,5 @@ pub fn render_nav( } }); - 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))) } - -fn get_scroll_id( - top: &Route, - depth: usize, - timeline_cache: &TimelineCache, - col: usize, -) -> Option<egui::Id> { - match top { - Route::Timeline(timeline_kind) => match timeline_kind { - TimelineKind::List(_) - | TimelineKind::Search(_) - | TimelineKind::Algo(_) - | TimelineKind::Notifications(_) - | TimelineKind::Universe - | TimelineKind::Hashtag(_) - | TimelineKind::Generic(_) => { - TimelineView::scroll_id(timeline_cache, timeline_kind, col) - } - TimelineKind::Profile(pubkey) => { - if depth > 1 { - Some(ProfileView::scroll_id(col, pubkey)) - } else { - TimelineView::scroll_id(timeline_cache, timeline_kind, col) - } - } - }, - Route::Thread(thread_selection) => Some(ThreadView::scroll_id( - thread_selection.selected_or_root(), - col, - )), - Route::Accounts(accounts_route) => match accounts_route { - crate::accounts::AccountsRoute::Accounts => Some(AccountsView::scroll_id()), - crate::accounts::AccountsRoute::AddAccount => None, - crate::accounts::AccountsRoute::Onboarding => { - Some(FollowPackOnboardingView::scroll_id()) - } - }, - Route::Reply(note_id) => Some(PostReplyView::scroll_id(col, note_id.bytes())), - Route::Quote(note_id) => Some(QuoteRepostView::scroll_id(col, note_id.bytes())), - Route::Relays => Some(RelayView::scroll_id()), - Route::ComposeNote => Some(PostView::scroll_id()), - Route::AddColumn(add_column_route) => Some(AddColumnView::scroll_id(add_column_route)), - Route::EditProfile(_) => Some(EditProfileView::scroll_id()), - Route::Support => None, - Route::NewDeck => Some(ConfigureDeckView::scroll_id()), - Route::Search => Some(SearchView::scroll_id()), - Route::EditDeck(_) => None, - Route::Wallet(_) => None, - Route::CustomizeZapAmount(_) => None, - Route::Settings => None, - } -} - -/// Does the corresponding View for the route use a egui::Frame to wrap the ScrollArea? -/// TODO(kernelkind): this is quite hacky... -fn route_uses_frame(route: &Route) -> bool { - match route { - Route::Accounts(accounts_route) => match accounts_route { - crate::accounts::AccountsRoute::Accounts => true, - crate::accounts::AccountsRoute::AddAccount => false, - crate::accounts::AccountsRoute::Onboarding => false, - }, - Route::Relays => true, - Route::Timeline(_) => false, - Route::Thread(_) => false, - Route::Reply(_) => false, - Route::Quote(_) => false, - Route::Settings => false, - Route::ComposeNote => false, - Route::AddColumn(_) => false, - Route::EditProfile(_) => false, - Route::Support => false, - Route::NewDeck => false, - Route::Search => false, - Route::EditDeck(_) => false, - Route::Wallet(_) => false, - Route::CustomizeZapAmount(_) => false, - } -}