Skip to content

Commit

Permalink
feat: improve switcher layout and presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
allsochen authored and lwouis committed Nov 4, 2024
1 parent 649a5cb commit 545b5db
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/logic/Appearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Appearance {
static var windowMaxWidthInRow = CGFloat(0)
static var iconSize = CGFloat(0)
static var fontHeight = CGFloat(0)
static var maxWidthOnScreen = CGFloat(0)
static var maxHeightOnScreen = CGFloat(0)
static var maxWidthOnScreen = CGFloat(0.8)
static var maxHeightOnScreen = CGFloat(0.8)

// theme
static var material = NSVisualEffectView.Material.dark
Expand Down Expand Up @@ -72,6 +72,24 @@ class Appearance {
}
}

// calculate windowMinWidthInRow and windowMaxWidthInRow such that:
// * fullscreen windows fill their tile vertically
// * narrow windows have enough width that a few words can be read from their title
private static func calculateGoodValuesForThumbnailsWidthMinMax() -> (CGFloat, CGFloat) {
let aspectRatio = NSScreen.preferred().ratio()
let minRatio: CGFloat
let maxRatio: CGFloat
if aspectRatio >= 1 {
minRatio = 0.7 / (aspectRatio * rowsCount)
maxRatio = 1.5 / (aspectRatio * rowsCount)
} else {
minRatio = 1.3 / rowsCount
maxRatio = 2.1 / rowsCount
}
// Make sure the values are clamped between some reasonable bounds
return (max(0.09, minRatio), min(0.3, maxRatio))
}

private static func thumbnailsSize(_ isHorizontalScreen: Bool) {
hideThumbnails = false
windowPadding = 18
Expand All @@ -80,10 +98,6 @@ class Appearance {
intraCellPadding = 5
interCellPadding = 1
edgeInsetsSize = 12
maxWidthOnScreen = 0.9
maxHeightOnScreen = 0.8
windowMinWidthInRow = 0.1
windowMaxWidthInRow = 0.15
switch currentSize {
case .small:
rowsCount = isHorizontalScreen ? 5 : 8
Expand All @@ -95,11 +109,10 @@ class Appearance {
fontHeight = 13
case .large:
rowsCount = isHorizontalScreen ? 3 : 6
windowMinWidthInRow = 0.15
windowMaxWidthInRow = 0.3
iconSize = 32
fontHeight = 16
}
(windowMinWidthInRow, windowMaxWidthInRow) = calculateGoodValuesForThumbnailsWidthMinMax()
if currentVisibility == .highest {
edgeInsetsSize = 10
cellCornerRadius = 12
Expand All @@ -114,8 +127,6 @@ class Appearance {
intraCellPadding = 5
interCellPadding = 1
edgeInsetsSize = 5
maxWidthOnScreen = 0.95
maxHeightOnScreen = 0.9
windowMinWidthInRow = 0.04
windowMaxWidthInRow = 0.3
rowsCount = 1
Expand All @@ -141,8 +152,7 @@ class Appearance {
intraCellPadding = 5
interCellPadding = 1
edgeInsetsSize = 7
maxWidthOnScreen = isHorizontalScreen ? 0.6 : 0.85
maxHeightOnScreen = 0.8
maxWidthOnScreen = isHorizontalScreen ? 0.6 : 0.8
windowMinWidthInRow = 0.6
windowMaxWidthInRow = 0.9
rowsCount = 1
Expand Down

0 comments on commit 545b5db

Please sign in to comment.