Skip to content

Commit

Permalink
Merge pull request #10 from morishin/configurable-column-width
Browse files Browse the repository at this point in the history
Make configurable column width
  • Loading branch information
morishin authored Jan 24, 2024
2 parents 7c3948d + 5de36a6 commit 7ca3ee0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions XDeck/Config/AppConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum AppConfigError: Error {
}

struct AppConfig: Decodable {
var columnWidth: Int?
var columns: [Column]

struct Column: Decodable {
Expand Down
3 changes: 3 additions & 0 deletions XDeck/Config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"$schema": {
"type": "string"
},
"columnWidth": {
"type": "integer"
},
"columns": {
"type": "array",
"items": {
Expand Down
1 change: 1 addition & 0 deletions XDeck/Config/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"$schema": "./schema.json",
"columnWidth": 380,
"columns": [
{
"type": "forYou"
Expand Down
11 changes: 8 additions & 3 deletions XDeck/View/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct ContentView: View {
@State var isShowingAlert: Bool = false
@State var alertMessage: String? = nil
@State var backgroundColor: Color = .white
@State var columnWidth: CGFloat = 380
@State var columnWidth: CGFloat
@State var refreshSwitch: Bool = false
@State var scriptExecutionRequest: String? = nil
@State var isShowConfirmOpenPreference: Bool = false
Expand Down Expand Up @@ -47,6 +47,11 @@ struct ContentView: View {
"""
}

init(appConfig: AppConfig) {
self.appConfig = appConfig
self._columnWidth = State<CGFloat>(initialValue: appConfig.columnWidth.map(CGFloat.init) ?? Self.defaultColumnWidth)
}

@ViewBuilder
private func makeColumn(
column: AppConfig.Column, isLeftMostXColumn: Bool, profileUrl: Binding<URL?>
Expand Down Expand Up @@ -121,11 +126,11 @@ struct ContentView: View {
ZStack {
Button("+") {
pageZoom = pageZoom + 0.2
columnWidth = Self.defaultColumnWidth * pageZoom
columnWidth = (appConfig.columnWidth.map(CGFloat.init) ?? Self.defaultColumnWidth) * pageZoom
}.keyboardShortcut("+").opacity(0)
Button("-") {
pageZoom = pageZoom - 0.2
columnWidth = Self.defaultColumnWidth * pageZoom
columnWidth = (appConfig.columnWidth.map(CGFloat.init) ?? Self.defaultColumnWidth) * pageZoom
}.keyboardShortcut("-").opacity(0)
Button("r") {
refreshSwitch = !refreshSwitch
Expand Down

0 comments on commit 7ca3ee0

Please sign in to comment.