@@ -30,6 +30,7 @@ public class StackWidget: WidgetWrapper {
30
30
private var modeState : StackMode = . auto
31
31
private var fixedSizeState : Bool = false
32
32
private var monospacedFontState : Bool = false
33
+ private var alignmentState : String = " left "
33
34
34
35
private var values : [ Stack_t ] = [ ]
35
36
@@ -38,6 +39,13 @@ public class StackWidget: WidgetWrapper {
38
39
39
40
private let orderTableView : OrderTableView
40
41
42
+ private var alignment : NSTextAlignment {
43
+ if let alignmentPair= Alignments . first ( where: { $0. key== self . alignmentState} ) {
44
+ return alignmentPair. additionalas? NSTextAlignment ?? . left
45
+ }
46
+ return . left
47
+ }
48
+
41
49
public init ( title: String , config: NSDictionary ? , preview: Bool = false ) {
42
50
if let config, preview{
43
51
if let previewConfig= config [ " Preview " ] as? NSDictionary {
@@ -62,6 +70,7 @@ public class StackWidget: WidgetWrapper {
62
70
self . modeState= StackMode ( rawValue: Store . shared. string ( key: " \( self . title) _ \( self . type. rawValue) _mode " , defaultValue: self . modeState. rawValue) ) ?? . auto
63
71
self . fixedSizeState= Store . shared. bool ( key: " \( self . title) _ \( self . type. rawValue) _size " , defaultValue: self . fixedSizeState)
64
72
self . monospacedFontState= Store . shared. bool ( key: " \( self . title) _ \( self . type. rawValue) _monospacedFont " , defaultValue: self . monospacedFontState)
73
+ self . alignmentState= Store . shared. string ( key: " \( self . title) _ \( self . type. rawValue) _alignment " , defaultValue: self . alignmentState)
65
74
}
66
75
67
76
self . orderTableView. reorderCallback= { [ weak self] in
@@ -136,7 +145,7 @@ public class StackWidget: WidgetWrapper {
136
145
}
137
146
138
147
let style = NSMutableParagraphStyle ( )
139
- style. alignment= . center
148
+ style. alignment= self . alignment
140
149
141
150
var width : CGFloat = self . oneRowWidth
142
151
if !self . fixedSizeState{
@@ -164,7 +173,7 @@ public class StackWidget: WidgetWrapper {
164
173
font= NSFont . systemFont ( ofSize: 10 , weight: . light)
165
174
}
166
175
let style = NSMutableParagraphStyle ( )
167
- style. alignment= . right
176
+ style. alignment= self . alignment
168
177
169
178
let attributes = [
170
179
NSAttributedString . Key. font: font,
@@ -232,6 +241,11 @@ public class StackWidget: WidgetWrapper {
232
241
PreferencesRow ( localizedString ( " Monospaced font " ) , component: switchView (
233
242
action: #selector( self . toggleMonospacedFont) ,
234
243
state: self . monospacedFontState
244
+ ) ) ,
245
+ PreferencesRow ( localizedString ( " Alignment " ) , component: selectView (
246
+ action: #selector( self . toggleAlignment) ,
247
+ items: Alignments,
248
+ selected: self . alignmentState
235
249
) )
236
250
]
237
251
if self . title!= " Clock " {
@@ -265,6 +279,15 @@ public class StackWidget: WidgetWrapper {
265
279
Store . shared. set ( key: " \( self . title) _ \( self . type. rawValue) _monospacedFont " , value: self . monospacedFontState)
266
280
self . display ( )
267
281
}
282
+
283
+ @objc private func toggleAlignment( _ sender: NSMenuItem ) {
284
+ guard let key= sender. representedObjectas? String else { return }
285
+ if let newAlignment= Alignments . first ( where: { $0. key== key} ) {
286
+ self . alignmentState= newAlignment. key
287
+ }
288
+ Store . shared. set ( key: " \( self . title) _ \( self . type. rawValue) _alignment " , value: key)
289
+ self . display ( )
290
+ }
268
291
}
269
292
270
293
private class OrderTableView : NSView , NSTableViewDelegate , NSTableViewDataSource {