mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-08 13:33:42 +08:00
a82935f326
Integrate onroad views, configurable widgets, local settings, steering-profile contracts, Bluetooth and Android Auto with their device and runtime services. Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Daniel Koepping <elkoled@gmail.com> Co-authored-by: Danny <dannyirwin31@yahoo.com> Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com> Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com> Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com> Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu> Co-authored-by: Shane Smiskol <shane@smiskol.com> Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com> Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com> Co-authored-by: stef <19478336+stefpi@users.noreply.github.com> Co-authored-by: whoisdomi <dcantu83@gmail.com> Co-authored-by: Intelli <contact@intelli.software> Co-authored-by: pharmacomaniac <blittle65@gmail.com> Co-authored-by: prabhaavp <prabhaav@msu.edu>
68 lines
2.6 KiB
Python
68 lines
2.6 KiB
Python
"""Sample-only Big developer sidebar artwork for the parked layout preview."""
|
|
|
|
from dataclasses import dataclass
|
|
|
|
import pyray as rl
|
|
|
|
from openpilot.starpilot.ui.presentation import BitmapFonts, FontRole
|
|
|
|
|
|
SIDEBAR_WIDTH = 300
|
|
METRIC_WIDTH = 275
|
|
METRIC_HEIGHT = 126
|
|
METRIC_MARGIN = 12
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class SidebarMetric:
|
|
label: str
|
|
value: str
|
|
color: tuple[int, int, int]
|
|
|
|
|
|
SAMPLE_METRICS = (
|
|
SidebarMetric("ACCEL", "1.08 ft/s²", (255, 255, 255)),
|
|
SidebarMetric("STEER DELAY", "0.15000", (59, 130, 246)),
|
|
SidebarMetric("FRICTION", "0.12000", (34, 197, 94)),
|
|
SidebarMetric("LAT ACCEL", "2.50000", (59, 130, 246)),
|
|
SidebarMetric("LATERAL %", "78.00%", (255, 255, 255)),
|
|
SidebarMetric("TORQUE %", "42%", (255, 255, 255)),
|
|
SidebarMetric("CHESTNUT", "", (255, 255, 255)),
|
|
)
|
|
|
|
|
|
def metric_rects(frame: rl.Rectangle, count: int) -> tuple[rl.Rectangle, ...]:
|
|
if not 0 <= count <= 7:
|
|
raise ValueError("Big developer sidebar supports up to seven metrics")
|
|
spacing = max(1, (int(frame.height) - count * METRIC_HEIGHT) // max(1, count + 1))
|
|
x = int(frame.x + frame.width) - METRIC_MARGIN - METRIC_WIDTH
|
|
return tuple(rl.Rectangle(x, frame.y + spacing + index * (METRIC_HEIGHT + spacing),
|
|
METRIC_WIDTH, METRIC_HEIGHT) for index in range(count))
|
|
|
|
|
|
def render_sidebar(fonts: BitmapFonts, frame: rl.Rectangle,
|
|
metrics: tuple[SidebarMetric, ...] = SAMPLE_METRICS) -> None:
|
|
if len(metrics) > 7:
|
|
raise ValueError("Big developer sidebar supports up to seven metrics")
|
|
rl.draw_rectangle_rec(frame, rl.BLACK)
|
|
for rect, metric in zip(metric_rects(frame, len(metrics)), metrics, strict=True):
|
|
color = rl.Color(*metric.color, 255)
|
|
edge = rl.Rectangle(rect.x + METRIC_WIDTH - 104, rect.y + 4, 100, 118)
|
|
rl.draw_rectangle_rounded(edge, 0.3, 10, color)
|
|
rl.draw_rectangle_rec(rl.Rectangle(edge.x, rect.y, 82, rect.height), rl.BLACK)
|
|
rl.draw_rectangle_rounded_lines_ex(rect, 0.3, 10, 2, rl.Color(255, 255, 255, 85))
|
|
lines = (metric.label, metric.value) if metric.value else (metric.label,)
|
|
fitted = []
|
|
for line in lines:
|
|
font_size = 35
|
|
measured = fonts.measure(line, FontRole.SEMI_BOLD, font_size)
|
|
while measured.width > rect.width - 22 and font_size > 20:
|
|
font_size -= 1
|
|
measured = fonts.measure(line, FontRole.SEMI_BOLD, font_size)
|
|
fitted.append((line, font_size, measured))
|
|
y = rect.y + (rect.height - sum(measured.height for _, _, measured in fitted)) / 2
|
|
for line, font_size, measured in fitted:
|
|
fonts.draw(line, FontRole.SEMI_BOLD, font_size,
|
|
rect.x + (rect.width - measured.width) / 2, y, rl.WHITE)
|
|
y += measured.height
|