Skip to content

Commit

Permalink
fix: marquee
Browse files Browse the repository at this point in the history
cleans up ugly marquee code, prioritizes front end API for marquee entry (less complicated marquee usage)
  • Loading branch information
ejbills committed Dec 31, 2024
1 parent fd73d9f commit e5d3a7c
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 39 deletions.
4 changes: 4 additions & 0 deletions DockDoor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
BB1CBD582C1BA800003969BC /* MainSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1CBD572C1BA800003969BC /* MainSettingsView.swift */; };
BB1CBD5B2C1BA8DC003969BC /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = BB1CBD5A2C1BA8DC003969BC /* Defaults */; };
BB1CBD5D2C1BCA4F003969BC /* Misc Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1CBD5C2C1BCA4F003969BC /* Misc Utils.swift */; };
BB1F60E52D238A9800808E05 /* CGSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1F60E42D238A9700808E05 /* CGSize.swift */; };
BB2567C62C10C5F000C0C93E /* DockUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2567C52C10C5F000C0C93E /* DockUtils.swift */; };
BB2CBB092C481295004502C5 /* SpaceWindowCacheManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2CBB082C48128D004502C5 /* SpaceWindowCacheManager.swift */; };
BB33E68C2C24C72F00A21D69 /* LaunchAtLogin in Frameworks */ = {isa = PBXBuildFile; productRef = BB33E68B2C24C72F00A21D69 /* LaunchAtLogin */; };
Expand Down Expand Up @@ -146,6 +147,7 @@
BB1A85F62D08E52A00326297 /* DragPreviewCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DragPreviewCoordinator.swift; sourceTree = "<group>"; };
BB1CBD572C1BA800003969BC /* MainSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainSettingsView.swift; sourceTree = "<group>"; };
BB1CBD5C2C1BCA4F003969BC /* Misc Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Misc Utils.swift"; sourceTree = "<group>"; };
BB1F60E42D238A9700808E05 /* CGSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CGSize.swift; sourceTree = "<group>"; };
BB2567C52C10C5F000C0C93E /* DockUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DockUtils.swift; sourceTree = "<group>"; };
BB2CBB082C48128D004502C5 /* SpaceWindowCacheManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpaceWindowCacheManager.swift; sourceTree = "<group>"; };
BB3967FC2C291D5A004F1AB6 /* StackedShadow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackedShadow.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -239,6 +241,7 @@
3A105FD72C1BF11D0015EC66 /* Extensions */ = {
isa = PBXGroup;
children = (
BB1F60E42D238A9700808E05 /* CGSize.swift */,
BBE153C12D22024E00CD3D4A /* View.swift */,
BBAC6B442D15FA8800A0F370 /* AXValue.swift */,
BB918BB42CF7613200931236 /* CGRect.swift */,
Expand Down Expand Up @@ -639,6 +642,7 @@
BB15E1E42C8E9435002ECFB9 /* FluidGradientView.swift in Sources */,
BB15E1E52C8E9435002ECFB9 /* BlobLayer.swift in Sources */,
3A1622CC2C8D5F5B00D318EE /* FirstTimePermissionsTabView.swift in Sources */,
BB1F60E52D238A9800808E05 /* CGSize.swift in Sources */,
3A105FDD2C1C0EE20015EC66 /* DynStack.swift in Sources */,
BB4ED9092C3CD97400BBDD16 /* Traffic Light Buttons.swift in Sources */,
C119BDF22C2AFA7600E06E18 /* WindowSwitcherSettingsView.swift in Sources */,
Expand Down
60 changes: 36 additions & 24 deletions DockDoor/Components/Marquee.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
import SmoothGradient
import SwiftUI

struct MarqueeText: View {
var text: String
var fontSize: CGFloat
var startDelay: Double
let maxWidth: Double
@State private var textWidth: CGFloat = 0

var body: some View {
GeometryReader { geometry in
TheMarquee(
width: maxWidth,
secsBeforeLooping: startDelay,
speedPtsPerSec: 30,
marqueeAlignment: .leading,
nonMovingAlignment: .leading,
spacingBetweenElements: 8,
horizontalPadding: 8,
fadeLength: 8
) {
Text(text)
.font(.system(size: fontSize))
.lineLimit(1)
.background(
GeometryReader { textGeometry in
Color.clear.onAppear {
textWidth = textGeometry.size.width
}
}
)
}
}
.frame(width: textWidth > maxWidth ? maxWidth : textWidth, height: fontSize + 4)
}
}

struct TheMarquee<C: View>: View {
var width: Double
var secsBeforeLooping: Double = 0
Expand Down Expand Up @@ -32,7 +67,7 @@ struct TheMarquee<C: View>: View {
let offsetAmount = contentSize.width + spacingBetweenElements
let duration = offsetAmount / speedPtsPerSec

withAnimation(.linear(duration: duration)) {
withAnimation(.easeInOut(duration: duration)) {
offset = -offsetAmount
}

Expand Down Expand Up @@ -108,23 +143,6 @@ extension View {
}
}

extension View {
func measure(_ sizeBinding: Binding<CGSize>) -> some View {
background {
Color.clear
.background(
GeometryReader { geometry in
Color.clear
.preference(key: ViewSizeKey.self, value: geometry.size)
}
)
.onPreferenceChange(ViewSizeKey.self) { size in
sizeBinding.wrappedValue = size
}
}
}
}

struct ViewSizeKey: PreferenceKey {
static var defaultValue: CGSize = .zero
static func reduce(value: inout CGSize, nextValue: () -> CGSize) {
Expand All @@ -139,9 +157,3 @@ func doAfter(_ seconds: Double = 0, action: @escaping () -> Void) {
func timer(_ seconds: Double = 0, action: @escaping (Timer) -> Void) -> Timer {
Timer.scheduledTimer(withTimeInterval: seconds, repeats: false, block: action)
}

extension CGSize {
static func + (lhs: CGSize, rhs: CGSize) -> CGSize {
CGSize(width: lhs.width + rhs.width, height: lhs.height + rhs.height)
}
}
7 changes: 7 additions & 0 deletions DockDoor/Extensions/CGSize.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Cocoa

extension CGSize {
static func + (lhs: CGSize, rhs: CGSize) -> CGSize {
CGSize(width: lhs.width + rhs.width, height: lhs.height + rhs.height)
}
}
17 changes: 17 additions & 0 deletions DockDoor/Extensions/View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,20 @@ extension View {
}
}
}

extension View {
func measure(_ sizeBinding: Binding<CGSize>) -> some View {
background {
Color.clear
.background(
GeometryReader { geometry in
Color.clear
.preference(key: ViewSizeKey.self, value: geometry.size)
}
)
.onPreferenceChange(ViewSizeKey.self) { size in
sizeBinding.wrappedValue = size
}
}
}
}
15 changes: 4 additions & 11 deletions DockDoor/Views/Hover Window/WindowPreview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,10 @@ struct WindowPreview: View {
!windowTitle.isEmpty,
windowTitle != windowInfo.app.localizedName
{
let stringMeasurementWidth = measureString(windowTitle, fontSize: 12).width + 5
let maxLabelWidth = max(dimensions.size.width - 50, 50)
let width = min(stringMeasurementWidth, maxLabelWidth)
TheMarquee(width: width, secsBeforeLooping: 1, speedPtsPerSec: 20, nonMovingAlignment: .leading) {
Text(windowInfo.windowName ?? "Hidden window")
.font(.system(size: 12, weight: .medium))
.foregroundStyle(.primary)
.lineLimit(1)
}
.materialPill()
.padding(4)
MarqueeText(text: windowTitle, fontSize: 12, startDelay: 1, maxWidth: dimensions.size.width * 0.75)
.lineLimit(1)
.materialPill()
.padding(4)
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions DockDoor/Views/Intro/Tabs/FirstTimeIntroTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,3 @@ struct FirstTimeIntroTabView: View {
}
}
}

// #Preview {
// FirstTimeIntroTabView()
// }

0 comments on commit e5d3a7c

Please sign in to comment.