From e0acbc66e4f54670659f797926b3e260d1aa6a4f Mon Sep 17 00:00:00 2001 From: Amos Jun-yeung Ng Date: Tue, 30 Jul 2024 20:14:25 +0700 Subject: [PATCH 1/5] Make Window and UI smaller on Retina Macs --- src-svelte/src/routes/styles.css | 6 ++++++ src-tauri/src/main.rs | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src-svelte/src/routes/styles.css b/src-svelte/src/routes/styles.css index 6b683288..3322edf7 100644 --- a/src-svelte/src/routes/styles.css +++ b/src-svelte/src/routes/styles.css @@ -78,6 +78,12 @@ font-size: 18px; } +@media only screen and (-webkit-min-device-pixel-ratio: 2) { + :root { + font-size: 14px; + } +} + td, th { padding: 0; } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 5753308c..3145bc6a 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -13,13 +13,14 @@ mod test_helpers; mod upgrades; mod views; +use anyhow::anyhow; use clap::Parser; use diesel::sqlite::SqliteConnection; use futures::executor; use setup::api_keys::{setup_api_keys, ApiKeys}; #[cfg(debug_assertions)] use specta::collect_types; -use tauri::Manager; +use tauri::{LogicalSize, Manager, Size}; #[cfg(debug_assertions)] use tauri_specta::ts; use tokio::sync::Mutex; @@ -77,6 +78,16 @@ fn main() { }); }); + #[cfg(target_os = "macos")] + { + app.get_window("main") + .ok_or(anyhow!("No main window"))? + .set_size(Size::Logical(LogicalSize { + width: 600.0, + height: 450.0, + }))?; + } + Ok(()) }) .manage(ZammDatabase(Mutex::new(possible_db))) From ca84d9c583d67ccf3464403032fc9d2644c1d3bc Mon Sep 17 00:00:00 2001 From: Amos Jun-yeung Ng Date: Thu, 1 Aug 2024 13:28:16 +0700 Subject: [PATCH 2/5] Adjust JS font sizes based on rem --- src-svelte/src/lib/InfoBox.svelte | 9 +++++++-- src-svelte/src/lib/Slider.svelte | 6 ++---- src-svelte/src/lib/Switch.svelte | 7 ++----- src-svelte/src/lib/preferences.ts | 18 ++++++++++++++++++ src-svelte/src/routes/BackgroundUI.svelte | 4 ++-- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src-svelte/src/lib/InfoBox.svelte b/src-svelte/src/lib/InfoBox.svelte index d93b4d09..1eb27f5b 100644 --- a/src-svelte/src/lib/InfoBox.svelte +++ b/src-svelte/src/lib/InfoBox.svelte @@ -244,7 +244,12 @@ import getComponentId from "./label-id"; import RoundDef from "./RoundDef.svelte"; import { cubicInOut, cubicOut, linear } from "svelte/easing"; - import { animationSpeed, animationsOn, transparencyOn } from "./preferences"; + import { + animationSpeed, + animationsOn, + transparencyOn, + getAdjustedFontSize, + } from "./preferences"; import { fade, type TransitionConfig } from "svelte/transition"; import { firstAppLoad, firstPageLoad } from "./firstPageLoad"; import { SubAnimation, PropertyAnimation } from "$lib/animation-timing"; @@ -267,7 +272,7 @@ const parentNode = node.parentNode as Element; const actualWidth = parentNode.clientWidth; const actualHeight = parentNode.clientHeight; - const heightPerTitleLinePx = 26; + const heightPerTitleLinePx = getAdjustedFontSize(26); const titleHeight = (titleElement as HTMLElement).clientHeight; // multiply by 1.3 to account for small pixel differences between browsers const titleIsMultiline = titleHeight > heightPerTitleLinePx * 1.3; diff --git a/src-svelte/src/lib/Slider.svelte b/src-svelte/src/lib/Slider.svelte index 27d6b04f..2cfa41ee 100644 --- a/src-svelte/src/lib/Slider.svelte +++ b/src-svelte/src/lib/Slider.svelte @@ -6,14 +6,12 @@ type DragOptions, type DragEventData, } from "@neodrag/svelte"; + import { ROOT_EM } from "./preferences"; - const rootFontSize = parseFloat( - getComputedStyle(document.documentElement).fontSize, - ); const sliderId = getComponentId("slider"); const transitionAnimation = `transition: ` + `transform var(--standard-duration) ease-out;`; - const overshoot = 0.4 * rootFontSize; // how much overshoot to allow per-side + const overshoot = 0.4 * ROOT_EM; // how much overshoot to allow per-side export let label: string | undefined = undefined; export let min = 0; diff --git a/src-svelte/src/lib/Switch.svelte b/src-svelte/src/lib/Switch.svelte index fff7e3fc..4f481b71 100644 --- a/src-svelte/src/lib/Switch.svelte +++ b/src-svelte/src/lib/Switch.svelte @@ -10,7 +10,7 @@