notedeck

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

commit 52604e65c6b60d56031b59c3939142a4fd382aaa
parent 00091c508845a3e5a1beec322e9e4de9ac932ad8
Author: kernelkind <kernelkind@gmail.com>
Date:   Mon,  9 Sep 2024 18:17:56 -0400

remove global popup conception

can be added later if we need it again

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

Diffstat:
Msrc/app.rs | 11+----------
Msrc/ui/account_switcher.rs | 12+++---------
Dsrc/ui/fixed_window.rs | 63---------------------------------------------------------------
Dsrc/ui/global_popup.rs | 53-----------------------------------------------------
Msrc/ui/mod.rs | 4----
Msrc/ui/side_panel.rs | 3+--
6 files changed, 5 insertions(+), 141 deletions(-)

diff --git a/src/app.rs b/src/app.rs @@ -18,7 +18,7 @@ use crate::subscriptions::{SubKind, Subscriptions}; use crate::thread::{DecrementResult, Threads}; use crate::timeline::{Timeline, TimelineKind, TimelineSource, ViewFilter}; use crate::ui::note::PostAction; -use crate::ui::{self, AccountSelectionWidget, DesktopGlobalPopup}; +use crate::ui::{self, AccountSelectionWidget}; use crate::ui::{DesktopSidePanel, RelayView, View}; use crate::unknowns::UnknownIds; use crate::{filter, Result}; @@ -48,9 +48,6 @@ pub struct Damus { note_cache: NoteCache, pub pool: RelayPool, - /// global navigation for account management popups, etc. - pub global_nav: Vec<Route>, - pub columns: Columns, pub ndb: Ndb, pub unknown_ids: UnknownIds, @@ -67,7 +64,6 @@ pub struct Damus { pub since_optimize: bool, pub textmode: bool, pub show_account_switcher: bool, - pub show_global_popup: bool, } fn relay_setup(pool: &mut RelayPool, ctx: &egui::Context) { @@ -701,8 +697,6 @@ impl Damus { accounts, frame_history: FrameHistory::default(), show_account_switcher: false, - show_global_popup: false, - global_nav: Vec::new(), } } @@ -745,8 +739,6 @@ impl Damus { accounts: AccountManager::new(None, KeyStorageType::None), frame_history: FrameHistory::default(), show_account_switcher: false, - show_global_popup: true, - global_nav: Vec::new(), } } @@ -1109,7 +1101,6 @@ fn render_damus_desktop(ctx: &egui::Context, app: &mut Damus) { main_panel(&ctx.style(), ui::is_narrow(ctx)).show(ctx, |ui| { ui.spacing_mut().item_spacing.x = 0.0; AccountSelectionWidget::ui(app, ui); - DesktopGlobalPopup::show(app.global_nav.clone(), app, ui); if need_scroll { egui::ScrollArea::horizontal().show(ui, |ui| { timelines_view(ui, panel_sizes, app, app.columns.columns().len()); diff --git a/src/ui/account_switcher.rs b/src/ui/account_switcher.rs @@ -1,5 +1,5 @@ use crate::{ - account_manager::UserAccount, colors::PINK, profile::DisplayName, route::Route, ui, + account_manager::UserAccount, colors::PINK, profile::DisplayName, ui, ui::profile_preview_controller, Damus, Result, }; @@ -17,7 +17,6 @@ pub struct AccountSelectionWidget {} enum AccountSelectAction { RemoveAccount { _index: usize }, SelectAccount { _index: usize }, - OpenAccountManagement, } #[derive(Default)] @@ -54,11 +53,6 @@ impl AccountSelectionWidget { app.show_account_switcher = false; app.accounts.select_account(_index); } - AccountSelectAction::OpenAccountManagement => { - app.show_account_switcher = false; - app.global_nav.push(Route::ManageAccount); - app.show_global_popup = true; - } } } @@ -196,7 +190,7 @@ fn selection_widget() -> impl egui::Widget { fn top_section_widget(ui: &mut egui::Ui) -> AccountSelectResponse { ui.horizontal(|ui| { - let mut resp = AccountSelectResponse::default(); + let resp = AccountSelectResponse::default(); ui.allocate_ui_with_layout( Vec2::new(ui.available_size_before_wrap().x, 32.0), @@ -209,7 +203,7 @@ fn top_section_widget(ui: &mut egui::Ui) -> AccountSelectResponse { Layout::right_to_left(egui::Align::Center), |ui| { if ui.add(manage_accounts_button()).clicked() { - resp.action = Some(AccountSelectAction::OpenAccountManagement); + // resp.action = Some(AccountSelectAction::OpenAccountManagement); TODO implement after temporary column impl is finished } }, ); diff --git a/src/ui/fixed_window.rs b/src/ui/fixed_window.rs @@ -1,63 +0,0 @@ -use egui::{Rect, Response, RichText, Sense, Window}; - -#[derive(Default)] -pub struct FixedWindow { - title: Option<RichText>, -} - -#[derive(PartialEq)] -pub enum FixedWindowResponse { - Opened, - Closed, -} - -impl FixedWindow { - #[allow(dead_code)] - pub fn new() -> Self { - FixedWindow::default() - } - - pub fn maybe_with_title(maybe_title: Option<RichText>) -> Self { - Self { title: maybe_title } - } - - #[allow(dead_code)] - pub fn with_title(mut self, title: RichText) -> Self { - self.title = Some(title); - self - } - - pub fn show( - self, - ui: &mut egui::Ui, - rect: Rect, - add_contents: impl FnOnce(&mut egui::Ui) -> Response, - ) -> FixedWindowResponse { - let mut is_open = true; - - let use_title_bar = self.title.is_some(); - let title = if let Some(title) = self.title { - title - } else { - RichText::new("") - }; - - Window::new(title) - .open(&mut is_open) - .fixed_rect(rect) - .collapsible(false) - .movable(false) - .resizable(false) - .title_bar(use_title_bar) - .show(ui.ctx(), |ui| { - let resp = add_contents(ui); - ui.allocate_rect(resp.rect, Sense::hover()) - }); - - if !is_open { - FixedWindowResponse::Closed - } else { - FixedWindowResponse::Opened - } - } -} diff --git a/src/ui/global_popup.rs b/src/ui/global_popup.rs @@ -1,53 +0,0 @@ -use std::{cell::RefCell, rc::Rc}; - -use egui::Sense; -use egui_nav::{Nav, NavAction}; - -use crate::{route::Route, ui, Damus}; - -static MARGIN: f32 = 200.0; - -pub struct DesktopGlobalPopup {} - -impl DesktopGlobalPopup { - pub fn show(routes: Vec<Route>, app: &mut Damus, ui: &mut egui::Ui) { - if routes.is_empty() || !app.show_global_popup { - return; - } - - let rect = ui.ctx().screen_rect().shrink(MARGIN); - - let title = routes.last().map(|r| r.title()); - - let app_ctx = Rc::new(RefCell::new(app)); - - let resp = ui::FixedWindow::maybe_with_title(title).show(ui, rect, |ui| { - let nav_response = - Nav::new(routes) - .title(false) - .navigating(false) - .show(ui, |ui, nav| { - if let Some(resp) = - nav.top().show_global_popup(&mut app_ctx.borrow_mut(), ui) - { - ui.allocate_rect(resp.rect, Sense::hover()) - } else { - ui.label("") // TODO(kernelkind): not a great practice - } - }); - - if let Some(NavAction::Returned) = nav_response.action { - app_ctx.borrow_mut().global_nav.pop(); - } - - nav_response.inner - }); - - let mut app = app_ctx.borrow_mut(); - - if resp == ui::FixedWindowResponse::Closed { - app.global_nav.pop(); - app.show_global_popup = false; - } - } -} diff --git a/src/ui/mod.rs b/src/ui/mod.rs @@ -2,8 +2,6 @@ pub mod account_login_view; pub mod account_management; pub mod account_switcher; pub mod anim; -pub mod fixed_window; -pub mod global_popup; pub mod mention; pub mod note; pub mod preview; @@ -16,8 +14,6 @@ pub mod username; pub use account_management::AccountManagementView; pub use account_switcher::AccountSelectionWidget; -pub use fixed_window::{FixedWindow, FixedWindowResponse}; -pub use global_popup::DesktopGlobalPopup; pub use mention::Mention; pub use note::{NoteResponse, NoteView, PostReplyView, PostView}; pub use preview::{Preview, PreviewApp, PreviewConfig}; diff --git a/src/ui/side_panel.rs b/src/ui/side_panel.rs @@ -127,7 +127,7 @@ mod preview { use crate::{ test_data, - ui::{AccountSelectionWidget, DesktopGlobalPopup, Preview, PreviewConfig}, + ui::{AccountSelectionWidget, Preview, PreviewConfig}, }; use super::*; @@ -158,7 +158,6 @@ mod preview { }); AccountSelectionWidget::ui(&mut self.app, ui); - DesktopGlobalPopup::show(self.app.global_nav.clone(), &mut self.app, ui); } }