Skip to content

Commit

Permalink
Fix textfield style
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-ludwig committed Sep 2, 2024
1 parent 851f940 commit c5b6c1e
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 67 deletions.
4 changes: 4 additions & 0 deletions CodeEdit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@
617DB3DA2C25B07F00B58BFE /* TaskNotificationsDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 617DB3D92C25B07F00B58BFE /* TaskNotificationsDetailView.swift */; };
617DB3DC2C25B14A00B58BFE /* ActivityViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 617DB3DB2C25B14A00B58BFE /* ActivityViewer.swift */; };
617DB3DF2C25E13800B58BFE /* TaskNotificationHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 617DB3DE2C25E13800B58BFE /* TaskNotificationHandlerTests.swift */; };
61816B832C81DC2C00C71BF7 /* ThemeSearchField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61816B822C81DC2C00C71BF7 /* ThemeSearchField.swift */; };
618725A12C29EFCC00987354 /* SchemeDropDownView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618725A02C29EFCC00987354 /* SchemeDropDownView.swift */; };
618725A42C29F00400987354 /* WorkspaceMenuItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618725A32C29F00400987354 /* WorkspaceMenuItemView.swift */; };
618725A62C29F02500987354 /* DropdownMenuItemStyleModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618725A52C29F02500987354 /* DropdownMenuItemStyleModifier.swift */; };
Expand Down Expand Up @@ -978,6 +979,7 @@
617DB3D92C25B07F00B58BFE /* TaskNotificationsDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskNotificationsDetailView.swift; sourceTree = "<group>"; };
617DB3DB2C25B14A00B58BFE /* ActivityViewer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityViewer.swift; sourceTree = "<group>"; };
617DB3DE2C25E13800B58BFE /* TaskNotificationHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskNotificationHandlerTests.swift; sourceTree = "<group>"; };
61816B822C81DC2C00C71BF7 /* ThemeSearchField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeSearchField.swift; sourceTree = "<group>"; };
618725A02C29EFCC00987354 /* SchemeDropDownView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SchemeDropDownView.swift; sourceTree = "<group>"; };
618725A32C29F00400987354 /* WorkspaceMenuItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceMenuItemView.swift; sourceTree = "<group>"; };
618725A52C29F02500987354 /* DropdownMenuItemStyleModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropdownMenuItemStyleModifier.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2469,6 +2471,7 @@
children = (
B6F0518D29DA29F900D72287 /* Models */,
58F2EAAF292FB2B0004A9BDE /* ThemeSettingsView.swift */,
61816B822C81DC2C00C71BF7 /* ThemeSearchField.swift */,
B6EA1FF729DB78DB001BF195 /* ThemeSettingThemeRow.swift */,
B6EA1FFA29DB78F6001BF195 /* ThemeSettingsThemeDetails.swift */,
B6EA1FFC29DB792C001BF195 /* ThemeSettingsColorPreview.swift */,
Expand Down Expand Up @@ -4252,6 +4255,7 @@
6C97EBCC2978760400302F95 /* AcknowledgementsWindowController.swift in Sources */,
284DC84F2978B7B400BF2770 /* ContributorsView.swift in Sources */,
B62AEDC92A2704F3009A9F52 /* UtilityAreaTabView.swift in Sources */,
61816B832C81DC2C00C71BF7 /* ThemeSearchField.swift in Sources */,
30B088052C0D53080063A882 /* LanguageServer+DocumentLink.swift in Sources */,
58798250292E78D80085B254 /* CodeFileDocument.swift in Sources */,
5878DAA5291AE76700DD95A3 /* OpenQuicklyView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// ThemeSearchField.swift
// CodeEdit
//
// Created by Tommy Ludwig on 30.08.24.
//

import SwiftUI

struct ThemeSearchField: View {
@Binding var themeSearchQuery: String
var body: some View {
VStack {
HStack(alignment: .top) {
Image(systemName: "magnifyingglass")
.padding(.leading, 2)
.padding(.trailing, -7)

TextField("", text: $themeSearchQuery)
.textFieldStyle(PlainTextFieldStyle())
.multilineTextAlignment(.leading)
.overlay {
HStack {
Text("Search")
.foregroundStyle(.secondary)
.opacity(themeSearchQuery.isEmpty ? 1 : 0)
.padding(.leading, 6.5)

Spacer()
}
}
}
.padding(3)
.overlay(
RoundedRectangle(cornerRadius: 5)
.foregroundStyle(.secondary)
// .blendMode(.overlay)
.blendMode(.difference)
.opacity(0.1)
)
.overlay {
RoundedRectangle(cornerRadius: 5)
.stroke(Color.gray, lineWidth: 1)
.foregroundStyle(.secondary)
.opacity(0.2)
}
// TextField(text: $themeSearchQuery, prompt: Text("Search")) {
// Label("Test", systemImage: "magnifyingglass")
// }
// .textFieldStyle(.roundedBorder)
// .padding()
}
}
}

#Preview {
ThemeSearchField(themeSearchQuery: .constant("Test"))
}
162 changes: 95 additions & 67 deletions CodeEdit/Features/Settings/Pages/ThemeSettings/ThemeSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,85 +22,113 @@ struct ThemeSettingsView: View {
@State private var filteredThemes: [Theme] = []

var body: some View {
SettingsForm {
Section {
changeThemeOnSystemAppearance
if settings.matchAppearance {
alwaysUseDarkTerminalAppearance
}
useThemeBackground
}
Section {
VStack(spacing: 0) {
HStack {
TextField("Search Themes", text: $themeSearchQuery)
.textFieldStyle(.roundedBorder)
VStack {
Form {
Form {
Section {
HStack {
ThemeSearchField(themeSearchQuery: $themeSearchQuery)

Button {

Button {
withAnimation {
themeModel.selectedAppearance = themeModel.selectedAppearance == .dark ? .light : .dark
} label: {
Image(systemName: "plus")
}

Button {

} label: {
Image(systemName: "ellipsis")
}
} label: {
// Image(systemName: "arrow.up.arrow.down")
// .rotationEffect(.degrees(themeModel.selectedAppearance == .dark ? 0 : 180))
// .animation(.easeInOut, value: themeModel.selectedAppearance)
Image(
systemName: themeModel.selectedAppearance == .dark ?
"moon.circle.fill" : "sun.max.circle"
).font(.title2)
}
.buttonStyle(.icon)
}
.padding(10)
.padding(.leading, 10)
}
.formStyle(.columns)

VStack(spacing: 0) {
ForEach(filteredThemes) { theme in
Divider().padding(.horizontal, 10)
ThemeSettingsThemeRow(
theme: $themeModel.themes[themeModel.themes.firstIndex(of: theme)!],
active: themeModel.getThemeActive(theme)
).id(theme)
if themeSearchQuery.isEmpty {
Section {
changeThemeOnSystemAppearance
if settings.matchAppearance {
alwaysUseDarkTerminalAppearance
}
useThemeBackground
}
}
.padding(-10)
} footer: {
HStack {
Spacer()
Button("Import...") {
themeModel.importTheme()

Section {
VStack(spacing: 0) {
// HStack {
// TextField("Search Themes", text: $themeSearchQuery)
// .textFieldStyle(.roundedBorder)
//
// Button {
// withAnimation {
// themeModel.selectedAppearance = themeModel.selectedAppearance == .dark ? .light : .dark

Check failure on line 66 in CodeEdit/Features/Settings/Pages/ThemeSettings/ThemeSettingsView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Line should be 120 characters or less; currently it has 145 characters (line_length)
// }
// } label: {
//// Image(systemName: "arrow.up.arrow.down")
//// .rotationEffect(.degrees(themeModel.selectedAppearance == .dark ? 0 : 180))

Check failure on line 70 in CodeEdit/Features/Settings/Pages/ThemeSettings/ThemeSettingsView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Line should be 120 characters or less; currently it has 135 characters (line_length)
//// .animation(.easeInOut, value: themeModel.selectedAppearance)
// Image(
// systemName: themeModel.selectedAppearance == .dark ?
// "moon.circle.fill" : "sun.max.circle"
// ).font(.title2)
// }
// .buttonStyle(.icon)
// }
// .padding(10)
// .padding(.leading, 10)

VStack(spacing: 0) {
ForEach(filteredThemes) { theme in
Divider().padding(.horizontal, 10)
ThemeSettingsThemeRow(
theme: $themeModel.themes[themeModel.themes.firstIndex(of: theme)!],
active: themeModel.getThemeActive(theme)
).id(theme)
}
}
}
}
.padding(.top, 10)
}
}
.sheet(item: $themeModel.detailsTheme) {
themeModel.isAdding = false
} content: { theme in
if let index = themeModel.themes.firstIndex(where: {
$0.fileURL?.absoluteString == theme.fileURL?.absoluteString
}) {
ThemeSettingsThemeDetails(theme: Binding(
get: { themeModel.themes[index] },
set: { newValue in
themeModel.themes[index] = newValue
themeModel.save(newValue)
if settings.selectedTheme == theme.name {
themeModel.activateTheme(newValue)
.padding(-10)
} footer: {
HStack {
Spacer()
Button("Import...") {
themeModel.importTheme()
}
}
))
.padding(.top, 10)
}
.sheet(item: $themeModel.detailsTheme) {
themeModel.isAdding = false
} content: { theme in
if let index = themeModel.themes.firstIndex(where: {
$0.fileURL?.absoluteString == theme.fileURL?.absoluteString
}) {
ThemeSettingsThemeDetails(theme: Binding(
get: { themeModel.themes[index] },
set: { newValue in
themeModel.themes[index] = newValue
themeModel.save(newValue)
if settings.selectedTheme == theme.name {
themeModel.activateTheme(newValue)
}
}
))
}
}
.onAppear {
updateFilteredThemes()
}
.onChange(of: themeSearchQuery) { _ in
updateFilteredThemes()
}
.onChange(of: themeModel.selectedAppearance) { _ in
updateFilteredThemes()
}

}
}
.onAppear {
updateFilteredThemes()
}
.onChange(of: themeSearchQuery) { _ in
updateFilteredThemes()
}
.onChange(of: themeModel.selectedAppearance) { _ in
updateFilteredThemes()
.formStyle(.grouped)
}
}

Expand Down

0 comments on commit c5b6c1e

Please sign in to comment.