← All repositories

listless

A simple list app for Apple platforms

git clone https://code.inqk.net/listless.git


commit 8e45b34ce855229a0aa043883b6dfd684fbfed24
parent 164fada66965680562b546afcfc6b1f38749ae00
Author: Michael Camilleri <[email protected]>
Date:   Wed, 25 Mar 2026 06:21:43 +0900

Tweak FPS overlay to show target frame speed

Diffstat

MListlessiOS/Helpers/FPSOverlay.swift | 19++++++++++++++-----
MListlessiOS/Views/TaskListView.swift | 6+++---

2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/ListlessiOS/Helpers/FPSOverlay.swift b/ListlessiOS/Helpers/FPSOverlay.swift

@@ -3,17 +3,21 @@ import UIKit
 
 struct FPSOverlay: View {
     @State private var fps: Int = 0
+    @State private var targetFPS: Int = 0
     @State private var monitor = FPSMonitor()
 
     var body: some View {
-        Text("\(fps) FPS")
+        Text("\(fps) / \(targetFPS) FPS")
             .font(.system(size: 12, weight: .bold, design: .monospaced))
             .foregroundStyle(fps >= 55 ? .green : fps >= 45 ? .yellow : .red)
             .padding(.horizontal, 8)
             .padding(.vertical, 4)
             .background(.black.opacity(0.7), in: Capsule())
             .onAppear {
-                monitor.start { fps = $0 }
+                monitor.start { actual, target in
+                    fps = actual
+                    targetFPS = target
+                }
             }
             .onDisappear {
                 monitor.stop()
@@ -26,9 +30,10 @@ private class FPSMonitor {
     private var displayLink: CADisplayLink?
     private var lastTimestamp: CFTimeInterval = 0
     private var frameCount: Int = 0
-    private var onUpdate: ((Int) -> Void)?
+    private var lastTargetFPS: Int = 0
+    private var onUpdate: ((Int, Int) -> Void)?
 
-    func start(onUpdate: @escaping (Int) -> Void) {
+    func start(onUpdate: @escaping (Int, Int) -> Void) {
         self.onUpdate = onUpdate
         let link = CADisplayLink(target: self, selector: #selector(tick))
         link.preferredFrameRateRange = CAFrameRateRange(minimum: 80, maximum: 120, preferred: 120)
@@ -42,6 +47,10 @@ private class FPSMonitor {
     }
 
     @objc private func tick(_ link: CADisplayLink) {
+        let interval = link.targetTimestamp - link.timestamp
+        if interval > 0 {
+            lastTargetFPS = Int(round(1.0 / interval))
+        }
         if lastTimestamp == 0 {
             lastTimestamp = link.timestamp
             return
@@ -49,7 +58,7 @@ private class FPSMonitor {
         frameCount += 1
         let elapsed = link.timestamp - lastTimestamp
         if elapsed >= 1.0 {
-            onUpdate?(frameCount)
+            onUpdate?(frameCount, lastTargetFPS)
             frameCount = 0
             lastTimestamp = link.timestamp
         }

diff --git a/ListlessiOS/Views/TaskListView.swift b/ListlessiOS/Views/TaskListView.swift

@@ -407,11 +407,11 @@ struct TaskListView: View, TaskListViewProtocol {
 
     var body: some View {
         taskScrollView
-            .overlay(alignment: .topTrailing) {
+            .overlay(alignment: .topLeading) {
                 if showFPSOverlay {
                     FPSOverlay()
-                        .padding(.top, 4)
-                        .padding(.trailing, 8)
+                        .padding(.top, -16)
+                        .padding(.leading, 8)
                         .allowsHitTesting(false)
                 }
             }