mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-30 20:49:23 +00:00
fix: sync download table header layout
This commit is contained in:
@@ -232,31 +232,28 @@ private struct DownloadTable: View {
|
|||||||
}
|
}
|
||||||
.padding(.horizontal, 12)
|
.padding(.horizontal, 12)
|
||||||
.padding(.vertical, 8)
|
.padding(.vertical, 8)
|
||||||
tableHeader
|
GeometryReader { proxy in
|
||||||
|
let tableWidth = max(totalWidth, proxy.size.width)
|
||||||
|
let trailingWidth = max(0, tableWidth - totalWidth)
|
||||||
|
|
||||||
|
ScrollView(.horizontal) {
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
tableHeader(trailingWidth: trailingWidth)
|
||||||
Divider()
|
Divider()
|
||||||
ScrollView([.horizontal, .vertical]) {
|
ScrollView(.vertical) {
|
||||||
LazyVStack(spacing: 0) {
|
LazyVStack(spacing: 0) {
|
||||||
ForEach(sortedItems) { item in
|
ForEach(sortedItems) { item in
|
||||||
DownloadRow(
|
tableRow(for: item, tableWidth: tableWidth, trailingWidth: trailingWidth)
|
||||||
item: item,
|
|
||||||
visibleColumns: orderedVisibleColumns,
|
|
||||||
columnWidth: { width(for: $0) }
|
|
||||||
)
|
|
||||||
.id(item.id)
|
|
||||||
.background(selection == item.id ? Color.accentColor.opacity(0.12) : Color.clear)
|
|
||||||
.contentShape(Rectangle())
|
|
||||||
.onTapGesture {
|
|
||||||
selection = item.id
|
|
||||||
}
|
|
||||||
.contextMenu {
|
|
||||||
rowContextMenu(for: item)
|
|
||||||
}
|
|
||||||
Divider()
|
Divider()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(minWidth: totalWidth, maxHeight: .infinity, alignment: .topLeading)
|
.frame(width: tableWidth, alignment: .topLeading)
|
||||||
|
.frame(maxHeight: .infinity, alignment: .topLeading)
|
||||||
}
|
}
|
||||||
.defaultScrollAnchor(.topLeading)
|
.defaultScrollAnchor(.topLeading)
|
||||||
|
}
|
||||||
|
.frame(width: tableWidth, height: proxy.size.height, alignment: .topLeading)
|
||||||
|
}
|
||||||
.overlay {
|
.overlay {
|
||||||
if items.isEmpty {
|
if items.isEmpty {
|
||||||
ContentUnavailableView(
|
ContentUnavailableView(
|
||||||
@@ -267,6 +264,7 @@ private struct DownloadTable: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
.confirmationDialog(
|
.confirmationDialog(
|
||||||
"Delete Download",
|
"Delete Download",
|
||||||
isPresented: Binding(
|
isPresented: Binding(
|
||||||
@@ -301,10 +299,28 @@ private struct DownloadTable: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var tableHeader: some View {
|
private func tableRow(for item: DownloadItem, tableWidth: CGFloat, trailingWidth: CGFloat) -> some View {
|
||||||
|
DownloadRow(
|
||||||
|
item: item,
|
||||||
|
visibleColumns: orderedVisibleColumns,
|
||||||
|
columnWidth: { width(for: $0) },
|
||||||
|
trailingWidth: trailingWidth
|
||||||
|
)
|
||||||
|
.id(item.id)
|
||||||
|
.frame(width: tableWidth, alignment: .leading)
|
||||||
|
.background(selection == item.id ? Color.accentColor.opacity(0.12) : Color.clear)
|
||||||
|
.contentShape(Rectangle())
|
||||||
|
.onTapGesture {
|
||||||
|
selection = item.id
|
||||||
|
}
|
||||||
|
.contextMenu {
|
||||||
|
rowContextMenu(for: item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func tableHeader(trailingWidth: CGFloat) -> some View {
|
||||||
HStack(spacing: 0) {
|
HStack(spacing: 0) {
|
||||||
ForEach(orderedVisibleColumns) { column in
|
ForEach(orderedVisibleColumns) { column in
|
||||||
HStack(spacing: 0) {
|
|
||||||
ZStack(alignment: .trailing) {
|
ZStack(alignment: .trailing) {
|
||||||
Button {
|
Button {
|
||||||
if sortColumn == column {
|
if sortColumn == column {
|
||||||
@@ -361,9 +377,12 @@ private struct DownloadTable: View {
|
|||||||
.frame(width: width(for: column), height: 34)
|
.frame(width: width(for: column), height: 34)
|
||||||
.clipped()
|
.clipped()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if trailingWidth > 0 {
|
||||||
|
Color.clear
|
||||||
|
.frame(width: trailingWidth, height: 34)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(minWidth: totalWidth, alignment: .leading)
|
|
||||||
.background(.bar)
|
.background(.bar)
|
||||||
.contextMenu {
|
.contextMenu {
|
||||||
Section("Columns") {
|
Section("Columns") {
|
||||||
@@ -509,6 +528,7 @@ private struct DownloadRow: View {
|
|||||||
let item: DownloadItem
|
let item: DownloadItem
|
||||||
let visibleColumns: [DownloadColumn]
|
let visibleColumns: [DownloadColumn]
|
||||||
let columnWidth: (DownloadColumn) -> CGFloat
|
let columnWidth: (DownloadColumn) -> CGFloat
|
||||||
|
let trailingWidth: CGFloat
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack(alignment: .top, spacing: 0) {
|
HStack(alignment: .top, spacing: 0) {
|
||||||
@@ -519,6 +539,11 @@ private struct DownloadRow: View {
|
|||||||
.frame(width: columnWidth(column), alignment: alignment(for: column))
|
.frame(width: columnWidth(column), alignment: alignment(for: column))
|
||||||
.clipped()
|
.clipped()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if trailingWidth > 0 {
|
||||||
|
Color.clear
|
||||||
|
.frame(width: trailingWidth)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user