mirror of
https://github.com/yJason/ClashX-Dashboard.git
synced 2026-02-04 10:02:26 +08:00
78 lines
1.5 KiB
Swift
78 lines
1.5 KiB
Swift
//
|
|
// RuleItemView.swift
|
|
// ClashX Dashboard
|
|
//
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct RuleItemView: View {
|
|
@State var index: Int
|
|
@State var rule: ClashRule
|
|
|
|
var body: some View {
|
|
HStack(alignment: .center, spacing: 12) {
|
|
Text("\(index)")
|
|
.font(.system(size: 16))
|
|
.foregroundColor(.secondary)
|
|
.frame(width: 30)
|
|
|
|
VStack(alignment: .leading) {
|
|
HStack(alignment: .bottom, spacing: 18) {
|
|
if let payload = rule.payload,
|
|
payload != "" {
|
|
Text(rule.payload!)
|
|
.font(.system(size: 14))
|
|
}
|
|
|
|
if rule.size > 0 {
|
|
Text("size: \(rule.size)")
|
|
.font(.system(size: 12))
|
|
.foregroundColor(.secondary)
|
|
}
|
|
}
|
|
|
|
HStack {
|
|
Text(rule.type)
|
|
.foregroundColor(.secondary)
|
|
.frame(width: 120, alignment: .leading)
|
|
|
|
Text(rule.proxy ?? "")
|
|
.foregroundColor({
|
|
switch rule.proxy {
|
|
case "DIRECT":
|
|
return .orange
|
|
case "REJECT":
|
|
return .red
|
|
default:
|
|
return .blue
|
|
}
|
|
}())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
struct RulesRowView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
RuleItemView(index: 114, rule: .init(type: "DIRECT", payload: "cn", proxy: "GeoSite"))
|
|
}
|
|
}
|
|
|
|
|
|
extension HorizontalAlignment {
|
|
|
|
private struct RuleItemOBAlignment: AlignmentID {
|
|
static func defaultValue(in context: ViewDimensions) -> CGFloat {
|
|
context[.leading]
|
|
}
|
|
}
|
|
|
|
static let ruleItemOBAlignmentGuide = HorizontalAlignment(
|
|
RuleItemOBAlignment.self
|
|
)
|
|
}
|