Skip to content

Commit

Permalink
fix: order grid vertical or horizontal
Browse files Browse the repository at this point in the history
  • Loading branch information
hasansultan92 committed Sep 14, 2024
1 parent f34b60c commit 1b8830a
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions DockDoor/Views/Hover Window/WindowPreviewHoverContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct WindowPreviewHoverContainer: View {
@State private var showWindows: Bool = false
@State private var hasAppeared: Bool = false
@State private var appIcon: NSImage? = nil
@State private var isVerticalGrid: Bool = true

var maxWindowDimension: CGPoint {
let thickness = SharedPreviewWindowCoordinator.shared.windowSize.height
Expand All @@ -46,10 +45,6 @@ struct WindowPreviewHoverContainer: View {
return CGPoint(x: maxWidth, y: maxHeight)
}

var scrollDirection: Axis.Set {
.vertical
}

var body: some View {
ZStack {
if let mouseLocation {
Expand All @@ -58,7 +53,7 @@ struct WindowPreviewHoverContainer: View {
}

ScrollViewReader { scrollProxy in
ScrollView(scrollDirection, showsIndicators: false) {
ScrollView(.vertical, showsIndicators: false) {
windowPreviewGrid
.padding(14)
.onAppear {
Expand All @@ -75,9 +70,6 @@ struct WindowPreviewHoverContainer: View {
.onChange(of: windows) { _ in
runUIUpdates()
}
.onChange(of: bestGuessMonitor) { _ in
initGridLayout()
}
}
.opacity(showWindows ? 1 : 0.8)
}
Expand All @@ -94,7 +86,7 @@ struct WindowPreviewHoverContainer: View {

private var windowPreviewGrid: some View {
Group {
if isVerticalGrid {
if GridLayoutVertical() {
LazyHGrid(rows: calculateGridInfo(), spacing: 16) {
gridContent
}
Expand Down Expand Up @@ -218,7 +210,6 @@ struct WindowPreviewHoverContainer: View {
private func runUIUpdates() {
runAnimation()
loadAppIcon()
initGridLayout()
}

private func runAnimation() {
Expand All @@ -237,17 +228,22 @@ struct WindowPreviewHoverContainer: View {
}
}

private func initGridLayout() {
if mouseLocation != nil, dockPosition == .left || dockPosition == .right {
private func GridLayoutVertical() -> Bool {
var isVerticalGrid = false
if windowSwitcherCoordinator.windowSwitcherActive {
isVerticalGrid = false
} else if mouseLocation != nil, dockPosition == .left || dockPosition == .right {
isVerticalGrid = true
} else {
} else if mouseLocation != nil, dockPosition == .bottom || dockPosition == .top {
isVerticalGrid = false
}
return isVerticalGrid
}

private func calculateGridInfo() -> [GridItem] {
let isVerticalGrid = GridLayoutVertical()
let availablePixels = isVerticalGrid ? bestGuessMonitor.visibleFrame.height - 15 : bestGuessMonitor.visibleFrame.width - 15
let maxColumnWidth = maxWindowDimension.x
let maxColumnWidth = isVerticalGrid ? maxWindowDimension.y : maxWindowDimension.x
var numberOfColumns = 0
let maxNumberOfColumns = Int(availablePixels / maxColumnWidth)
if windows.count < maxNumberOfColumns {
Expand Down

0 comments on commit 1b8830a

Please sign in to comment.