Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from p0deje:master #87

Merged
merged 9 commits into from
Jan 23, 2025
Prev Previous commit
Next Next commit
Fix SwiftLint warnings
  • Loading branch information
p0deje committed Jan 22, 2025
commit f5e6cf5298fb0aaf08ba9ff3db3c075942947b69
73 changes: 36 additions & 37 deletions Maccy/Settings/AppearanceSettingsPane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,49 +48,13 @@ struct AppearanceSettingsPane: View {
return formatter
}()

private func labelForScreen(index screenIndex: Int) -> String {
switch screenIndex {
case 0:
return String(localized: "ActiveScreen", table: "AppearanceSettings")
case _: return screens[screenIndex - 1].localizedName
}
}

@ViewBuilder private func screenPicker(for position: PopupPosition)
-> some View
{
let screenBinding: Binding<Int> = Binding {
return popupScreen
} set: {
popupScreen = $0
popupAt = position
}
Picker(selection: screenBinding) {
Text(labelForScreen(index: 0))
.tag(0)

ForEach(screens.indices, id: \.self) { index in
Text(labelForScreen(index: index + 1))
.tag(index + 1)
}
} label: {
if popupAt == position {
Text("\(position.description) (\(labelForScreen(index: popupScreen)))")
} else {
Text(position.description)
}
}
}

var body: some View {
Settings.Container(contentWidth: 650) {
Settings.Section(label: { Text("PopupAt", tableName: "AppearanceSettings") }) {
HStack {
Picker("", selection: $popupAt) {
ForEach(PopupPosition.allCases) { position in
if position == .center || position == .lastPosition,
screens.count > 1
{
if position == .center || position == .lastPosition, screens.count > 1 {
screenPicker(for: position)
} else {
Text(position.description)
Expand Down Expand Up @@ -220,6 +184,41 @@ struct AppearanceSettingsPane: View {
screens = NSScreen.screens
}
}

@ViewBuilder
private func screenPicker(for position: PopupPosition) -> some View {
let screenBinding: Binding<Int> = Binding {
return popupScreen
} set: {
popupScreen = $0
popupAt = position
}

Picker(selection: screenBinding) {
Text(labelForScreen(index: 0))
.tag(0)

ForEach(screens.indices, id: \.self) { index in
Text(labelForScreen(index: index + 1))
.tag(index + 1)
}
} label: {
if popupAt == position {
Text("\(position.description) (\(labelForScreen(index: popupScreen)))")
} else {
Text(position.description)
}
}
}

private func labelForScreen(index screenIndex: Int) -> String {
switch screenIndex {
case 0:
return String(localized: "ActiveScreen", table: "AppearanceSettings")
case _:
return screens[screenIndex - 1].localizedName
}
}
}

#Preview {
Expand Down