add a border to ansipicker, and fix the corner radius

fix light themes having unreadable text
added a luminance property to calculate the brighness of the bg color
if its > 0.5, choose a light theme to get black text
This commit is contained in:
neon443
2025-07-03 18:19:13 +01:00
parent d71d6199c8
commit b9327f993e
4 changed files with 41 additions and 23 deletions

View File

@@ -27,7 +27,7 @@ struct ShhShellApp: App {
hostsManager: hostsManager,
keyManager: keyManager
)
.colorScheme(.dark)
.colorScheme(hostsManager.selectedTheme.background.luminance > 0.5 ? .light : .dark)
.tint(hostsManager.selectedTheme.ansi[hostsManager.selectedAnsi].suiColor)
}
}

View File

@@ -55,3 +55,12 @@ extension SwiftTerm.Color {
return UIColor(red: red, green: green, blue: blue, alpha: 1)
}
}
extension SwiftTerm.Color {
var luminance: Double {
let r = Double(red)/65535
let g = Double(green)/65535
let b = Double(blue)/65535
return (0.2126*r + 0.7152*g + 0.0722*b)
}
}

View File

@@ -11,6 +11,10 @@ struct AnsiPickerView: View {
@ObservedObject var hostsManager: HostsManager
var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 15)
.aspectRatio(CGSize(width: 4, height: 1), contentMode: .fit)
.foregroundStyle(hostsManager.selectedTheme.foreground.suiColor.opacity(0.7))
GeometryReader { geo in
VStack(spacing: 0) {
ForEach(0...1, id: \.self) { row in
@@ -21,14 +25,9 @@ struct AnsiPickerView: View {
ZStack {
Rectangle()
.fill(hostsManager.selectedTheme.background.suiColor)
Rectangle()
RoundedRectangle(cornerRadius: isSelected ? 5 : 0)
.fill(hostsManager.selectedTheme.ansi[index].suiColor)
.padding(isSelected ? 5 : 0)
.clipShape(
RoundedRectangle(
cornerRadius: isSelected ? 10 : 0
)
)
.onTapGesture {
hostsManager.selectAnsi(index)
}
@@ -38,7 +37,10 @@ struct AnsiPickerView: View {
}
}
}
.clipShape(RoundedRectangle(cornerRadius: 15))
.aspectRatio(CGSize(width: 4, height: 1), contentMode: .fit)
.clipShape(RoundedRectangle(cornerRadius: 10))
.padding(5)
}
}
}

View File

@@ -51,6 +51,13 @@ struct ThemeManagerView: View {
}
.padding(.horizontal)
HStack {
Text("Your Themes")
.padding(.top)
.padding(.horizontal)
.font(.headline)
Spacer()
}
if hostsManager.themes.isEmpty {
VStack(alignment: .leading) {
Image(systemName: "paintpalette")