Files
StarPilot/openpilot/starpilot/ui/onroad_widget_style.py
T
firestar5683 a82935f326 User interfaces and Android Auto
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>
2026-10-14 20:02:39 -05:00

45 lines
1.8 KiB
Python

"""Shared visual tokens for the StarPilot on-road control widgets."""
import pyray as rl
from openpilot.starpilot.ui.onroad_customization import rgba
# The two left-hand control cards share a visible frame. Keeping these values
# here prevents the Set Speed and SLC implementations from drifting apart.
CONTROL_WIDTH = 176
SET_SPEED_HEIGHT = 196
SLC_HEIGHT = SET_SPEED_HEIGHT
# Stable Raylib shape settings for scaled rendering.
CONTROL_RADIUS = 31
CONTROL_ROUNDNESS = 0.35
CONTROL_SEGMENTS = 10
CONTROL_BORDER_WIDTH = 6
CONTROL_BG = rl.Color(0, 0, 0, 166)
CONTROL_BORDER = rl.Color(196, 205, 208, 180)
# The layout manager has historically anchored the left controls at x + 146.
# Keep that placement stable while making the width explicit and shared.
WIDGET_ANCHOR_OFFSET = 146
def roundness_for(rect: rl.Rectangle, radius: float = CONTROL_RADIUS) -> float:
"""Convert a pixel corner radius to Raylib's normalized roundness value."""
return min(1.0, radius / max(1.0, min(rect.width, rect.height) / 2.0))
def draw_control_card(rect: rl.Rectangle, *, fill: rl.Color = CONTROL_BG,
border: rl.Color = CONTROL_BORDER,
border_width: float = CONTROL_BORDER_WIDTH,
roundness: float = CONTROL_ROUNDNESS) -> None:
"""Draw the common translucent rounded card used by left-hand controls."""
rl.draw_rectangle_rounded(rect, roundness, CONTROL_SEGMENTS, fill)
rl.draw_rectangle_rounded_lines_ex(rect, roundness, CONTROL_SEGMENTS, border_width, border)
def draw_widget_frame(rect, document, profile, widget):
fill = rl.Color(*rgba(document, "cardFill", profile, widget))
border = rl.Color(*rgba(document, "cardBorder", profile, widget))
if fill.a:
rl.draw_rectangle_rounded(rect, 0.2, 8, fill)
if border.a:
rl.draw_rectangle_rounded_lines_ex(rect, 0.2, 8, 2 if str(profile) == "compact" else 4, border)