added a themepreview to themeditor

added background to themeeditor
extracted the raw themepreview to thempreview and made the previous view themebutton
fixed padding above your themes header
This commit is contained in:
neon443 committed 2025-07-09 12:12:34 +01:00
1 parent e2cb313ddc
commit a3003a6e90
5 files changed
+173 -142

No files matched your search

+90
View File
@@ -0,0 +1,90 @@
//
// ThemeButton.swift
// ShhShell
//
// Created by neon443 on 27/06/2025.
//
import SwiftUI
struct ThemeButton: View {
@ObservedObject var hostsManager: HostsManager
@Binding var theme: Theme
@State var canModify: Bool
@State private var showRenameAlert: Bool = false
@State private var rename: String = ""
var isSelected: Bool {
return hostsManager.isThemeSelected(theme)
}
var body: some View {
let padding: CGFloat = 10
let innerPadding: CGFloat = 5
let outerR: CGFloat = 15
var paletteR: CGFloat {
outerR-padding
}
var selectionR: CGFloat {
outerR-innerPadding
}
ZStack(alignment: .center) {
Rectangle()
.fill(Color.accentColor)
.opacity(isSelected ? 1 : 0)
Rectangle()
.fill(theme.background.suiColor)
.clipShape(
RoundedRectangle(
cornerRadius: isSelected ? selectionR : 0
)
)
.padding(isSelected ? innerPadding : 0)
ThemePreview(theme: theme, padding: padding, paletteR: paletteR)
}
.onTapGesture {
hostsManager.selectTheme(theme)
}
.animation(.spring, value: isSelected)
.clipShape(RoundedRectangle(cornerRadius: outerR))
.contextMenu {
if canModify {
NavigationLink {
ThemeEditorView(hostsManager: hostsManager, theme: $theme)
} label: {
Label("Edit", systemImage: "pencil")
}
Button() {
rename = theme.name
showRenameAlert.toggle()
} label: {
Label("Rename", systemImage: "text.cursor")
}
Button(role: .destructive) {
hostsManager.deleteTheme(theme)
} label: {
Label("Delete", systemImage: "trash")
}
}
}
.alert("Rename \(theme.name)", isPresented: $showRenameAlert) {
TextField("", text: $rename)
Button("OK") {
hostsManager.renameTheme(theme, to: rename)
rename = ""
}
}
}
}
#Preview {
ThemeButton(
hostsManager: HostsManager(),
theme: .constant(Theme.defaultTheme),
canModify: true
)
.border(Color.red)
}
+42 -39
View File
@@ -16,52 +16,55 @@ struct ThemeEditorView: View {
@Environment(\.dismiss) var dismiss
var body: some View {
NavigationStack {
List {
ZStack {
hostsManager.selectedTheme.background.suiColor.opacity(0.7)
.ignoresSafeArea(.all)
NavigationStack {
ThemePreview(theme: theme, padding: 10, paletteR: 20)
.id(theme)
.padding(.bottom)
.fixedSize(horizontal: false, vertical: true)
Section("Preview") {
// ThemePreview(hostsManager: HostsManager(), theme: .constant(theme), canModify: false)
// .id(theme)
}
Section("Name") {
TextField("Name", text: $theme.name)
.textFieldStyle(.roundedBorder)
}
Section("Main Colors") {
List {
Section("Name") {
TextField("Name", text: $theme.name)
.textFieldStyle(.roundedBorder)
}
ColorPicker("Text", selection: $theme.foreground.suiColor, supportsOpacity: false)
ColorPicker("Background", selection: $theme.background.suiColor, supportsOpacity: false)
ColorPicker("Cursor", selection: $theme.cursor.suiColor, supportsOpacity: false)
ColorPicker("Cusor Text", selection: $theme.cursorText.suiColor, supportsOpacity: false)
ColorPicker("Bold Text", selection: $theme.bold.suiColor, supportsOpacity: false)
ColorPicker("Selection", selection: $theme.selection.suiColor, supportsOpacity: false)
ColorPicker("Selected Text", selection: $theme.selectedText.suiColor, supportsOpacity: false)
}
Section("Ansi Colors") {
ForEach(0...1, id: \.self) { row in
HStack {
Spacer()
ForEach(1...8, id: \.self) { col in
let index = (col + (row * 8)) - 1
ColorPicker("", selection: $theme.ansi[index].suiColor, supportsOpacity: false)
.labelsHidden()
Section("Main Colors") {
ColorPicker("Text", selection: $theme.foreground.suiColor, supportsOpacity: false)
ColorPicker("Background", selection: $theme.background.suiColor, supportsOpacity: false)
ColorPicker("Cursor", selection: $theme.cursor.suiColor, supportsOpacity: false)
ColorPicker("Cusor Text", selection: $theme.cursorText.suiColor, supportsOpacity: false)
ColorPicker("Bold Text", selection: $theme.bold.suiColor, supportsOpacity: false)
ColorPicker("Selection", selection: $theme.selection.suiColor, supportsOpacity: false)
ColorPicker("Selected Text", selection: $theme.selectedText.suiColor, supportsOpacity: false)
}
Section("Ansi Colors") {
ForEach(0...1, id: \.self) { row in
HStack {
Spacer()
ForEach(1...8, id: \.self) { col in
let index = (col + (row * 8)) - 1
ColorPicker("", selection: $theme.ansi[index].suiColor, supportsOpacity: false)
.labelsHidden()
Spacer()
}
}
}
}
}
}
.navigationTitle("Edit Theme")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
Button() {
hostsManager.updateTheme(theme)
dismiss()
} label: {
Label("Done", systemImage: "checkmark")
.navigationTitle("Edit Theme")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
Button() {
hostsManager.updateTheme(theme)
dismiss()
} label: {
Label("Done", systemImage: "checkmark")
}
}
}
}
+3 -2
View File
@@ -50,6 +50,7 @@ struct ThemeManagerView: View {
HStack {
Text("Your Themes")
.padding(.horizontal)
.padding(.vertical)
.font(.headline)
Spacer()
}
@@ -69,7 +70,7 @@ struct ThemeManagerView: View {
} else {
LazyVGrid(columns: layout, alignment: .center, spacing: 8) {
ForEach($hostsManager.themes) { $theme in
ThemePreview(hostsManager: hostsManager, theme: $theme, canModify: true)
ThemeButton(hostsManager: hostsManager, theme: $theme, canModify: true)
}
}
.padding(.horizontal)
@@ -85,7 +86,7 @@ struct ThemeManagerView: View {
}
LazyVGrid(columns: layout, alignment: .center, spacing: 8) {
ForEach(Theme.builtinThemes) { theme in
ThemePreview(hostsManager: hostsManager, theme: .constant(theme), canModify: false)
ThemeButton(hostsManager: hostsManager, theme: .constant(theme), canModify: false)
}
}
.padding(.horizontal)
+30 -97
View File
@@ -2,115 +2,48 @@
// ThemePreview.swift
// ShhShell
//
// Created by neon443 on 27/06/2025.
// Created by neon443 on 09/07/2025.
//
import SwiftUI
struct ThemePreview: View {
@ObservedObject var hostsManager: HostsManager
@Binding var theme: Theme
@State var canModify: Bool
@State var theme: Theme
@State var padding: CGFloat
@State var paletteR: CGFloat
@State private var showRenameAlert: Bool = false
@State private var rename: String = ""
var isSelected: Bool {
return hostsManager.isThemeSelected(theme)
}
var body: some View {
let padding: CGFloat = 10
let innerPadding: CGFloat = 5
let outerR: CGFloat = 15
var paletteR: CGFloat {
outerR-padding
}
var selectionR: CGFloat {
outerR-innerPadding
}
ZStack(alignment: .center) {
Rectangle()
.fill(Color.accentColor)
.opacity(isSelected ? 1 : 0)
Rectangle()
.fill(theme.background.suiColor)
.clipShape(
RoundedRectangle(
cornerRadius: isSelected ? selectionR : 0
)
)
.padding(isSelected ? innerPadding : 0)
VStack {
Text(theme.name)
.foregroundStyle(theme.foreground.suiColor)
.font(.headline)
.lineLimit(1)
Spacer()
VStack(spacing: 0) {
HStack(spacing: 0) {
ForEach(0..<8, id: \.self) { index in
Rectangle()
.aspectRatio(CGSize(width: 1, height: 1), contentMode: .fit)
.foregroundStyle(theme.ansi[index].suiColor)
}
}
HStack(spacing: 0) {
ForEach(8..<16, id: \.self) { index in
Rectangle()
.aspectRatio(CGSize(width: 1, height: 1), contentMode: .fit)
.foregroundStyle(theme.ansi[index].suiColor)
}
var body: some View {
VStack {
Text(theme.name)
.foregroundStyle(theme.foreground.suiColor)
.font(.headline)
.lineLimit(1)
Spacer()
VStack(spacing: 0) {
HStack(spacing: 0) {
ForEach(0..<8, id: \.self) { index in
Rectangle()
.aspectRatio(CGSize(width: 1, height: 1), contentMode: .fit)
.foregroundStyle(theme.ansi[index].suiColor)
}
}
.clipShape(RoundedRectangle(cornerRadius: paletteR))
}
.padding(padding)
}
.onTapGesture {
hostsManager.selectTheme(theme)
}
.animation(.spring, value: isSelected)
.clipShape(RoundedRectangle(cornerRadius: outerR))
.contextMenu {
if canModify {
NavigationLink {
ThemeEditorView(hostsManager: hostsManager, theme: $theme)
} label: {
Label("Edit", systemImage: "pencil")
}
Button() {
rename = theme.name
showRenameAlert.toggle()
} label: {
Label("Rename", systemImage: "text.cursor")
}
Button(role: .destructive) {
hostsManager.deleteTheme(theme)
} label: {
Label("Delete", systemImage: "trash")
HStack(spacing: 0) {
ForEach(8..<16, id: \.self) { index in
Rectangle()
.aspectRatio(CGSize(width: 1, height: 1), contentMode: .fit)
.foregroundStyle(theme.ansi[index].suiColor)
}
}
}
.clipShape(RoundedRectangle(cornerRadius: paletteR))
}
.alert("Rename \(theme.name)", isPresented: $showRenameAlert) {
TextField("", text: $rename)
Button("OK") {
hostsManager.renameTheme(theme, to: rename)
rename = ""
}
}
}
.padding(padding)
}
}
#Preview {
ThemePreview(
hostsManager: HostsManager(),
theme: .constant(Theme.defaultTheme),
canModify: true
)
.border(Color.red)
ThemePreview(theme: Theme.defaultTheme, padding: 5, paletteR: 10)
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.