Skip to content

Commit

Permalink
Add WidgetAppearance.autoCompact
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Feb 20, 2025
1 parent 44b18bc commit 08f6a98
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/TrueWidget/swift/TrueWidgetApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,17 @@ struct TrueWidgetApp: App {
title: "Compact",
checked: userSettings.widgetAppearance == WidgetAppearance.compact.rawValue)
}
)

Button(
action: {
userSettings.widgetAppearance = WidgetAppearance.autoCompact.rawValue
},
label: {
checkmarkLabel(
title: "Auto Compact",
checked: userSettings.widgetAppearance == WidgetAppearance.autoCompact.rawValue)
}
)

Button(
Expand Down
1 change: 1 addition & 0 deletions src/TrueWidget/swift/UserSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum WidgetScreen: String {
enum WidgetAppearance: String {
case normal
case compact
case autoCompact
case hidden
}

Expand Down
19 changes: 17 additions & 2 deletions src/TrueWidget/swift/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ struct ContentView: View {
@Environment(\.openSettingsLegacy) var openSettingsLegacy
private var window: NSWindow
@ObservedObject private var userSettings: UserSettings
@StateObject private var displayMonitor = DisplayMonitor()

@State private var hidden = false
private let windowPositionManager: WindowPositionManager
Expand All @@ -17,7 +18,7 @@ struct ContentView: View {

var body: some View {
VStack {
if userSettings.widgetAppearance == WidgetAppearance.compact.rawValue {
if isCompactView() {
CompactView(userSettings: userSettings)
} else {
VStack(alignment: .leading, spacing: 10.0) {
Expand Down Expand Up @@ -47,7 +48,7 @@ struct ContentView: View {
}
}
.padding()
.if(userSettings.widgetAppearance != WidgetAppearance.compact.rawValue) {
.if(!isCompactView()) {
$0.frame(width: userSettings.widgetWidth)
}
.fixedSize()
Expand Down Expand Up @@ -91,4 +92,18 @@ struct ContentView: View {
}
}
}

private func isCompactView() -> Bool {
switch userSettings.widgetAppearance {
case WidgetAppearance.compact.rawValue:
return true
case WidgetAppearance.autoCompact.rawValue:
if displayMonitor.displayCount == 1 {
return true
}
return false
default:
return false
}
}
}
1 change: 1 addition & 0 deletions src/TrueWidget/swift/Views/Settings/SettingsMainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ struct SettingsMainView: View {
Picker("", selection: $userSettings.widgetAppearance) {
Text("Normal").tag(WidgetAppearance.normal.rawValue)
Text("Compact").tag(WidgetAppearance.compact.rawValue)
Text("Auto Compact").tag(WidgetAppearance.autoCompact.rawValue)
Text("Hidden").tag(WidgetAppearance.hidden.rawValue)
}
.pickerStyle(.radioGroup)
Expand Down

0 comments on commit 08f6a98

Please sign in to comment.