notedeck

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

commit 4a4fb0642570a87698ee2bdd691deba7cc371d72
parent 772bfbad5f6291f03acc3908bba81944622ed5d9
Author: William Casarin <jb55@jb55.com>
Date:   Fri,  6 Sep 2024 21:53:42 -0700

split is_mobile to is_narrow and is_oled

is_mobile doesn't really make sense for android tablets. We were
overloading this variable to mean "is_narrow". What we really want is
is_oled for mobile devices and is_narrow for if its phone-like.

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/app.rs | 23++++++++---------------
Msrc/app_style.rs | 4++--
Msrc/test_data.rs | 4++--
Msrc/ui/account_management.rs | 16++++++++--------
Msrc/ui/account_switcher.rs | 12++++++------
Msrc/ui/mod.rs | 11+++++++++++
Msrc/ui/note/mod.rs | 2+-
Msrc/ui/note/post.rs | 8++++----
Msrc/ui/side_panel.rs | 8++++----
9 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/src/app.rs b/src/app.rs @@ -66,8 +66,7 @@ pub struct Damus { frame_history: crate::frame_history::FrameHistory, - // TODO: make these flags - is_mobile: bool, + // TODO: make these bitflags pub debug: bool, pub since_optimize: bool, pub textmode: bool, @@ -537,7 +536,7 @@ fn process_message(damus: &mut Damus, relay: &str, msg: &RelayMessage) { } fn render_damus(damus: &mut Damus, ctx: &Context) { - if damus.is_mobile() { + if ui::is_narrow(ctx) { render_damus_mobile(ctx, damus); } else { render_damus_desktop(ctx, damus); @@ -656,7 +655,6 @@ impl Damus { Self { pool, debug, - is_mobile, unknown_ids: UnknownIds::default(), subscriptions: Subscriptions::default(), since_optimize: parsed_args.since_optimize, @@ -685,7 +683,7 @@ impl Damus { } } - pub fn mock<P: AsRef<Path>>(data_path: P, is_mobile: bool) -> Self { + pub fn mock<P: AsRef<Path>>(data_path: P) -> Self { let mut timelines: Vec<Timeline> = vec![]; let filter = Filter::from_json(include_str!("../queries/global.json")).unwrap(); timelines.push(Timeline::new( @@ -700,7 +698,6 @@ impl Damus { let mut config = Config::new(); config.set_ingester_threads(2); Self { - is_mobile, debug, unknown_ids: UnknownIds::default(), subscriptions: Subscriptions::default(), @@ -770,10 +767,6 @@ impl Damus { } self.selected_timeline += 1; } - - pub fn is_mobile(&self) -> bool { - self.is_mobile - } } /* @@ -810,7 +803,7 @@ fn render_panel(ctx: &egui::Context, app: &mut Damus, timeline_ind: usize) { ui.visuals_mut().button_frame = false; if let Some(new_visuals) = - user_requested_visuals_change(app.is_mobile(), ctx.style().visuals.dark_mode, ui) + user_requested_visuals_change(ui::is_oled(), ctx.style().visuals.dark_mode, ui) { ctx.set_visuals(new_visuals) } @@ -1020,14 +1013,14 @@ fn render_damus_mobile(ctx: &egui::Context, app: &mut Damus) { //let routes = app.timelines[0].routes.clone(); - main_panel(&ctx.style(), app.is_mobile()).show(ctx, |ui| { + main_panel(&ctx.style(), ui::is_narrow(ctx)).show(ctx, |ui| { render_nav(app.timelines[0].routes.clone(), 0, app, ui); }); } -fn main_panel(style: &Style, mobile: bool) -> egui::CentralPanel { +fn main_panel(style: &Style, narrow: bool) -> egui::CentralPanel { let inner_margin = egui::Margin { - top: if mobile { 50.0 } else { 0.0 }, + top: if narrow { 50.0 } else { 0.0 }, left: 0.0, right: 0.0, bottom: 0.0, @@ -1054,7 +1047,7 @@ fn render_damus_desktop(ctx: &egui::Context, app: &mut Damus) { Size::remainder() }; - main_panel(&ctx.style(), app.is_mobile()).show(ctx, |ui| { + 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); diff --git a/src/app_style.rs b/src/app_style.rs @@ -27,7 +27,7 @@ pub fn dark_mode(mobile: bool) -> Visuals { } pub fn user_requested_visuals_change( - mobile: bool, + oled: bool, cur_darkmode: bool, ui: &mut Ui, ) -> Option<Visuals> { @@ -44,7 +44,7 @@ pub fn user_requested_visuals_change( .on_hover_text("Switch to dark mode") .clicked() { - return Some(dark_mode(mobile)); + return Some(dark_mode(oled)); } None } diff --git a/src/test_data.rs b/src/test_data.rs @@ -92,10 +92,10 @@ pub fn get_test_accounts() -> Vec<UserAccount> { .collect() } -pub fn test_app(is_mobile: bool) -> Damus { +pub fn test_app() -> Damus { let db_dir = Path::new("."); let path = db_dir.to_str().unwrap(); - let mut app = Damus::mock(path, is_mobile); + let mut app = Damus::mock(path); let accounts = get_test_accounts(); for account in accounts { diff --git a/src/ui/account_management.rs b/src/ui/account_management.rs @@ -2,6 +2,7 @@ use crate::colors::PINK; use crate::{ account_manager::AccountManager, app_style::NotedeckTextStyle, + ui, ui::{profile_preview_controller, Preview, PreviewConfig, View}, Damus, }; @@ -14,7 +15,7 @@ pub struct AccountManagementView {} impl AccountManagementView { pub fn ui(app: &mut Damus, ui: &mut egui::Ui) -> Option<Response> { - if app.is_mobile() { + if ui::is_narrow(ui.ctx()) { AccountManagementView::show_mobile(app, ui); None } else { @@ -216,22 +217,21 @@ mod preview { use crate::test_data; pub struct AccountManagementPreview { - is_mobile: bool, app: Damus, } impl AccountManagementPreview { - fn new(is_mobile: bool) -> Self { - let app = test_data::test_app(is_mobile); + fn new() -> Self { + let app = test_data::test_app(); - AccountManagementPreview { is_mobile, app } + AccountManagementPreview { app } } } impl View for AccountManagementPreview { fn ui(&mut self, ui: &mut egui::Ui) { ui.add_space(24.0); - if self.is_mobile { + if ui::is_narrow(ui.ctx()) { AccountManagementView::show_mobile(&mut self.app, ui); } else { AccountManagementView::show(&mut self.app, ui); @@ -242,8 +242,8 @@ mod preview { impl Preview for AccountManagementView { type Prev = AccountManagementPreview; - fn preview(cfg: PreviewConfig) -> Self::Prev { - AccountManagementPreview::new(cfg.is_mobile) + fn preview(_cfg: PreviewConfig) -> Self::Prev { + AccountManagementPreview::new() } } } 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, + account_manager::UserAccount, colors::PINK, profile::DisplayName, route::Route, ui, ui::profile_preview_controller, Damus, Result, }; @@ -31,7 +31,7 @@ impl AccountSelectionWidget { return; } - if app.is_mobile() { + if ui::is_narrow(ui.ctx()) { Self::show_mobile(ui); } else { account_switcher_window(&mut app.show_account_switcher.clone()).show( @@ -256,8 +256,8 @@ mod previews { } impl AccountSelectionPreview { - fn new(is_mobile: bool) -> Self { - let app = test_data::test_app(is_mobile); + fn new() -> Self { + let app = test_data::test_app(); AccountSelectionPreview { app } } } @@ -271,8 +271,8 @@ mod previews { impl Preview for AccountSelectionWidget { type Prev = AccountSelectionPreview; - fn preview(cfg: PreviewConfig) -> Self::Prev { - AccountSelectionPreview::new(cfg.is_mobile) + fn preview(_cfg: PreviewConfig) -> Self::Prev { + AccountSelectionPreview::new() } } } diff --git a/src/ui/mod.rs b/src/ui/mod.rs @@ -72,3 +72,14 @@ pub fn is_compiled_as_mobile() -> bool { false } } + +/// Determine if the screen is narrow. This is useful for detecting mobile +/// contexts, but with the nuance that we may also have a wide android tablet. +pub fn is_narrow(ctx: &egui::Context) -> bool { + let screen_size = ctx.input(|c| c.screen_rect().size()); + screen_size.x < 550.0 +} + +pub fn is_oled() -> bool { + is_compiled_as_mobile() +} diff --git a/src/ui/note/mod.rs b/src/ui/note/mod.rs @@ -255,7 +255,7 @@ impl<'a> NoteView<'a> { let profile_key = profile.as_ref().unwrap().record().note_key(); let note_key = note_key.as_u64(); - if self.app.is_mobile() { + if ui::is_narrow(ui.ctx()) { ui.add(ui::ProfilePic::new(&mut self.app.img_cache, pic)); } else { let (rect, size, _resp) = ui::anim::hover_expand( diff --git a/src/ui/note/post.rs b/src/ui/note/post.rs @@ -174,9 +174,9 @@ mod preview { } impl PostPreview { - fn new(is_mobile: bool) -> Self { + fn new() -> Self { PostPreview { - app: test_data::test_app(is_mobile), + app: test_data::test_app(), } } } @@ -191,8 +191,8 @@ mod preview { impl<'app, 'p> Preview for PostView<'app, 'p> { type Prev = PostPreview; - fn preview(cfg: PreviewConfig) -> Self::Prev { - PostPreview::new(cfg.is_mobile) + fn preview(_cfg: PreviewConfig) -> Self::Prev { + PostPreview::new() } } } diff --git a/src/ui/side_panel.rs b/src/ui/side_panel.rs @@ -137,8 +137,8 @@ mod preview { } impl DesktopSidePanelPreview { - fn new(is_mobile: bool) -> Self { - let app = test_data::test_app(is_mobile); + fn new() -> Self { + let app = test_data::test_app(); DesktopSidePanelPreview { app } } } @@ -165,8 +165,8 @@ mod preview { impl<'a> Preview for DesktopSidePanel<'a> { type Prev = DesktopSidePanelPreview; - fn preview(cfg: PreviewConfig) -> Self::Prev { - DesktopSidePanelPreview::new(cfg.is_mobile) + fn preview(_cfg: PreviewConfig) -> Self::Prev { + DesktopSidePanelPreview::new() } } }