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

Commit840df63

Browse files
committed
extract
1 parente9ddfbc commit840df63

File tree

3 files changed

+96
-94
lines changed

3 files changed

+96
-94
lines changed

‎Desktop/AgentRow.swift

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import SwiftUI
2+
3+
structAgentRow:Identifiable{
4+
letid:UUID
5+
letname:String
6+
letstatus:Color
7+
letcopyableDNS:String
8+
}
9+
10+
structAgentRowView:View{
11+
letworkspace:AgentRow
12+
@StateprivatevarnameIsSelected:Bool=false
13+
@StateprivatevarcopyIsSelected:Bool=false
14+
15+
privatevarfmtWsName:AttributedString{
16+
varformattedName=AttributedString(workspace.name)
17+
formattedName.foregroundColor=.primary
18+
varcoderPart=AttributedString(".coder")
19+
coderPart.foregroundColor=.gray
20+
formattedName.append(coderPart)
21+
return formattedName
22+
}
23+
24+
varbody:someView{
25+
HStack(spacing:0){
26+
Button{
27+
// TODO: Action
28+
} label:{
29+
HStack(spacing:10){
30+
ZStack{
31+
Circle()
32+
.fill(workspace.status.opacity(0.4))
33+
.frame(width:12, height:12)
34+
Circle()
35+
.fill(workspace.status.opacity(1.0))
36+
.frame(width:7, height:7)
37+
}
38+
Text(fmtWsName).lineLimit(1).truncationMode(.tail)
39+
Spacer()
40+
}.padding(.horizontal,10)
41+
.frame(minHeight:22)
42+
.frame(maxWidth:.infinity, alignment:.leading)
43+
.foregroundStyle(nameIsSelected?Color.white:.primary)
44+
.background(nameIsSelected?Color.accentColor.opacity(0.8):.clear)
45+
.clipShape(.rect(cornerRadius:4))
46+
.onHover{ hoveringin nameIsSelected= hovering}
47+
Spacer()
48+
}.buttonStyle(.plain)
49+
Button{
50+
// TODO: Proper clipboard abstraction
51+
NSPasteboard.general.setString(workspace.copyableDNS, forType:.string)
52+
} label:{
53+
Image(systemName:"doc.on.doc")
54+
.symbolVariant(.fill)
55+
.padding(3)
56+
}.foregroundStyle(copyIsSelected?Color.white:.primary)
57+
.imageScale(.small)
58+
.background(copyIsSelected?Color.accentColor.opacity(0.8):.clear)
59+
.clipShape(.rect(cornerRadius:4))
60+
.onHover{ hoveringin copyIsSelected= hovering}
61+
.buttonStyle(.plain)
62+
.padding(.trailing,5)
63+
}
64+
}
65+
}

‎Desktop/ButtonRow.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import SwiftUI
2+
3+
structButtonRowView<Label:View>:View{
4+
@StateprivatevarisSelected:Bool=false
5+
@ViewBuildervarlabel:()->Label
6+
varaction:()->Void
7+
8+
varbody:someView{
9+
Button{
10+
action()
11+
} label:{
12+
HStack(spacing:0){
13+
label()
14+
Spacer()
15+
}
16+
.padding(.horizontal,10)
17+
.frame(minHeight:22)
18+
.frame(maxWidth:.infinity, alignment:.leading)
19+
.foregroundStyle(isSelected?Color.white:.primary)
20+
.background(isSelected?Color.accentColor.opacity(0.8):.clear)
21+
.clipShape(.rect(cornerRadius:4))
22+
.onHover{ hoveringin isSelected= hovering}
23+
}.buttonStyle(.plain)
24+
}
25+
}

‎Desktop/VPNMenu.swift

Lines changed: 6 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import SwiftUI
22

