Skip to content

Commit

Permalink
Fix click through
Browse files Browse the repository at this point in the history
  • Loading branch information
alin23 committed Oct 8, 2023
1 parent 26ed4d7 commit 54c5b92
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
1 change: 1 addition & 0 deletions Clop/ClopApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ class AppDelegate: LowtechProAppDelegate {
Defaults[.videoDirs] = Defaults[.videoDirs].filter { fm.fileExists(atPath: $0) }

guard !SWIFTUI_PREVIEW else { return }
sizeNotificationWindow.animateOnResize = true
pub(.floatingResultsCorner)
.sink {
sizeNotificationWindow.moveToScreen(.withMouse, corner: $0.newValue)
Expand Down
28 changes: 26 additions & 2 deletions Clop/CompactResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ struct CompactResult: View {
@ViewBuilder var sizeDiff: some View {
if let oldSize = optimiser.oldSize {
ResolutionField(optimiser: optimiser, size: oldSize)
.buttonStyle(FlatButton(color: .primary.opacity(colorScheme == .dark ? (isEven ? 0.1 : 0.05) : (isEven ? 0.04 : 0.13)), textColor: .primary, radius: 3, horizontalPadding: 3, verticalPadding: 1))
.font(.mono(11, weight: .medium))
.foregroundColor(.secondary)
.fixedSize()
Expand Down Expand Up @@ -285,6 +286,8 @@ struct OverlayMessageView: View {
struct CompactResultList: View {
@State var hovering = false
@State var showList = false
@State var size = NSSize(width: 50, height: 50)

var optimisers: [Optimiser]
var progress: Progress?

Expand Down Expand Up @@ -352,7 +355,8 @@ struct CompactResultList: View {
.padding(.bottom, progress == nil ? 0 : 18)
}
.padding(.vertical, 5)
.frame(width: THUMB_SIZE.width + (showCompactImages ? 50 : 0), height: min(360, (optimisers.count * 80).cg), alignment: .center)
.frame(width: size.width, height: size.height, alignment: .center)
.fixedSize()
.background(Color.inverted.brightness(0.1))
.onHover { hovering in
if !hovering {
Expand Down Expand Up @@ -380,16 +384,36 @@ struct CompactResultList: View {
}
}
.padding(isTrailing ? .trailing : .leading)
.frame(width: THUMB_SIZE.width + (showCompactImages ? 60 : 50), height: 442, alignment: floatingResultsCorner.alignment)
.onHover { hovered in
withAnimation(.easeIn(duration: 0.35)) {
hovering = hovered
}
}
.onChange(of: showList) { showList in
compactResultsSizeTask = mainAsyncAfter(ms: showList ? 0 : 500) {
setSize(showList: showList)
}
}
.onChange(of: optimisers.count) { count in setSize(count: count) }
.onChange(of: showCompactImages) { compactImages in setSize(compactImages: compactImages) }
.onAppear {
showList = preview || optimisers.count <= 3
setSize()
}
}

func setSize(showList: Bool? = nil, count: Int? = nil, compactImages: Bool? = nil) {
size = NSSize(
width: (showList ?? self.showList) ? (THUMB_SIZE.width + ((compactImages ?? showCompactImages) ? 50 : 0)) : 50,
height: (showList ?? self.showList) ? min(360, ((count ?? optimisers.count) * 80).cg) : 50
)
}
}

var compactResultsSizeTask: DispatchWorkItem? {
didSet {
oldValue?.cancel()
}
}

struct ToggleCompactResultListButton: View {
Expand Down
15 changes: 12 additions & 3 deletions Clop/FloatingResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ struct FloatingResultContainer: View {
if optimisers.isNotEmpty {
if (alwaysShowCompactResults && !isPreview) || optimisers.count > 5 || om.compactResults {
CompactResultList(optimisers: optimisers, progress: om.progress, doneCount: om.doneCount, failedCount: om.failedCount, visibleCount: om.visibleCount).preview(isPreview)
.padding()
.padding(.horizontal, 10)
.padding(.vertical, 15)
.onAppear {
om.compactResults = true
}
Expand All @@ -96,11 +97,13 @@ struct FloatingResultContainer: View {
hoveredOptimiserID = nil
}
}
.padding(.vertical, showImages ? 36 : 10)
.padding(.vertical, om.compactResults ? 0 : (showImages ? 36 : 10))
.padding(floatingResultsCorner.isTrailing ? .leading : .trailing, 20)
}
}

var initializedFloatingWindow = false

@MainActor
struct FloatingPreview: View {
static var om: OptimisationManager = {
Expand Down Expand Up @@ -208,6 +211,7 @@ struct FloatingResult: View {
@ViewBuilder var sizeDiff: some View {
if let oldSize = optimiser.oldSize {
ResolutionField(optimiser: optimiser, size: oldSize)
.buttonStyle(FlatButton(color: .black.opacity(0.1), textColor: .white, radius: 3, horizontalPadding: 3, verticalPadding: 1))
.font(.round(10))
.foregroundColor(optimiser.thumbnail != nil && showImages ? .lightGray : .secondary)
.fixedSize()
Expand Down Expand Up @@ -415,6 +419,7 @@ struct FloatingResult: View {
height: THUMB_SIZE.height / 2,
alignment: .center
)
.fixedSize()
.padding(.horizontal, 5)
.padding(.vertical, 5)
.background(
Expand Down Expand Up @@ -473,6 +478,7 @@ struct FloatingResult: View {
)
)
.frame(width: THUMB_SIZE.width / 2, height: 16, alignment: .leading)
.fixedSize()
.padding(.horizontal, 5)
.offset(y: hovering || editingFilename || SWIFTUI_PREVIEW ? 0 : 30)
.opacity(hovering || editingFilename || SWIFTUI_PREVIEW ? 1 : 0)
Expand Down Expand Up @@ -500,16 +506,19 @@ struct FloatingResult: View {

if hasThumbnail, hovering {
SideButtons(optimiser: optimiser, size: showsThumbnail ? 24 : 18)
.frame(width: 30, alignment: .bottom)
.fixedSize()
} else {
SwiftUI.Image("clop")
.resizable()
.scaledToFit()
.frame(width: 30, height: 30, alignment: .center)
.fixedSize()
.opacity(showFloatingHatIcon ? 1 : 0)
}
}
}
.frame(width: THUMB_SIZE.width, alignment: floatingResultsCorner.isTrailing ? .trailing : .leading)
// .frame(minWidth: THUMB_SIZE.width / 2, idealWidth: THUMB_SIZE.width / 2, maxWidth: THUMB_SIZE.width, alignment: floatingResultsCorner.isTrailing ? .trailing : .leading)
.padding(.horizontal)
.fixedSize()
.onHover { hovering in
Expand Down
2 changes: 1 addition & 1 deletion Clop/OptimisationUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ class OptimisationManager: ObservableObject, QLPreviewPanelDataSource {

func updateProgress() {
visibleCount = visibleOptimisers.count
doneCount = visibleOptimisers.filter { !$0.running && $0.error == nil && $0.notice == nil }.count
doneCount = visibleOptimisers.filter { !$0.running && $0.error == nil }.count
failedCount = visibleOptimisers.filter { !$0.running && $0.error != nil }.count
let finishedCount = doneCount + failedCount

Expand Down
11 changes: 8 additions & 3 deletions Clop/ResolutionField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ struct ResolutionField: View {
.lineLimit(1)
}
)
.buttonStyle(FlatButton(color: .black.opacity(0.1), textColor: .white, radius: 3, horizontalPadding: 3, verticalPadding: 1))
}

var editor: some View {
Expand Down Expand Up @@ -68,7 +67,8 @@ struct ResolutionField: View {
guard !preview else { return }
optimiser.crop(to: NSSize(width: tempWidth, height: tempHeight))
}
.buttonStyle(FlatButton(color: .inverted.opacity(0.6), textColor: .primary))
.buttonStyle(.bordered)
.fontDesign(.rounded)
.monospacedDigit()

HStack {
Expand All @@ -80,7 +80,9 @@ struct ResolutionField: View {
else { return }

savedCropSizes.append(CropSize(width: tempWidth, height: tempHeight, name: name))
}.buttonStyle(FlatButton(color: .inverted.opacity(0.6), textColor: .primary))
}
.buttonStyle(.bordered)
.fontDesign(.rounded)
}
}
.padding()
Expand Down Expand Up @@ -134,6 +136,7 @@ struct ResolutionField: View {
HStack {
Text(size.name)
.allowsTightening(false)
.fontDesign(.rounded)
Spacer()
Text(size.id)
.monospaced()
Expand All @@ -142,6 +145,7 @@ struct ResolutionField: View {
.frame(width: 150)
.lineLimit(1)
})
.buttonStyle(.bordered)

Button(action: {
withAnimation(.easeOut(duration: 0.1)) {
Expand All @@ -151,6 +155,7 @@ struct ResolutionField: View {
SwiftUI.Image(systemName: "trash")
.foregroundColor(.red)
})
.buttonStyle(.bordered)

}
}
Expand Down

0 comments on commit 54c5b92

Please sign in to comment.