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>
This commit is contained in:
William Casarin
2024-09-06 21:53:42 -07:00
parent 772bfbad5f
commit 4a4fb06425
9 changed files with 46 additions and 42 deletions

View File

@@ -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()
}
}
}

View File

@@ -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()
}
}
}

View File

@@ -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()
}

View File

@@ -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(

View File

@@ -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()
}
}
}

View File

@@ -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()
}
}
}