3-
structVPNMenu<Conn:CoderVPN>:View{
4-
@ObservedObjectvarvpnService:Conn
3+
structVPNMenu<VPN:CoderVPN>:View{
4+
@ObservedObjectvarvpnService:VPN
55

66
varbody:someView{
77
// Main stack
@@ -45,24 +45,24 @@ struct VPNMenu<Conn: CoderVPN>: View {
4545
// Trailing stack
4646
VStack(alignment:.leading, spacing:3){
4747
Divider().padding([.horizontal],10).padding(.vertical,4)
48-
RowButtonView{
48+
ButtonRowView{
4949
Text("Create workspace")
5050
EmptyView()
5151
} action:{
5252
// TODO
5353
}
5454
Divider().padding([.horizontal],10).padding(.vertical,4)
55-
RowButtonView{
55+
ButtonRowView{
5656
Text("About")
5757
} action:{
5858
// TODO
5959
}
60-
RowButtonView{
60+
ButtonRowView{
6161
Text("Preferences")
6262
} action:{
6363
// TODO
6464
}
65-
RowButtonView{
65+
ButtonRowView{
6666
Text("Sign out")
6767
} action:{
6868
// TODO
@@ -72,94 +72,6 @@ struct VPNMenu<Conn: CoderVPN>: View {
7272
}
7373
}
7474

75-
structAgentRow:Identifiable{
76-
letid:UUID
77-
letname:String
78-
letstatus:Color
79-
letcopyableDNS:String
80-
}
81-
82-
structAgentRowView:View{
83-
letworkspace:AgentRow
84-
@StateprivatevarnameIsSelected:Bool=false
85-
@StateprivatevarcopyIsSelected:Bool=false
86-
87-
privatevarfmtWsName:AttributedString{
88-
varformattedName=AttributedString(workspace.name)
89-
formattedName.foregroundColor=.primary
90-
varcoderPart=AttributedString(".coder")
91-
coderPart.foregroundColor=.gray
92-
formattedName.append(coderPart)
93-
return formattedName
94-
}
95-
96-
varbody:someView{
97-
HStack(spacing:0){
98-
Button{
99-
// TODO: Action
100-
} label:{
101-
HStack(spacing:10){
102-
ZStack{
103-
Circle()
104-
.fill(workspace.status.opacity(0.4))
105-
.frame(width:12, height:12)
106-
Circle()
107-
.fill(workspace.status.opacity(1.0))
108-
.frame(width:7, height:7)
109-
}
110-
Text(fmtWsName).lineLimit(1).truncationMode(.tail)
111-
Spacer()
112-
}.padding(.horizontal,10)
113-
.frame(minHeight:22)
114-
.frame(maxWidth:.infinity, alignment:.leading)
115-
.foregroundStyle(nameIsSelected?Color.white:.primary)
116-
.background(nameIsSelected?Color.accentColor.opacity(0.8):.clear)
117-
.clipShape(.rect(cornerRadius:4))
118-
.onHover{ hoveringin nameIsSelected= hovering}
119-
Spacer()
120-
}.buttonStyle(.plain)
121-
Button{
122-
// TODO: Proper clipboard abstraction
123-
NSPasteboard.general.setString(workspace.copyableDNS, forType:.string)
124-
} label:{
125-
Image(systemName:"doc.on.doc")
126-
.symbolVariant(.fill)
127-
.padding(3)
128-
}.foregroundStyle(copyIsSelected?Color.white:.primary)
129-
.imageScale(.small)
130-
.background(copyIsSelected?Color.accentColor.opacity(0.8):.clear)
131-
.clipShape(.rect(cornerRadius:4))
132-
.onHover{ hoveringin copyIsSelected= hovering}
133-
.buttonStyle(.plain)
134-
.padding(.trailing,5)
135-
}
136-
}
137-
}
138-
139-
structRowButtonView<Label:View>:View{
140-
@StateprivatevarisSelected:Bool=false
141-
@ViewBuildervarlabel:()->Label
142-
varaction:()->Void
143-
144-
varbody:someView{
145-
Button{
146-
action()
147-
} label:{
148-
HStack(spacing:0){
149-
label()
150-
Spacer()
151-
}
152-
.padding(.horizontal,10)
153-
.frame(minHeight:22)
154-
.frame(maxWidth:.infinity, alignment:.leading)
155-
.foregroundStyle(isSelected?Color.white:.primary)
156-
.background(isSelected?Color.accentColor.opacity(0.8):.clear)
157-
.clipShape(.rect(cornerRadius:4))
158-
.onHover{ hoveringin isSelected= hovering}
159-
}.buttonStyle(.plain)
160-
}
161-
}
162-
16375
#Preview{
16476
VPNMenu(vpnService:PreviewVPN()).frame(width:256)
16577
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp