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:
23
src/app.rs
23
src/app.rs
@@ -66,8 +66,7 @@ pub struct Damus {
|
|||||||
|
|
||||||
frame_history: crate::frame_history::FrameHistory,
|
frame_history: crate::frame_history::FrameHistory,
|
||||||
|
|
||||||
// TODO: make these flags
|
// TODO: make these bitflags
|
||||||
is_mobile: bool,
|
|
||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
pub since_optimize: bool,
|
pub since_optimize: bool,
|
||||||
pub textmode: 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) {
|
fn render_damus(damus: &mut Damus, ctx: &Context) {
|
||||||
if damus.is_mobile() {
|
if ui::is_narrow(ctx) {
|
||||||
render_damus_mobile(ctx, damus);
|
render_damus_mobile(ctx, damus);
|
||||||
} else {
|
} else {
|
||||||
render_damus_desktop(ctx, damus);
|
render_damus_desktop(ctx, damus);
|
||||||
@@ -656,7 +655,6 @@ impl Damus {
|
|||||||
Self {
|
Self {
|
||||||
pool,
|
pool,
|
||||||
debug,
|
debug,
|
||||||
is_mobile,
|
|
||||||
unknown_ids: UnknownIds::default(),
|
unknown_ids: UnknownIds::default(),
|
||||||
subscriptions: Subscriptions::default(),
|
subscriptions: Subscriptions::default(),
|
||||||
since_optimize: parsed_args.since_optimize,
|
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 mut timelines: Vec<Timeline> = vec![];
|
||||||
let filter = Filter::from_json(include_str!("../queries/global.json")).unwrap();
|
let filter = Filter::from_json(include_str!("../queries/global.json")).unwrap();
|
||||||
timelines.push(Timeline::new(
|
timelines.push(Timeline::new(
|
||||||
@@ -700,7 +698,6 @@ impl Damus {
|
|||||||
let mut config = Config::new();
|
let mut config = Config::new();
|
||||||
config.set_ingester_threads(2);
|
config.set_ingester_threads(2);
|
||||||
Self {
|
Self {
|
||||||
is_mobile,
|
|
||||||
debug,
|
debug,
|
||||||
unknown_ids: UnknownIds::default(),
|
unknown_ids: UnknownIds::default(),
|
||||||
subscriptions: Subscriptions::default(),
|
subscriptions: Subscriptions::default(),
|
||||||
@@ -770,10 +767,6 @@ impl Damus {
|
|||||||
}
|
}
|
||||||
self.selected_timeline += 1;
|
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;
|
ui.visuals_mut().button_frame = false;
|
||||||
|
|
||||||
if let Some(new_visuals) =
|
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)
|
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();
|
//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);
|
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 {
|
let inner_margin = egui::Margin {
|
||||||
top: if mobile { 50.0 } else { 0.0 },
|
top: if narrow { 50.0 } else { 0.0 },
|
||||||
left: 0.0,
|
left: 0.0,
|
||||||
right: 0.0,
|
right: 0.0,
|
||||||
bottom: 0.0,
|
bottom: 0.0,
|
||||||
@@ -1054,7 +1047,7 @@ fn render_damus_desktop(ctx: &egui::Context, app: &mut Damus) {
|
|||||||
Size::remainder()
|
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;
|
ui.spacing_mut().item_spacing.x = 0.0;
|
||||||
AccountSelectionWidget::ui(app, ui);
|
AccountSelectionWidget::ui(app, ui);
|
||||||
DesktopGlobalPopup::show(app.global_nav.clone(), app, ui);
|
DesktopGlobalPopup::show(app.global_nav.clone(), app, ui);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ pub fn dark_mode(mobile: bool) -> Visuals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn user_requested_visuals_change(
|
pub fn user_requested_visuals_change(
|
||||||
mobile: bool,
|
oled: bool,
|
||||||
cur_darkmode: bool,
|
cur_darkmode: bool,
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
) -> Option<Visuals> {
|
) -> Option<Visuals> {
|
||||||
@@ -44,7 +44,7 @@ pub fn user_requested_visuals_change(
|
|||||||
.on_hover_text("Switch to dark mode")
|
.on_hover_text("Switch to dark mode")
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
return Some(dark_mode(mobile));
|
return Some(dark_mode(oled));
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,10 +92,10 @@ pub fn get_test_accounts() -> Vec<UserAccount> {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn test_app(is_mobile: bool) -> Damus {
|
pub fn test_app() -> Damus {
|
||||||
let db_dir = Path::new(".");
|
let db_dir = Path::new(".");
|
||||||
let path = db_dir.to_str().unwrap();
|
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();
|
let accounts = get_test_accounts();
|
||||||
for account in accounts {
|
for account in accounts {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use crate::colors::PINK;
|
|||||||
use crate::{
|
use crate::{
|
||||||
account_manager::AccountManager,
|
account_manager::AccountManager,
|
||||||
app_style::NotedeckTextStyle,
|
app_style::NotedeckTextStyle,
|
||||||
|
ui,
|
||||||
ui::{profile_preview_controller, Preview, PreviewConfig, View},
|
ui::{profile_preview_controller, Preview, PreviewConfig, View},
|
||||||
Damus,
|
Damus,
|
||||||
};
|
};
|
||||||
@@ -14,7 +15,7 @@ pub struct AccountManagementView {}
|
|||||||
|
|
||||||
impl AccountManagementView {
|
impl AccountManagementView {
|
||||||
pub fn ui(app: &mut Damus, ui: &mut egui::Ui) -> Option<Response> {
|
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);
|
AccountManagementView::show_mobile(app, ui);
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@@ -216,22 +217,21 @@ mod preview {
|
|||||||
use crate::test_data;
|
use crate::test_data;
|
||||||
|
|
||||||
pub struct AccountManagementPreview {
|
pub struct AccountManagementPreview {
|
||||||
is_mobile: bool,
|
|
||||||
app: Damus,
|
app: Damus,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AccountManagementPreview {
|
impl AccountManagementPreview {
|
||||||
fn new(is_mobile: bool) -> Self {
|
fn new() -> Self {
|
||||||
let app = test_data::test_app(is_mobile);
|
let app = test_data::test_app();
|
||||||
|
|
||||||
AccountManagementPreview { is_mobile, app }
|
AccountManagementPreview { app }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl View for AccountManagementPreview {
|
impl View for AccountManagementPreview {
|
||||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||||
ui.add_space(24.0);
|
ui.add_space(24.0);
|
||||||
if self.is_mobile {
|
if ui::is_narrow(ui.ctx()) {
|
||||||
AccountManagementView::show_mobile(&mut self.app, ui);
|
AccountManagementView::show_mobile(&mut self.app, ui);
|
||||||
} else {
|
} else {
|
||||||
AccountManagementView::show(&mut self.app, ui);
|
AccountManagementView::show(&mut self.app, ui);
|
||||||
@@ -242,8 +242,8 @@ mod preview {
|
|||||||
impl Preview for AccountManagementView {
|
impl Preview for AccountManagementView {
|
||||||
type Prev = AccountManagementPreview;
|
type Prev = AccountManagementPreview;
|
||||||
|
|
||||||
fn preview(cfg: PreviewConfig) -> Self::Prev {
|
fn preview(_cfg: PreviewConfig) -> Self::Prev {
|
||||||
AccountManagementPreview::new(cfg.is_mobile)
|
AccountManagementPreview::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
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,
|
ui::profile_preview_controller, Damus, Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ impl AccountSelectionWidget {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if app.is_mobile() {
|
if ui::is_narrow(ui.ctx()) {
|
||||||
Self::show_mobile(ui);
|
Self::show_mobile(ui);
|
||||||
} else {
|
} else {
|
||||||
account_switcher_window(&mut app.show_account_switcher.clone()).show(
|
account_switcher_window(&mut app.show_account_switcher.clone()).show(
|
||||||
@@ -256,8 +256,8 @@ mod previews {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AccountSelectionPreview {
|
impl AccountSelectionPreview {
|
||||||
fn new(is_mobile: bool) -> Self {
|
fn new() -> Self {
|
||||||
let app = test_data::test_app(is_mobile);
|
let app = test_data::test_app();
|
||||||
AccountSelectionPreview { app }
|
AccountSelectionPreview { app }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,8 +271,8 @@ mod previews {
|
|||||||
impl Preview for AccountSelectionWidget {
|
impl Preview for AccountSelectionWidget {
|
||||||
type Prev = AccountSelectionPreview;
|
type Prev = AccountSelectionPreview;
|
||||||
|
|
||||||
fn preview(cfg: PreviewConfig) -> Self::Prev {
|
fn preview(_cfg: PreviewConfig) -> Self::Prev {
|
||||||
AccountSelectionPreview::new(cfg.is_mobile)
|
AccountSelectionPreview::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,3 +72,14 @@ pub fn is_compiled_as_mobile() -> bool {
|
|||||||
false
|
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()
|
||||||
|
}
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ impl<'a> NoteView<'a> {
|
|||||||
let profile_key = profile.as_ref().unwrap().record().note_key();
|
let profile_key = profile.as_ref().unwrap().record().note_key();
|
||||||
let note_key = note_key.as_u64();
|
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));
|
ui.add(ui::ProfilePic::new(&mut self.app.img_cache, pic));
|
||||||
} else {
|
} else {
|
||||||
let (rect, size, _resp) = ui::anim::hover_expand(
|
let (rect, size, _resp) = ui::anim::hover_expand(
|
||||||
|
|||||||
@@ -174,9 +174,9 @@ mod preview {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PostPreview {
|
impl PostPreview {
|
||||||
fn new(is_mobile: bool) -> Self {
|
fn new() -> Self {
|
||||||
PostPreview {
|
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> {
|
impl<'app, 'p> Preview for PostView<'app, 'p> {
|
||||||
type Prev = PostPreview;
|
type Prev = PostPreview;
|
||||||
|
|
||||||
fn preview(cfg: PreviewConfig) -> Self::Prev {
|
fn preview(_cfg: PreviewConfig) -> Self::Prev {
|
||||||
PostPreview::new(cfg.is_mobile)
|
PostPreview::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,8 +137,8 @@ mod preview {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DesktopSidePanelPreview {
|
impl DesktopSidePanelPreview {
|
||||||
fn new(is_mobile: bool) -> Self {
|
fn new() -> Self {
|
||||||
let app = test_data::test_app(is_mobile);
|
let app = test_data::test_app();
|
||||||
DesktopSidePanelPreview { app }
|
DesktopSidePanelPreview { app }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,8 +165,8 @@ mod preview {
|
|||||||
impl<'a> Preview for DesktopSidePanel<'a> {
|
impl<'a> Preview for DesktopSidePanel<'a> {
|
||||||
type Prev = DesktopSidePanelPreview;
|
type Prev = DesktopSidePanelPreview;
|
||||||
|
|
||||||
fn preview(cfg: PreviewConfig) -> Self::Prev {
|
fn preview(_cfg: PreviewConfig) -> Self::Prev {
|
||||||
DesktopSidePanelPreview::new(cfg.is_mobile)
|
DesktopSidePanelPreview::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user