Refactor project structure and API
This commit is contained in:
47
Views/Cells/InfoCell.swift
Normal file
47
Views/Cells/InfoCell.swift
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// InfoBarCell.swift
|
||||
// iKeyMon
|
||||
//
|
||||
// Created by tracer on 03.04.25.
|
||||
//
|
||||
|
||||
//
|
||||
// ResourcesBarRow.swift
|
||||
// iKeyMon
|
||||
//
|
||||
// Created by tracer on 31.03.25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct InfoCell: View {
|
||||
var value: [String]
|
||||
var monospaced: Bool = false
|
||||
var color: Color = .primary
|
||||
|
||||
init(value: [String], monospaced: Bool = false) {
|
||||
self.value = value
|
||||
self.monospaced = monospaced
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
ForEach(value, id: \.self) { item in
|
||||
Text(item)
|
||||
.font(monospaced ? .system(.body, design: .monospaced) : .body)
|
||||
}
|
||||
}
|
||||
// if let subtext {
|
||||
// Text(subtext)
|
||||
// .font(.caption)
|
||||
// .foregroundColor(.secondary)
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
InfoCell(value: ["Some Text", "Another Text"])
|
||||
}
|
||||
|
||||
37
Views/Cells/LoadBarCell.swift
Normal file
37
Views/Cells/LoadBarCell.swift
Normal file
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// ResourcesBarRow.swift
|
||||
// iKeyMon
|
||||
//
|
||||
// Created by tracer on 31.03.25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct LoadBarCell: View {
|
||||
let percent: Double
|
||||
let load1: Double
|
||||
let load5: Double
|
||||
let load15: Double
|
||||
var subtext: String? = nil
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
Text(String(format: "%.2f%%", percent))
|
||||
.foregroundColor(.green)
|
||||
Text(String(format: "(%.2f / %.2f / %.2f)", load1, load5, load15))
|
||||
}
|
||||
if let subtext {
|
||||
Text(subtext)
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
ProgressView(value: percent / 100)
|
||||
.progressViewStyle(.linear)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
LoadBarCell(percent: 2.34, load1: 1.23, load5: 0.08, load15: 0.06)
|
||||
}
|
||||
50
Views/Cells/UsageBarCell.swift
Normal file
50
Views/Cells/UsageBarCell.swift
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// UsageBarCell.swift
|
||||
// iKeyMon
|
||||
//
|
||||
// Created by tracer on 01.04.25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct UsageBarCell: View {
|
||||
let free: Int
|
||||
let used: Int
|
||||
let total: Int
|
||||
let percent: Double
|
||||
var subtext: String? = nil
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
Text("Free:")
|
||||
.fontWeight(.bold)
|
||||
Text(free.toNiceBinaryUnit())
|
||||
|
||||
Text("Used:")
|
||||
.fontWeight(.bold)
|
||||
Text(used.toNiceBinaryUnit())
|
||||
|
||||
Text("Total:")
|
||||
.fontWeight(.bold)
|
||||
Text(total.toNiceBinaryUnit())
|
||||
|
||||
}
|
||||
if let subtext {
|
||||
Text(subtext)
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
HStack {
|
||||
Spacer()
|
||||
Text(String(format: "%.2f %%", percent))
|
||||
}
|
||||
ProgressView(value: percent / 100)
|
||||
.progressViewStyle(.linear)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
UsageBarCell(free: 1024, used: 16238, total: 1232312323123, percent: 33.33)
|
||||
}
|
||||
Reference in New Issue
Block a user