Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit74a7609

Browse files
committed
feat: added text alignment for Stack widget (#2463)
1 parent7ddcb4c commit74a7609

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

‎Kit/Widgets/Stack.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class StackWidget: WidgetWrapper {
3030
privatevarmodeState:StackMode=.auto
3131
privatevarfixedSizeState:Bool=false
3232
privatevarmonospacedFontState:Bool=false
33+
privatevaralignmentState:String="left"
3334

3435
privatevarvalues:[Stack_t]=[]
3536

@@ -38,6 +39,13 @@ public class StackWidget: WidgetWrapper {
3839

3940
privateletorderTableView:OrderTableView
4041

42+
privatevaralignment:NSTextAlignment{
43+
iflet alignmentPair=Alignments.first(where:{ $0.key==self.alignmentState}){
44+
return alignmentPair.additionalas?NSTextAlignment??.left
45+
}
46+
return.left
47+
}
48+
4149
publicinit(title:String, config:NSDictionary?, preview:Bool=false){
4250
iflet config, preview{
4351
iflet previewConfig=config["Preview"]as?NSDictionary{
@@ -62,6 +70,7 @@ public class StackWidget: WidgetWrapper {
6270
self.modeState=StackMode(rawValue:Store.shared.string(key:"\(self.title)_\(self.type.rawValue)_mode", defaultValue:self.modeState.rawValue))??.auto
6371
self.fixedSizeState=Store.shared.bool(key:"\(self.title)_\(self.type.rawValue)_size", defaultValue:self.fixedSizeState)
6472
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)
6574
}
6675

6776
self.orderTableView.reorderCallback={[weak self]in
@@ -136,7 +145,7 @@ public class StackWidget: WidgetWrapper {
136145
}
137146

138147
letstyle=NSMutableParagraphStyle()
139-
style.alignment=.center
148+
style.alignment=self.alignment
140149

141150
varwidth:CGFloat=self.oneRowWidth
142151
if !self.fixedSizeState{
@@ -164,7 +173,7 @@ public class StackWidget: WidgetWrapper {
164173
font=NSFont.systemFont(ofSize:10, weight:.light)
165174
}
166175
letstyle=NSMutableParagraphStyle()
167-
style.alignment=.right
176+
style.alignment=self.alignment
168177

169178
letattributes=[
170179
NSAttributedString.Key.font: font,
@@ -232,6 +241,11 @@ public class StackWidget: WidgetWrapper {
232241
PreferencesRow(localizedString("Monospaced font"), component:switchView(
233242
action: #selector(self.toggleMonospacedFont),
234243
state:self.monospacedFontState
244+
)),
245+
PreferencesRow(localizedString("Alignment"), component:selectView(
246+
action: #selector(self.toggleAlignment),
247+
items: Alignments,
248+
selected:self.alignmentState
235249
))
236250
]
237251
ifself.title!="Clock"{
@@ -265,6 +279,15 @@ public class StackWidget: WidgetWrapper {
265279
Store.shared.set(key:"\(self.title)_\(self.type.rawValue)_monospacedFont", value:self.monospacedFontState)
266280
self.display()
267281
}
282+
283+
@objcprivatefunc toggleAlignment(_ sender:NSMenuItem){
284+
guardlet key= sender.representedObjectas?Stringelse{return}
285+
iflet 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+
}
268291
}
269292

270293
privateclassOrderTableView:NSView,NSTableViewDelegate,NSTableViewDataSource{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp