From 2bfdfa6686ef5101ab19ea88d87bbdc153c055d6 Mon Sep 17 00:00:00 2001 From: Jacopo Hernandez Date: Sat, 27 Jun 2026 22:52:36 +0200 Subject: [PATCH] chore(ui): dynamic fps counter color based on thresholds (green >30, yellow 20-30, red <20) --- app/src/main/runtime/display/PerformanceHud.kt | 7 +++++-- app/src/main/runtime/display/ui/FrameRating.java | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/runtime/display/PerformanceHud.kt b/app/src/main/runtime/display/PerformanceHud.kt index 1c73a400e..d6169b34d 100644 --- a/app/src/main/runtime/display/PerformanceHud.kt +++ b/app/src/main/runtime/display/PerformanceHud.kt @@ -96,7 +96,7 @@ fun PerformanceHudOverlay(modifier: Modifier = Modifier) { // value shows N/A rather than dropping the gauge (which would make the row jump around). val gauges = ArrayList(8) if (s.enabled.getOrElse(0) { false }) { - gauges.add(GaugeSpec("FPS", s.fps.toInt().toString(), s.fps / 120f, HudAccent)) + gauges.add(GaugeSpec("FPS", s.fps.toInt().toString(), s.fps / 120f, fpsColor(s.fps))) } if (s.enabled.getOrElse(2) { false }) { gauges.add(GaugeSpec("GPU", pctText(s.gpuLoad), pctFraction(s.gpuLoad), loadColor(maxOf(s.gpuLoad, 0)))) @@ -108,7 +108,7 @@ fun PerformanceHudOverlay(modifier: Modifier = Modifier) { gauges.add(GaugeSpec("RAM", pctText(s.ramPercent), pctFraction(s.ramPercent), loadColor(maxOf(s.ramPercent, 0)))) } if (s.enabled.getOrElse(6) { false }) { - gauges.add(GaugeSpec("ms", String.format("%.1f", s.frametimeMs), 1f - (s.frametimeMs / 33.3f), HudGood)) + gauges.add(GaugeSpec("ms", String.format("%.1f", s.frametimeMs), 1f - (s.frametimeMs / 33.3f), fpsColor(s.fps))) } if (s.enabled.getOrElse(5) { false }) { // Battery + temperature is a single HUD element: watts is the gauge value, temp the sublabel. @@ -165,6 +165,9 @@ private fun loadColor(pct: Int): Color = private fun tempColor(c: Int): Color = if (c >= 45) HudBad else if (c >= 40) HudWarn else HudGood +private fun fpsColor(fps: Float): Color = + if (fps >= 30f) HudGood else if (fps >= 20f) HudWarn else HudBad + @Composable private fun HudGauge( label: String, diff --git a/app/src/main/runtime/display/ui/FrameRating.java b/app/src/main/runtime/display/ui/FrameRating.java index dab98740b..d2a0190d3 100644 --- a/app/src/main/runtime/display/ui/FrameRating.java +++ b/app/src/main/runtime/display/ui/FrameRating.java @@ -1509,13 +1509,13 @@ this.lastFPS, this.currentMs, this.gpuLoad, this.cpuPercent, ramPercentValue(), if (this.enableFps && this.tvFpsBig != null) { this.tvFpsBig.setText(String.format(Locale.US, "%.0f", this.lastFPS)); - this.tvFpsBig.setTextColor(this.C_FPS_OK); + this.tvFpsBig.setTextColor(fpsColor(this.lastFPS)); this.tvFpsBig.setVisibility(View.VISIBLE); } else if (this.tvFpsBig != null) this.tvFpsBig.setVisibility(View.GONE); if (this.enableGraph && this.frametimeNumericMode && this.tvFrametime != null) { this.tvFrametime.setText(String.format(Locale.US, "%.1f ms", this.currentMs)); - this.tvFrametime.setTextColor(this.C_FPS_OK); + this.tvFrametime.setTextColor(fpsColor(this.lastFPS)); this.tvFrametime.setVisibility(View.VISIBLE); } else if (this.tvFrametime != null) { this.tvFrametime.setVisibility(View.GONE); @@ -1524,6 +1524,10 @@ this.lastFPS, this.currentMs, this.gpuLoad, this.cpuPercent, ramPercentValue(), if (getOrientation() == LinearLayout.HORIZONTAL) updateSeparators(true); } + private int fpsColor(float fps) { + return fps >= 30f ? C_FPS_OK : fps >= 20f ? C_WARM : C_HOT; + } + private void append(SpannableStringBuilder b, String t, int c) { int start = b.length(); b.append(t); @@ -1677,6 +1681,7 @@ protected void onDraw(Canvas canvas) { float y = h - ((this.history[idx] / 40.0f) * h); this.path.lineTo(i * step, Math.max(0.0f, y)); } + this.paintLine.setColor(fpsColor(lastFPS)); canvas.drawPath(this.path, this.paintLine); } }