From 94b6a3fe45001e9e0a20bde23e81971011ef05db Mon Sep 17 00:00:00 2001 From: mrFq1 <1xxbx0il0@mozmail.com> Date: Mon, 29 May 2023 20:31:32 +0800 Subject: [PATCH] feat: overview items count --- .../ContentTabs/Overview/OverviewView.swift | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/ClashX Dashboard/Views/ContentTabs/Overview/OverviewView.swift b/ClashX Dashboard/Views/ContentTabs/Overview/OverviewView.swift index 60d48e1..abb0e3d 100644 --- a/ClashX Dashboard/Views/ContentTabs/Overview/OverviewView.swift +++ b/ClashX Dashboard/Views/ContentTabs/Overview/OverviewView.swift @@ -11,14 +11,14 @@ struct OverviewView: View { @EnvironmentObject var data: ClashOverviewData - + @State private var columnCount: Int = 4 var body: some View { 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: "Download", value: $data.downloadString) @@ -28,6 +28,20 @@ struct OverviewView: View { OverviewTopItemView(name: "Active Connections", value: $data.activeConns) 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() + } @@ -53,6 +67,15 @@ struct OverviewView: View { }.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 {