mirror of
https://github.com/yJason/ClashX-Dashboard.git
synced 2026-03-01 00:35:19 +08:00
feat: overview items count
This commit is contained in:
@@ -11,14 +11,14 @@ struct OverviewView: View {
|
|||||||
|
|
||||||
@EnvironmentObject var data: ClashOverviewData
|
@EnvironmentObject var data: ClashOverviewData
|
||||||
|
|
||||||
|
@State private var columnCount: Int = 4
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(spacing: 25) {
|
VStack(spacing: 25) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible(minimum: 155)), count: 4)) {
|
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: columnCount)) {
|
||||||
|
|
||||||
OverviewTopItemView(name: "Upload", value: $data.uploadString)
|
OverviewTopItemView(name: "Upload", value: $data.uploadString)
|
||||||
OverviewTopItemView(name: "Download", value: $data.downloadString)
|
OverviewTopItemView(name: "Download", value: $data.downloadString)
|
||||||
@@ -29,6 +29,20 @@ struct OverviewView: View {
|
|||||||
OverviewTopItemView(name: "Memory Usage", value: $data.memory)
|
OverviewTopItemView(name: "Memory Usage", value: $data.memory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.background {
|
||||||
|
GeometryReader { geometry in
|
||||||
|
Rectangle()
|
||||||
|
.fill(.clear)
|
||||||
|
.frame(height: 1)
|
||||||
|
.onChange(of: geometry.size.width) { newValue in
|
||||||
|
updateColumnCount(newValue)
|
||||||
|
}
|
||||||
|
.onAppear {
|
||||||
|
updateColumnCount(geometry.size.width)
|
||||||
|
}
|
||||||
|
}.padding()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
@@ -53,6 +67,15 @@ struct OverviewView: View {
|
|||||||
}.padding()
|
}.padding()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateColumnCount(_ width: Double) {
|
||||||
|
let v = Int(Int(width) / 155)
|
||||||
|
let new = v == 0 ? 1 : v
|
||||||
|
|
||||||
|
if new != columnCount {
|
||||||
|
columnCount = new
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//struct OverviewView_Previews: PreviewProvider {
|
//struct OverviewView_Previews: PreviewProvider {
|
||||||
|
|||||||
Reference in New Issue
Block a user