mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 06:13:40 +08:00
Enlarge large-UI speed group and align numbers on one row
This commit is contained in:
@@ -25,15 +25,15 @@ metadata.widgets.jetlink_status = { label: "Jetlink status", kind: "jetlink_stat
|
||||
metadata.widgetOrder = [...(metadata.widgetOrder || Object.keys(native.metadata.profiles.large.widgets)), "jetlink_status", "car_exit"]
|
||||
const widgets = Object.fromEntries(Object.entries(metadata.widgets).map(([id, widget]) => [id,
|
||||
{ ...widget.default, ...(widget.resizable ? { size: widget.resizable.default } : {}) }]))
|
||||
const doc = { version: 6, clock24Hour: false, largeUiGammaTrial: false, blindSpotBorder: false, signalBorder: false, blindSpotCamera: false, hidePersonalityAlerts: false, wheelPedalFeedback: false, leadIndicator: false, leadInfo: "Off", speedSources: false, speedSourcesCard: false, speedAlign: "center", canvas: { width: 2880, height: 1080 }, widgets }
|
||||
const doc = { version: 7, clock24Hour: false, largeUiGammaTrial: false, blindSpotBorder: false, signalBorder: false, blindSpotCamera: false, hidePersonalityAlerts: false, wheelPedalFeedback: false, leadIndicator: false, leadInfo: "Off", speedSources: false, speedSourcesCard: false, speedAlign: "center", canvas: { width: 2880, height: 1080 }, widgets }
|
||||
const raw = { version: 1, document: doc, defaults: copy(doc), metadata,
|
||||
screen: { width: 1280, height: 720, margin_width: 0, margin_height: 240 },
|
||||
revision: "aa-screen-and-layout", editable: true, valid: true,
|
||||
colors: { palette: native.document.palette, widgetColors: native.document.widgetColors.large, roadColors: {} } }
|
||||
const data = editorSnapshot(raw)
|
||||
assert.deepEqual(editorSnapshot({ ...raw, document: { ...doc, version: 4 }, defaults: { ...doc, version: 4 } }).document,
|
||||
data.document, "version 4 layouts remain readable alongside the backend's version 6")
|
||||
for (const bad of [{ version: 7 }, { version: "5" }, { canvas: { width: 1920, height: 1080 } }])
|
||||
data.document, "version 4 layouts remain readable alongside the backend's version 7")
|
||||
for (const bad of [{ version: 8 }, { version: "5" }, { canvas: { width: 1920, height: 1080 } }])
|
||||
assert.throws(() => editorSnapshot({ ...raw, document: { ...doc, ...bad } }), /does not match/)
|
||||
|
||||
assert.equal(validSnapshot(data), true)
|
||||
@@ -260,7 +260,7 @@ const draft = copy(feed.data.document)
|
||||
draft.layouts.large.current_speed.x += 20
|
||||
assert.equal(await feed.save(draft), true)
|
||||
assert.equal(requests[0].url, "./api/starport/layout")
|
||||
assert.equal(requests[1].body.document.version, 6)
|
||||
assert.equal(requests[1].body.document.version, 7)
|
||||
assert.deepEqual(Object.keys(requests[1].body.document).sort(), ["blindSpotBorder", "blindSpotCamera", "canvas", "clock24Hour", "hidePersonalityAlerts", "largeUiGammaTrial", "leadIndicator", "leadInfo", "signalBorder", "speedAlign", "speedSources", "speedSourcesCard", "version", "wheelPedalFeedback", "widgets"])
|
||||
assert.equal(requests[1].body.document.widgets.current_speed.x, 1170)
|
||||
assert.equal(requests[1].body.document.speedAlign, "center")
|
||||
|
||||
@@ -25,7 +25,7 @@ export function editorSnapshot(raw) {
|
||||
throw new Error(raw?.reason || "Connect Android Auto once to obtain the actual screen.")
|
||||
const colors = raw.colors
|
||||
const document = (value) => {
|
||||
if (![4, 5, 6].includes(value.version) || value.canvas?.width !== raw.metadata.width || value.canvas?.height !== raw.metadata.height)
|
||||
if (![4, 5, 6, 7].includes(value.version) || value.canvas?.width !== raw.metadata.width || value.canvas?.height !== raw.metadata.height)
|
||||
throw new Error("The saved StarPort layout does not match its screen. Reload before editing.")
|
||||
return { version: 8, clock24Hour: value.clock24Hour === true, largeUiGammaTrial: value.largeUiGammaTrial === true, blindSpotBorder: value.blindSpotBorder === true, signalBorder: value.signalBorder === true, blindSpotCamera: value.blindSpotCamera === true, hidePersonalityAlerts: value.hidePersonalityAlerts === true, wheelPedalFeedback: value.wheelPedalFeedback === true, leadIndicator: value.leadIndicator === true, leadInfo: LEAD_INFO.includes(value.leadInfo) ? value.leadInfo : "Off", speedSources: value.speedSources === true, speedSourcesCard: value.speedSourcesCard === true, speedAlign: ["center", "right"].includes(value.speedAlign) ? value.speedAlign : "left", ...(value.widgetOrder ? { widgetOrder: { large: clone(value.widgetOrder) } } : {}), palette: clone(colors.palette), layouts: { large: clone(value.widgets) },
|
||||
widgetColors: { large: clone(colors.widgetColors) }, roadColors: { large: clone(colors.roadColors) } }
|
||||
@@ -38,7 +38,7 @@ export function editorSnapshot(raw) {
|
||||
}
|
||||
|
||||
export function projectionPayload(body, metadata) {
|
||||
return { revision: body.revision, document: { version: 6,
|
||||
return { revision: body.revision, document: { version: 7,
|
||||
canvas: { width: metadata.profiles.large.width, height: metadata.profiles.large.height },
|
||||
clock24Hour: body.document.clock24Hour === true,
|
||||
largeUiGammaTrial: body.document.largeUiGammaTrial === true,
|
||||
|
||||
@@ -11,7 +11,7 @@ from openpilot.starpilot.ui.onroad_customization import (CEM_GAUGE_WIDGET, CLOCK
|
||||
SPEED_ALIGNMENTS, customization_metadata, validate_map_box, validate_widget_order)
|
||||
from openpilot.starpilot.ui.onroad_stopped_timer import timer_size
|
||||
from openpilot.starpilot.ui.onroad_torque_geometry import maximum_footprint
|
||||
from openpilot.starpilot.ui.onroad_customization import (SPEED_LAYOUT_V7, migrate_speed_layout, migrate_large_sign_layout,
|
||||
from openpilot.starpilot.ui.onroad_customization import (SPEED_LAYOUT_V7, migrate_speed_layout, migrate_large_sign_layout, migrate_attached_actions_gap,
|
||||
place_attached_slc_actions, migrate_confirmation_layout)
|
||||
from openpilot.starpilot.ui.large_speed_geometry import sources_extent
|
||||
|
||||
@@ -185,7 +185,7 @@ def default_layout(screen, display=None):
|
||||
def default_layout_for_viewport(viewport, display=None):
|
||||
metadata = layout_metadata_for_viewport(viewport)
|
||||
display = {**DISPLAY_DEFAULTS, **{key: value for key, value in (display or {}).items() if key in DISPLAY_DEFAULTS}}
|
||||
result = {'version': 6, 'clock24Hour': False, 'largeUiGammaTrial': False, **display, 'canvas': {key: metadata[key] for key in ('width', 'height')},
|
||||
result = {'version': 7, 'clock24Hour': False, 'largeUiGammaTrial': False, **display, 'canvas': {key: metadata[key] for key in ('width', 'height')},
|
||||
'widgets': {key: {**widget['default'], **({'size': 192} if key == 'steering_wheel' else {})}
|
||||
for key, widget in metadata['widgets'].items()}}
|
||||
place_attached_slc_actions(result['widgets'], metadata['bounds'], sources_extent(result))
|
||||
@@ -230,7 +230,7 @@ def validate_layout_for_viewport(value, viewport, *, _legacy_geometry=False):
|
||||
if type(value) is dict:
|
||||
fields |= {field for field in ('widgetOrder', 'clock24Hour', 'largeUiGammaTrial', *DISPLAY_DEFAULTS) if field in value}
|
||||
if (type(value) is not dict or set(value) != fields or
|
||||
type(value['version']) is not int or value['version'] not in (1, 2, 3, 4, 5, 6) or
|
||||
type(value['version']) is not int or value['version'] not in (1, 2, 3, 4, 5, 6, 7) or
|
||||
value['canvas'] != {key: metadata[key] for key in ('width', 'height')} or
|
||||
type(value['widgets']) is not dict or not set(value['widgets']) <= set(metadata['widgets']) or
|
||||
not set(metadata['widgets']) - set(value['widgets']) <= {CEM_GAUGE_WIDGET, MODE_WIDGET, CLOCK_WIDGET, WEATHER_WIDGET, *PROJECTION_WIDGETS}):
|
||||
@@ -353,12 +353,14 @@ def validate_layout_for_viewport(value, viewport, *, _legacy_geometry=False):
|
||||
actions = result['widgets']['speed_limit_actions']
|
||||
if (actions['x'], actions['y']) == (100, 296):
|
||||
actions.update(x=metadata['widgets']['speed_limit_actions']['default']['x'], y=metadata['widgets']['speed_limit_actions']['default']['y'])
|
||||
result['version'] = 6
|
||||
result['version'] = 7
|
||||
if value['version'] == 5 and result.get('speedSources') is True:
|
||||
card, actions = result['widgets']['cruise_limits'], result['widgets']['speed_limit_actions']
|
||||
old_gap = 284 + (8 if result.get('speedSourcesCard') is True else 0)
|
||||
if actions['x'] == card['x'] + 24 and actions['y'] == card['y'] + old_gap:
|
||||
actions['y'] = card['y'] + 192
|
||||
if value['version'] < 7:
|
||||
migrate_attached_actions_gap(result['widgets'], bounds)
|
||||
migrate_confirmation_layout(result['widgets'], 'large', metadata['widgets'], bounds, extra_height=sources_extent(result))
|
||||
place_attached_slc_actions(result['widgets'], bounds, sources_extent(result))
|
||||
if len(json.dumps(result, separators=(',', ':'), allow_nan=False).encode()) > MAX_BYTES:
|
||||
|
||||
@@ -4,15 +4,18 @@ import math
|
||||
|
||||
WIDTH = 488
|
||||
MAX_ROW_HEIGHT = 132
|
||||
# Preserve physical lettering size across the 402.5 PPI and 300 PPI displays.
|
||||
LARGE_SIGN_SCALE = math.hypot(2160, 1080) / 6 / 300
|
||||
# The compact display's physical size at 402.5 PPI, enlarged 1.3x: the windshield-mounted screen is
|
||||
# read at arm's length, and this puts the numbers near 27 arcmin at 70 cm (ISO 15008 recommends 20).
|
||||
PHYSICAL_SCALE = math.hypot(2160, 1080) / 6 / 300
|
||||
LARGE_SIGN_SCALE = PHYSICAL_SCALE * 1.3
|
||||
SIGN_WIDTH, SIGN_HEIGHT = 128, 144
|
||||
LIMIT_ROW_HEIGHT = math.ceil(SIGN_HEIGHT * LARGE_SIGN_SCALE)
|
||||
CARD_HEIGHT = LIMIT_ROW_HEIGHT
|
||||
ACTION_WIDTH = 308
|
||||
ACTION_HEIGHT = 168
|
||||
ACTION_X = 112
|
||||
ACTION_Y = 267
|
||||
# Attached just below the card.
|
||||
ACTION_Y = 75 + CARD_HEIGHT - 2
|
||||
GAP = 8
|
||||
SOURCE_ROW_HEIGHT = 76
|
||||
PADDING = 24
|
||||
@@ -26,6 +29,8 @@ ACTION_BOUNDS = {
|
||||
ACTION_TEXT_SIZE = {'large': 64, 'compact': 48}
|
||||
|
||||
CONFIRMATION_SCALE = {'large': LARGE_SIGN_SCALE, 'compact': 1.0}
|
||||
# The open prompt's Accept/Reject buttons are sized for fingers, which do not change with viewing distance.
|
||||
PROMPT_SCALE = {'large': PHYSICAL_SCALE, 'compact': 1.0}
|
||||
CONFIRMATION_HEIGHT = {'large': 168, 'compact': 152}
|
||||
CONFIRMATION_HEADER = 40
|
||||
CONFIRMATION_BUTTON = {'large': 180, 'compact': 150}
|
||||
@@ -34,18 +39,21 @@ CONFIRMATION_PADDING = 8
|
||||
|
||||
|
||||
def confirmation_bounds(profile, x, y, *, opened=False):
|
||||
# Opening keeps the notice's top; the buttons' width stays at finger size.
|
||||
scale = CONFIRMATION_SCALE[profile]
|
||||
width = 2 * CONFIRMATION_PADDING + 2 * CONFIRMATION_BUTTON[profile] + CONFIRMATION_GAP if opened else 240
|
||||
left = x + 172 if profile == 'large' else x - 172 if opened else x - 100
|
||||
# Large starts where the sign's tap area does, clear of a three-digit SET.
|
||||
left = x + 218 if profile == 'large' else x - 172 if opened else x - 100
|
||||
top = y - (12 if profile == 'large' else 8)
|
||||
height = CONFIRMATION_HEIGHT[profile] if opened else (168 if profile == 'large' else 159)
|
||||
return left, top, left + width * scale, top + height * scale
|
||||
# The large notice keeps its original spacing below a number on SET's row; its box is transparent.
|
||||
height = CONFIRMATION_HEIGHT[profile] if opened else (184 if profile == 'large' else 159)
|
||||
return left, top, left + width * (PROMPT_SCALE if opened else CONFIRMATION_SCALE)[profile], top + height * scale
|
||||
|
||||
|
||||
def confirmation_buttons(profile, bounds):
|
||||
left, top, _, bottom = bounds
|
||||
scale = CONFIRMATION_SCALE[profile]
|
||||
return tuple((left + (CONFIRMATION_PADDING + x) * scale, top + CONFIRMATION_HEADER * scale,
|
||||
scale = PROMPT_SCALE[profile]
|
||||
return tuple((left + (CONFIRMATION_PADDING + x) * scale, top + CONFIRMATION_HEADER * CONFIRMATION_SCALE[profile],
|
||||
left + (CONFIRMATION_PADDING + x + CONFIRMATION_BUTTON[profile]) * scale, bottom)
|
||||
for x in (0, CONFIRMATION_BUTTON[profile] + CONFIRMATION_GAP))
|
||||
|
||||
|
||||
@@ -347,7 +347,7 @@ def customization_metadata():
|
||||
|
||||
|
||||
def default_document():
|
||||
return {"version": 14, "clock24Hour": False, "reduceMotion": False, "palette": dict(PALETTE), "roadColors": {profile: {} for profile in PROFILES},
|
||||
return {"version": 15, "clock24Hour": False, "reduceMotion": False, "palette": dict(PALETTE), "roadColors": {profile: {} for profile in PROFILES},
|
||||
"widgetColors": {profile: {} for profile in PROFILES}, "layouts": {
|
||||
profile: {key: {**widget["default"], **({"size": WIDGET_SIZES[key][profile][1]} if key in WIDGET_SIZES else {})}
|
||||
for key, widget in data["widgets"].items()}
|
||||
@@ -421,6 +421,19 @@ def migrate_large_sign_layout(layout, bounds, *, widgets=None, extra_height=0):
|
||||
bounds['y'] + bounds['height'] - widgets['speed_limit_actions']['height'])
|
||||
|
||||
|
||||
# Attached action gaps below the card before the large speed group grew 1.3x: plain, inline sources, sources card.
|
||||
SMALL_CARD_ACTION_GAPS = (192, 284, 292)
|
||||
|
||||
|
||||
def migrate_attached_actions_gap(layout, bounds):
|
||||
"""Keep attached actions below the grown card; place_attached_slc_actions then adds any sources row."""
|
||||
card, actions = layout['cruise_limits'], layout['speed_limit_actions']
|
||||
if actions['x'] == card['x'] + ACTION_X - 88 and actions['y'] - card['y'] in SMALL_CARD_ACTION_GAPS:
|
||||
# Raise a low card so the moved actions still fit on screen and stay attached.
|
||||
card['y'] = min(card['y'], bounds['y'] + bounds['height'] - ACTION_HEIGHT - (ACTION_Y - 75))
|
||||
actions['y'] = card['y'] + ACTION_Y - 75
|
||||
|
||||
|
||||
def place_attached_slc_actions(layout, bounds, extra_height):
|
||||
card, actions = layout['cruise_limits'], layout['speed_limit_actions']
|
||||
if (actions['x'], actions['y']) == (card['x'] + ACTION_X - 88, card['y'] + ACTION_Y - 75):
|
||||
@@ -480,7 +493,7 @@ def migrate_confirmation_layout(layout, profile, widgets, bounds, *, extra_heigh
|
||||
|
||||
|
||||
def validate_document(value):
|
||||
if type(value) is not dict or type(value.get("version")) is not int or value["version"] not in range(1, 15):
|
||||
if type(value) is not dict or type(value.get("version")) is not int or value["version"] not in range(1, 16):
|
||||
raise ValueError("Invalid customization version")
|
||||
fields = {"version", "palette", "layouts"} | ({"widgetColors"} if value["version"] >= 2 else set())
|
||||
if value["version"] >= 3:
|
||||
@@ -729,6 +742,8 @@ def validate_document(value):
|
||||
migrate_speed_layout(result['layouts'][profile], profile, PROFILES[profile]['bounds'], old_gap)
|
||||
elif value['version'] == 8:
|
||||
migrate_speed_layout(result['layouts']['compact'], 'compact', PROFILES['compact']['bounds'], previous=COMPACT_SPEED_LAYOUT_V8)
|
||||
if value['version'] < 15:
|
||||
migrate_attached_actions_gap(result['layouts']['large'], PROFILES['large']['bounds'])
|
||||
if value['version'] < 11:
|
||||
for profile, data in PROFILES.items():
|
||||
actions = result['layouts'][profile]['speed_limit_actions']
|
||||
@@ -748,11 +763,11 @@ def validate_document(value):
|
||||
sign.update(x=LIMIT_RECTS['compact'][0], y=LIMIT_RECTS['compact'][1])
|
||||
if profile == 'large' and result.get('speedSources') is True:
|
||||
card, actions = result['layouts'][profile]['cruise_limits'], result['layouts'][profile]['speed_limit_actions']
|
||||
old_gap = 284 if value['version'] == 12 else ACTION_Y - 75 + SOURCE_ROW_HEIGHT
|
||||
old_gap = 284 if value['version'] == 12 else 192 + SOURCE_ROW_HEIGHT
|
||||
old_gap += GAP if result.get('speedSourcesCard') is True else 0
|
||||
if actions['x'] == card['x'] + ACTION_X - 88 and actions['y'] == card['y'] + old_gap:
|
||||
actions['y'] = card['y'] + ACTION_Y - 75
|
||||
if value['version'] < 14:
|
||||
if value['version'] < 15:
|
||||
migrate_confirmation_layout(result['layouts'][profile], profile, data['widgets'], data['bounds'],
|
||||
extra_height=sources_extent(result) if profile == 'large' else 0)
|
||||
elif not confirmation_layout_valid(result['layouts'][profile], profile, data['widgets'], data['bounds'],
|
||||
|
||||
@@ -333,6 +333,10 @@ def _inside_widget(x, y, state, widget, bounds):
|
||||
return left + dx <= x <= right + dx and top + dy <= y <= bottom + dy
|
||||
|
||||
|
||||
# Tap area above and below the sign, grown with the large sign so its tallest outline stays inside.
|
||||
SIGN_PADDING = {Profile.LARGE: (19, 26), Profile.COMPACT: (12, 8)}
|
||||
|
||||
|
||||
def speed_limit_bounds(profile: Profile, state: OnroadState) -> tuple[float, float, float, float] | None:
|
||||
from openpilot.starpilot.ui.unified_speed_presentation import displayed_limit_mps
|
||||
if (displayed_limit_mps(state.speed_limit) is None or
|
||||
@@ -347,7 +351,8 @@ def speed_limit_bounds(profile: Profile, state: OnroadState) -> tuple[float, flo
|
||||
else:
|
||||
x, y, width, height = LIMIT_RECTS[profile]
|
||||
dx, dy = offset(state.customization, profile, widget)
|
||||
bounds = x + dx - 12, y + dy - 12, x + dx + width + 12, y + dy + height + 8
|
||||
top, bottom = SIGN_PADDING[profile]
|
||||
bounds = x + dx - 12, y + dy - top, x + dx + width + 12, y + dy + height + bottom
|
||||
if profile == Profile.COMPACT and bounds[1] < 12:
|
||||
shift = 12 - bounds[1]
|
||||
bounds = bounds[0], bounds[1] + shift, bounds[2], bounds[3] + shift
|
||||
|
||||
@@ -60,8 +60,8 @@ class SpeedLimitShapes:
|
||||
rl.draw_texture_pro(self.texture, source, rl.Rectangle(x, y, source.width * scale * width_scale, source.height * scale),
|
||||
origin, rotation, color)
|
||||
|
||||
def circle(self, x, y, color):
|
||||
self._outlined('ring', x, y, color)
|
||||
def circle(self, x, y, color, *, scale=None):
|
||||
self._outlined('ring', x, y, color, scale=scale)
|
||||
|
||||
def _outlined(self, name, x, y, color, *, scale=None, width_scale=1):
|
||||
radius = self.scale if scale is None else scale
|
||||
@@ -80,15 +80,15 @@ class SpeedLimitShapes:
|
||||
for dx, dy in ((-1, 0), (1, 0), (0, -1), (0, 1), (0, 0)):
|
||||
self._draw('outline', x + dx * radius, y + dy * radius, color, scale=scale, width_scale=width_scale)
|
||||
|
||||
def in_use_ring(self, x, y, color):
|
||||
def in_use_ring(self, x, y, color, *, scale=None):
|
||||
"""A highlight ring around the red Vienna ring, whose outer edge is at radius 59.
|
||||
|
||||
A see-through gap keeps the green apart from the red, so it reads as a highlight
|
||||
around the sign rather than part of it, with the weight of the thick rectangular outline.
|
||||
"""
|
||||
center = rl.Vector2(x, y)
|
||||
rl.draw_ring(center, 61 * self.scale, 67.5 * self.scale, 0, 360, 96, rl.Color(6, 14, 10, 230))
|
||||
rl.draw_ring(center, 62 * self.scale, 66.5 * self.scale, 0, 360, 96, color)
|
||||
center, s = rl.Vector2(x, y), self.scale if scale is None else scale
|
||||
rl.draw_ring(center, 61 * s, 67.5 * s, 0, 360, 96, rl.Color(6, 14, 10, 230))
|
||||
rl.draw_ring(center, 62 * s, 66.5 * s, 0, 360, 96, color)
|
||||
|
||||
def button(self, x, y, color, *, profile, scale, pressed=False):
|
||||
self._draw(f'button_{profile}' + ('_pressed' if pressed else ''), x, y, color, scale=scale)
|
||||
|
||||
@@ -6,9 +6,10 @@ from typing import cast
|
||||
|
||||
from openpilot.starpilot.ui.raylib import rl
|
||||
|
||||
from openpilot.starpilot.ui.large_speed_geometry import LARGE_SIGN_SCALE, SIGN_WIDTH, SIGN_HEIGHT, CONFIRMATION_SCALE
|
||||
from openpilot.starpilot.ui.large_speed_geometry import LARGE_SIGN_SCALE, SIGN_WIDTH, SIGN_HEIGHT, CONFIRMATION_SCALE, PROMPT_SCALE
|
||||
from openpilot.starpilot.ui.onroad_customization import placement
|
||||
from openpilot.starpilot.ui.onroad_state import OnroadState, manual_slc_confirmation, speed_limit_bounds, slc_controls, slc_accept_available
|
||||
from openpilot.starpilot.ui.onroad_state import (SIGN_PADDING, OnroadState, manual_slc_confirmation, speed_limit_bounds, slc_controls,
|
||||
slc_accept_available)
|
||||
from openpilot.starpilot.ui.presentation import BitmapFonts, FontRole, Profile
|
||||
from openpilot.starpilot.ui.speed_limit_pulse import SpeedLimitPulse
|
||||
from openpilot.starpilot.ui.speed_limit_shapes import SpeedLimitShapes
|
||||
@@ -22,10 +23,17 @@ OVERRIDE = rl.Color(214, 188, 240, 255)
|
||||
REJECT = rl.Color(242, 139, 139, 255)
|
||||
SOURCE_LABELS = {'dashboard': 'DASH', 'map': 'OSM', 'vision': 'VISION', 'mapbox': 'NAV'}
|
||||
NUMBER_SIZE, HEADING_SIZE = 70, 26
|
||||
# Large UI labels (SET, source, offset, status) are read from further away than their numbers need.
|
||||
LABEL_SCALE = {Profile.LARGE: 36 / 26, Profile.COMPACT: 1.}
|
||||
# The large Vienna ring fills more of its tap area; text inside keeps its proportions to the ring.
|
||||
VIENNA_SCALE = 1.15
|
||||
# Ink-centered rows, shared by the portrait sign and the confirmation notice.
|
||||
HEADING_ROW, NUMBER_ROW = 16.75, 61
|
||||
# SET's label and number sit lower so they center on the sign beside them; its status still fits the card.
|
||||
SET_HEADING_ROW, SET_NUMBER_ROW, SET_STATUS_ROW = HEADING_ROW + 24, NUMBER_ROW + 24, 127
|
||||
# SET, the sign and the large new-limit notice put their number on this row below the card top,
|
||||
# so the numbers line up in every state and SET never moves.
|
||||
SHARED_NUMBER_ROW = 85
|
||||
SET_HEADING_ROW, SET_NUMBER_ROW = SHARED_NUMBER_ROW - (NUMBER_ROW - HEADING_ROW), SHARED_NUMBER_ROW
|
||||
SET_STATUS_ROW = SHARED_NUMBER_ROW + 40
|
||||
|
||||
|
||||
def draw_text(fonts, text, role, size, x, y, color=INK):
|
||||
@@ -60,7 +68,7 @@ def draw_speed_row(fonts, text, role, size, center, row, color, reference):
|
||||
def draw_set_speed(fonts, shown, center, top, color):
|
||||
scale = LARGE_SIGN_SCALE if fonts.profile == Profile.LARGE else 1.
|
||||
text_scale = scale * Profile.COMPACT.font_scale / fonts.profile.font_scale
|
||||
draw_speed_row(fonts, 'SET', FontRole.SEMI_BOLD, HEADING_SIZE * text_scale, center,
|
||||
draw_speed_row(fonts, 'SET', FontRole.SEMI_BOLD, HEADING_SIZE * LABEL_SCALE[fonts.profile] * text_scale, center,
|
||||
top + SET_HEADING_ROW * scale, color, 'SET')
|
||||
if shown.max_text == '–':
|
||||
draw_line(fonts.profile, rl.Vector2(center - 20 * scale, top + SET_NUMBER_ROW * scale),
|
||||
@@ -72,15 +80,19 @@ def draw_set_speed(fonts, shown, center, top, color):
|
||||
|
||||
def draw_set_status(fonts, label, center, top, color):
|
||||
scale = LARGE_SIGN_SCALE if fonts.profile == Profile.LARGE else 1.
|
||||
size = 22 * scale * Profile.COMPACT.font_scale / fonts.profile.font_scale
|
||||
size = 22 * LABEL_SCALE[fonts.profile] * scale * Profile.COMPACT.font_scale / fonts.profile.font_scale
|
||||
left, right = fonts.horizontal_ink(label, FontRole.MEDIUM, size)
|
||||
size *= min(1, 108 * scale / max(1, right - left))
|
||||
# Stay inside SET's column, 92 px either side of its center.
|
||||
size *= min(1, min(108 * scale, 176) / max(1, right - left))
|
||||
draw_speed_row(fonts, label, FontRole.MEDIUM, size, center, top + SET_STATUS_ROW * scale, color, label)
|
||||
|
||||
|
||||
def speed_status(shown):
|
||||
"""The only status SET shows: the driver's chosen speed winning over the limit."""
|
||||
return None if shown.override_text is None else f'OVERRIDE {shown.override_text}'
|
||||
if shown.override_text is None:
|
||||
return None
|
||||
# SET shows the held speed right above; only a different one, such as a pedal override's, needs repeating.
|
||||
return 'OVERRIDE' if shown.override_text == shown.max_text else f'OVERRIDE {shown.override_text}'
|
||||
|
||||
|
||||
def set_speed_status(state, profile, shown):
|
||||
@@ -128,7 +140,7 @@ class SpeedLimitWidget:
|
||||
return
|
||||
now = state.observed_ns / 1e9 if state.observed_ns else time.monotonic()
|
||||
self.pulse.update(state, now)
|
||||
scale = CONFIRMATION_SCALE[self.profile]
|
||||
scale = (PROMPT_SCALE if state.slc_prompt_open else CONFIRMATION_SCALE)[self.profile]
|
||||
x, y, right, _ = bounds
|
||||
width = (right - x) / scale
|
||||
shown = resolve_unified_speed(state, confirmation=True)
|
||||
@@ -186,11 +198,14 @@ class SpeedLimitWidget:
|
||||
|
||||
content_top = y + (12 if self.profile == Profile.LARGE else 8)
|
||||
row_origin = (content_top - y) / scale
|
||||
caption_row, hint_row = (112, 142) if self.profile == Profile.LARGE else (110, 136.75)
|
||||
large = self.profile == Profile.LARGE
|
||||
heading_row, number_row = (SET_HEADING_ROW, SHARED_NUMBER_ROW) if large else (HEADING_ROW, NUMBER_ROW)
|
||||
caption_row, hint_row = (131, 161) if large else (110, 136.75)
|
||||
source_color = rl.Color(197, 212, 208, 255)
|
||||
if current_status:
|
||||
source += f' / {current_status}'
|
||||
label_size = HEADING_SIZE * min(1, (width - 40) / max(1, ink_width(source, HEADING_SIZE, FontRole.SEMI_BOLD)))
|
||||
heading = HEADING_SIZE * LABEL_SCALE[self.profile]
|
||||
label_size = heading * min(1, (width - 40) / max(1, ink_width(source, heading, FontRole.SEMI_BOLD)))
|
||||
label_width = ink_width(source, label_size, FontRole.SEMI_BOLD)
|
||||
target = state.speed_limit.pending_adjusted_limit_mps
|
||||
if not positive(target):
|
||||
@@ -198,22 +213,23 @@ class SpeedLimitWidget:
|
||||
direction = (-1 if target > state.speed_mps else 1) if target is not None and state.speed_mps is not None and target != state.speed_mps else 0
|
||||
start = (width - label_width - (19.2 if direction else 0)) / 2
|
||||
draw_speed_row(self.fonts, source, FontRole.SEMI_BOLD, text_size(label_size),
|
||||
x + (start + label_width / 2) * scale, content_top + HEADING_ROW * scale, source_color, source)
|
||||
x + (start + label_width / 2) * scale, content_top + heading_row * scale, source_color, source)
|
||||
if direction:
|
||||
self.shapes.arrow('compact', x + (start + label_width + 12.6) * scale, content_top + (HEADING_ROW + .5) * scale,
|
||||
self.shapes.arrow('compact', x + (start + label_width + 12.6) * scale, content_top + (heading_row + .5) * scale,
|
||||
direction, source_color, scale=1.1 * scale)
|
||||
nw = ink_width(shown.posted_text, NUMBER_SIZE, FontRole.SET_SPEED)
|
||||
ow = ink_width(shown.offset_text, 32) if shown.offset_text else 0
|
||||
offset_size = 32 * LABEL_SCALE[self.profile]
|
||||
ow = ink_width(shown.offset_text, offset_size) if shown.offset_text else 0
|
||||
start = (width - nw - (10 + ow if ow else 0)) / 2
|
||||
draw_speed_row(self.fonts, shown.posted_text, FontRole.SET_SPEED, text_size(NUMBER_SIZE),
|
||||
x + (start + nw / 2) * scale, content_top + NUMBER_ROW * scale, white, '0123456789')
|
||||
x + (start + nw / 2) * scale, content_top + number_row * scale, white, '0123456789')
|
||||
if ow:
|
||||
offset_text = cast(str, shown.offset_text)
|
||||
ref_top, ref_bottom = self.fonts.vertical_ink('0123456789', FontRole.SET_SPEED, text_size(NUMBER_SIZE))
|
||||
_, ink_bottom = self.fonts.vertical_ink(shown.posted_text, FontRole.SET_SPEED, text_size(NUMBER_SIZE))
|
||||
number_bottom = row_origin + NUMBER_ROW + (ink_bottom - (ref_top + ref_bottom) / 2) / scale
|
||||
top, bottom = self.fonts.vertical_ink(offset_text, FontRole.MEDIUM, text_size(32))
|
||||
text(offset_text, 32, start + nw + 10 + ow / 2, number_bottom - (bottom - top) / scale / 2, secondary)
|
||||
number_bottom = row_origin + number_row + (ink_bottom - (ref_top + ref_bottom) / 2) / scale
|
||||
top, bottom = self.fonts.vertical_ink(offset_text, FontRole.MEDIUM, text_size(offset_size))
|
||||
text(offset_text, offset_size, start + nw + 10 + ow / 2, number_bottom - (bottom - top) / scale / 2, secondary)
|
||||
label = 'NEW LIMIT' if slc_accept_available(state) else 'Unavailable'
|
||||
caption = ink_width(label, 30, FontRole.SEMI_BOLD)
|
||||
cx = (width - caption - 10) / 2
|
||||
@@ -240,8 +256,9 @@ class SpeedLimitWidget:
|
||||
heading = SOURCE_LABELS.get(shown.source, 'SPEED')
|
||||
if shown.show_last and self.profile == Profile.LARGE:
|
||||
heading = f'LAST {heading}' if heading != 'SPEED' else 'LAST'
|
||||
x, top = bounds[0] + 12, bounds[1] + 12
|
||||
scale = self.scale
|
||||
x, top = bounds[0] + 12, bounds[1] + SIGN_PADDING[self.profile][0]
|
||||
card_top, large = top, self.profile == Profile.LARGE
|
||||
scale, text_scale = self.scale, self.text_scale
|
||||
center_x = SIGN_WIDTH / 2
|
||||
pending = shown.pending and not obs.automatic_adoption_pending
|
||||
target = displayed_adjusted_limit_mps(obs) if pending and not shown.posted_retained else None
|
||||
@@ -252,15 +269,15 @@ class SpeedLimitWidget:
|
||||
secondary = self.pulse.color(rl.Color(223, 232, 227, 255), now)
|
||||
|
||||
def ink(text, role, size):
|
||||
return tuple(value / scale for value in (*self.fonts.horizontal_ink(text, role, size * self.text_scale),
|
||||
*self.fonts.vertical_ink(text, role, size * self.text_scale)))
|
||||
return tuple(value / scale for value in (*self.fonts.horizontal_ink(text, role, size * text_scale),
|
||||
*self.fonts.vertical_ink(text, role, size * text_scale)))
|
||||
|
||||
def centered(text, role, size, ink_top, color, cx=None):
|
||||
left, right, a, b = ink(text, role, size)
|
||||
# Snap only the final draw, after fitting the visible glyphs inside the sign.
|
||||
origin = round(x + ((center_x if cx is None else cx) - (left + right) / 2) * scale)
|
||||
y = round(top + (ink_top - a) * scale)
|
||||
draw_text(self.fonts, text, role, size * self.text_scale, origin, y, color)
|
||||
draw_text(self.fonts, text, role, size * text_scale, origin, y, color)
|
||||
return origin + left * scale, y + a * scale, origin + right * scale, y + b * scale
|
||||
|
||||
vienna_center_y = 67
|
||||
@@ -273,33 +290,47 @@ class SpeedLimitWidget:
|
||||
color = white
|
||||
# Clamping the controller target does not configure an offset for this sign.
|
||||
offset_text = shown.offset_text if vienna or shown.offset_configured else None
|
||||
# Lift the Vienna stack to keep the offset clear of the bottom rim.
|
||||
lift = (7 if offset_text else 2) if vienna else 0
|
||||
# Large signs share one set of rows with or without an offset; compact keeps its own taller-or-centered rows.
|
||||
header_y = 47 - lift if vienna else 21 if offset_text or large else 26
|
||||
number_center = (73 if offset_text else 80) - lift if vienna else 76 if offset_text or large else 90
|
||||
# The outline alone marks the limit being followed; it is drawn thicker so it reads at a glance.
|
||||
if vienna:
|
||||
x, top = x + 5 * scale, top + 5 * scale
|
||||
if large:
|
||||
# A larger ring in the US sign's column, placed so its number sits on the shared row.
|
||||
scale, text_scale = scale * VIENNA_SCALE, text_scale * VIENNA_SCALE
|
||||
x = bounds[0] + 12 + SIGN_WIDTH / 2 * self.scale - 59 * scale
|
||||
top = card_top + SHARED_NUMBER_ROW * self.scale - number_center * scale
|
||||
else:
|
||||
x, top = x + 5 * scale, top + 5 * scale
|
||||
center_x = 59
|
||||
if shown.limit_in_use:
|
||||
self.shapes.in_use_ring(x + 59 * scale, top + vienna_center_y * scale, IN_USE)
|
||||
self.shapes.circle(x + 59 * scale, top + vienna_center_y * scale, self.pulse.color(rl.Color(201, 34, 49, 255), now))
|
||||
self.shapes.in_use_ring(x + 59 * scale, top + vienna_center_y * scale, IN_USE, scale=scale)
|
||||
self.shapes.circle(x + 59 * scale, top + vienna_center_y * scale, self.pulse.color(rl.Color(201, 34, 49, 255), now), scale=scale)
|
||||
else:
|
||||
# Keep 4:5 proportions and the original text sizes inside the existing tap area.
|
||||
sign_scale = (160 if offset_text else 150) / SIGN_HEIGHT
|
||||
if self.profile == Profile.LARGE:
|
||||
# Center either height on its tap area, level with SET; the text rows below move with the outline.
|
||||
top += (bounds[1] + bounds[3]) / 2 - (top + (SIGN_HEIGHT * sign_scale / 2 - 9) * scale)
|
||||
outline_row = SIGN_HEIGHT * sign_scale / 2 - 9
|
||||
if large:
|
||||
# The number sits on the shared row; without an offset the outline centers on the heading and number.
|
||||
top = card_top + (SHARED_NUMBER_ROW - number_center) * scale
|
||||
outline_row = outline_row if offset_text else 54.5
|
||||
draw = self.shapes.thick_outline if shown.limit_in_use else self.shapes.outline
|
||||
draw(x + center_x * scale, top + (SIGN_HEIGHT * sign_scale / 2 - 9) * scale, IN_USE if shown.limit_in_use else white,
|
||||
draw(x + center_x * scale, top + outline_row * scale, IN_USE if shown.limit_in_use else white,
|
||||
scale=scale * sign_scale, width_scale=SIGN_HEIGHT * 4 / 5 / SIGN_WIDTH)
|
||||
|
||||
heading_size = HEADING_SIZE if not vienna else 18
|
||||
if vienna and self.profile == Profile.LARGE and not shown.pending:
|
||||
heading_size = 21
|
||||
if not vienna:
|
||||
heading_size *= LABEL_SCALE[self.profile]
|
||||
left, right, a, b = ink(heading, FontRole.SEMI_BOLD, heading_size)
|
||||
if not vienna and right - left > 108:
|
||||
heading_size *= 108 / (right - left)
|
||||
# Leave room for a pending limit's arrow (12 wide plus a 6 gap) beside the heading.
|
||||
fit = 108 - (18 if arrow_direction else 0)
|
||||
if not vienna and right - left > fit:
|
||||
heading_size *= fit / (right - left)
|
||||
left, right, a, b = ink(heading, FontRole.SEMI_BOLD, heading_size)
|
||||
# Lift the Vienna stack to keep the offset clear of the bottom rim.
|
||||
lift = (7 if offset_text else 2) if vienna else 0
|
||||
header_y = 47 - lift if vienna else 21 if offset_text else 26
|
||||
arrow_scale = 1.
|
||||
if vienna:
|
||||
# Fit the heading and arrow inside the circle at the top of their ink.
|
||||
@@ -322,8 +353,8 @@ class SpeedLimitWidget:
|
||||
|
||||
role = FontRole.BOLD if vienna else FontRole.SET_SPEED
|
||||
size = 58 if vienna else NUMBER_SIZE
|
||||
offset_size = 30 if vienna else 27
|
||||
number_center = (73 if offset_text else 80) - lift if vienna else 76 if offset_text else 90
|
||||
# The Vienna ring is fixed, so larger labels there would shrink the number; only US labels grow.
|
||||
offset_size = 30 if vienna else 27 * LABEL_SCALE[self.profile]
|
||||
while True:
|
||||
left, right, a, b = ink(shown.posted_text, role, size)
|
||||
width, height = right - left, b - a
|
||||
@@ -344,7 +375,7 @@ class SpeedLimitWidget:
|
||||
if vienna:
|
||||
centered(shown.posted_text, role, size, number_top, color)
|
||||
else:
|
||||
draw_speed_row(self.fonts, shown.posted_text, role, size * self.text_scale, x + center_x * scale,
|
||||
draw_speed_row(self.fonts, shown.posted_text, role, size * text_scale, x + center_x * scale,
|
||||
top + number_center * scale, color, '0123456789')
|
||||
if offset_text:
|
||||
if not vienna:
|
||||
|
||||
@@ -626,7 +626,7 @@ class AppearanceSettingsTests(unittest.TestCase):
|
||||
from openpilot.starpilot.ui.tests.test_unified_speed_native import foreground_calls
|
||||
x, y = foreground_calls(fonts.draw)[0].args[3:5]
|
||||
self.assertAlmostEqual(x, 175)
|
||||
self.assertAlmostEqual(y, 118.27, places=2) # SET centers on the sign beside it
|
||||
self.assertAlmostEqual(y, 125.55, places=2) # SET centers on the sign beside it
|
||||
for profile in (Profile.LARGE, Profile.COMPACT):
|
||||
view = onroad.OnroadView.__new__(onroad.OnroadView)
|
||||
view._fade = Mock()
|
||||
|
||||
@@ -7,7 +7,7 @@ import pytest
|
||||
from openpilot.starpilot.ui.large_speed_geometry import LARGE_SIGN_SCALE, SIGN_WIDTH, SIGN_HEIGHT
|
||||
from openpilot.starpilot.ui.onroad_state import speed_limit_bounds, slc_controls, SpeedLimitObservation, ObservationKind
|
||||
from openpilot.starpilot.ui.presentation import Profile
|
||||
from openpilot.starpilot.ui.speed_limit_widget import SpeedLimitWidget
|
||||
from openpilot.starpilot.ui.speed_limit_widget import LABEL_SCALE, SpeedLimitWidget
|
||||
from openpilot.starpilot.ui.tests.test_unified_speed_native import foreground_calls, fonts, state as pending_state
|
||||
from openpilot.starpilot.ui.unified_speed_presentation import resolve_unified_speed
|
||||
|
||||
@@ -47,8 +47,13 @@ def test_sign_layout_and_tap_area_stay_fixed_with_or_without_offset(profile, off
|
||||
historical_outline.assert_not_called()
|
||||
widget.shapes.outline.assert_called_once()
|
||||
sign_scale = (160 if offset else 150) / SIGN_HEIGHT
|
||||
# Large centers either sign height on its tap area beside SET; compact keeps its top-anchored sign.
|
||||
center = (bounds[1]+bounds[3])/2 if profile == Profile.LARGE else bounds[1]+12+(SIGN_HEIGHT*sign_scale/2-9)*scale
|
||||
if profile == Profile.LARGE:
|
||||
# The number sits on SET's shared row; without an offset the outline centers on the heading and number.
|
||||
from openpilot.starpilot.ui.onroad_state import SIGN_PADDING
|
||||
from openpilot.starpilot.ui.speed_limit_widget import SHARED_NUMBER_ROW
|
||||
center = bounds[1]+SIGN_PADDING[profile][0]+(SHARED_NUMBER_ROW-76+(SIGN_HEIGHT*sign_scale/2-9 if offset else 54.5))*scale
|
||||
else:
|
||||
center = bounds[1]+12+(SIGN_HEIGHT*sign_scale/2-9)*scale
|
||||
assert widget.shapes.outline.call_args.args[:2] == pytest.approx((bounds[0]+12+SIGN_WIDTH/2*scale, center))
|
||||
assert widget.shapes.outline.call_args.kwargs == {'scale': scale * sign_scale, 'width_scale': .9}
|
||||
assert ('+5' in [call.args[0] for call in foreground_calls(widget.fonts.draw)]) == offset
|
||||
@@ -172,7 +177,11 @@ def test_mutcd_preserves_text_sizes_and_fits_both_sizes_with_real_fonts(profile)
|
||||
if text.startswith('LAST '):
|
||||
assert right - left == pytest.approx(108 * widget.scale)
|
||||
else:
|
||||
assert size == pytest.approx({FontRole.SEMI_BOLD: 26, FontRole.SET_SPEED: 70, FontRole.MEDIUM: 27}[role] * widget.text_scale)
|
||||
nominal = {FontRole.SEMI_BOLD: 26, FontRole.SET_SPEED: 70, FontRole.MEDIUM: 27}[role] * widget.text_scale
|
||||
if role == FontRole.SET_SPEED:
|
||||
assert size == pytest.approx(nominal)
|
||||
else: # Large labels are larger, shrinking only to fit the sign.
|
||||
assert nominal - 1e-6 <= size <= nominal * LABEL_SCALE[profile] + 1e-6
|
||||
boxes.append((x + left, y + top, x + right, y + bottom))
|
||||
assert cx - half_width + 1 <= min(box[0] for box in boxes)
|
||||
assert max(box[2] for box in boxes) <= cx + half_width - 1
|
||||
|
||||
@@ -101,9 +101,10 @@ def test_large_set_and_limit_share_typography_at_the_saved_position():
|
||||
assert right-left <= 108*LARGE_SIGN_SCALE
|
||||
assert abs(posted[3] + (left + right) / 2 - (418 + SIGN_WIDTH/2*LARGE_SIGN_SCALE)) <= .5
|
||||
a, b = fonts.vertical_ink('120', FontRole.SET_SPEED, posted[2])
|
||||
assert 60 <= b - a <= 70
|
||||
# The posted sign keeps its own rows; with an offset its number is centered on row 76.
|
||||
assert abs(posted[4]+(a+b)/2-(95+76*LARGE_SIGN_SCALE)) <= .5
|
||||
assert 60 * 1.3 <= b - a <= 70 * 1.3 # 1.3x the compact display's physical size
|
||||
# SET and the sign put their numbers on one shared row below the card top (y=95 here).
|
||||
from openpilot.starpilot.ui.speed_limit_widget import SHARED_NUMBER_ROW
|
||||
assert abs(posted[4]+(a+b)/2-(95+SHARED_NUMBER_ROW*LARGE_SIGN_SCALE)) <= .5
|
||||
assert {'DASH', '+10'} <= {call[0] for call in calls} and 'LIMIT' not in {call[0] for call in calls}
|
||||
set_calls = [call for call in calls if call[1] == FontRole.SET_SPEED and call[3] < 388]
|
||||
assert bool(set_calls) == (show_set and value is not None)
|
||||
@@ -241,7 +242,9 @@ def test_status_below_set_has_real_ink_clearance_and_fits_its_widget():
|
||||
widget.render_max_speed(current)
|
||||
rows = [row for row in calls if row[-1].a > 0 and (row[-1].r, row[-1].g, row[-1].b) not in ((0, 0, 0), (6, 14, 10), (7, 16, 12))]
|
||||
number = next(row for row in rows if row[0] == str(set_speed) and row[1] == FontRole.SET_SPEED)
|
||||
caption = next(row for row in rows if row[0] == (status if profile == Profile.LARGE else 'MAX'))
|
||||
# The status repeats the held speed only when it differs from SET.
|
||||
shown_status = 'OVERRIDE' if set_speed == 100 else status
|
||||
caption = next(row for row in rows if row[0] == (shown_status if profile == Profile.LARGE else 'MAX'))
|
||||
if profile == Profile.COMPACT:
|
||||
assert status not in [row[0] for row in rows]
|
||||
bottom = number[4] + fonts.vertical_ink(*number[:3])[1]
|
||||
@@ -251,8 +254,12 @@ def test_status_below_set_has_real_ink_clearance_and_fits_its_widget():
|
||||
saved = placement(current.customization, profile, key)
|
||||
width, height = widget_size(current.customization, profile, key)
|
||||
assert caption[4] + fonts.vertical_ink(*caption[:3])[1] <= saved['y'] + height - 12
|
||||
scale = LARGE_SIGN_SCALE if profile == Profile.LARGE else 1
|
||||
assert (16 <= caption[2] * profile.font_scale / Profile.COMPACT.font_scale / scale <= 22 + 1e-9) if profile == Profile.LARGE else caption[2] == 36
|
||||
# The status grew with the large labels but is width-capped to SET's column; measure it physically.
|
||||
from openpilot.starpilot.ui.large_speed_geometry import PHYSICAL_SCALE
|
||||
from openpilot.starpilot.ui.speed_limit_widget import LABEL_SCALE
|
||||
scale = PHYSICAL_SCALE if profile == Profile.LARGE else 1
|
||||
nominal = caption[2] * profile.font_scale / Profile.COMPACT.font_scale / scale
|
||||
assert (16 <= nominal <= 22 * 1.3 * LABEL_SCALE[profile] + 1e-9) if profile == Profile.LARGE else caption[2] == 36
|
||||
left, right = fonts.horizontal_ink(*caption[:3])
|
||||
number_left, number_right = fonts.horizontal_ink(*number[:3])
|
||||
if profile == Profile.COMPACT:
|
||||
@@ -549,6 +556,9 @@ def test_source_card_action_sprite_contains_both_actual_button_rows():
|
||||
|
||||
|
||||
def test_both_sign_styles_contain_text_and_arrows_at_each_profile_scale():
|
||||
from openpilot.starpilot.ui.onroad_state import SIGN_PADDING
|
||||
from openpilot.starpilot.ui.speed_limit_widget import LABEL_SCALE, VIENNA_SCALE
|
||||
from openpilot.starpilot.ui.unified_speed_presentation import resolve_unified_speed
|
||||
from unittest.mock import patch
|
||||
from openpilot.starpilot.ui.speed_limit_widget import SpeedLimitWidget
|
||||
from openpilot.starpilot.ui.tests.test_unified_speed_native import state
|
||||
@@ -591,7 +601,12 @@ def test_both_sign_styles_contain_text_and_arrows_at_each_profile_scale():
|
||||
last_received_source=source, last_received_adjusted_limit_mps=(posted+offset)/3.6))
|
||||
bounds = speed_limit_bounds(profile, current)
|
||||
assert bounds is not None
|
||||
x, y = bounds[0] + 12, bounds[1] + 12
|
||||
x, y = bounds[0] + 12, bounds[1] + SIGN_PADDING[profile][0]
|
||||
shown = resolve_unified_speed(current)
|
||||
from openpilot.starpilot.ui.speed_limit_widget import SHARED_NUMBER_ROW
|
||||
if profile == Profile.LARGE and not vienna:
|
||||
# The large US sign's rows are placed so its number (row 76) sits on SET's shared row.
|
||||
y += (SHARED_NUMBER_ROW - 76) * scale
|
||||
calls = []
|
||||
with patch.object(fonts, 'draw', lambda *args, sink=calls: sink.append(args)), \
|
||||
patch.object(widget.shapes, 'arrow') as arrow_draw:
|
||||
@@ -605,8 +620,12 @@ def test_both_sign_styles_contain_text_and_arrows_at_each_profile_scale():
|
||||
c, d = fonts.vertical_ink(text, role, size)
|
||||
box = left+a, top+c, left+b, top+d
|
||||
if vienna:
|
||||
cx, cy = x+64*scale, y+72*scale
|
||||
assert all((px-cx)**2+(py-cy)**2 <= (47*scale)**2
|
||||
ring = scale * (VIENNA_SCALE if profile == Profile.LARGE else 1)
|
||||
cx = x+64*scale
|
||||
# The large ring sits so its number (row 66, or 78 without an offset) is on SET's shared row.
|
||||
number_row = 66 if shown.offset_text else 78
|
||||
cy = y + SHARED_NUMBER_ROW*scale + (67 - number_row)*ring if profile == Profile.LARGE else y+72*scale
|
||||
assert all((px-cx)**2+(py-cy)**2 <= (47*ring)**2
|
||||
for px, py in product((box[0], box[2]), (box[1], box[3]))), case
|
||||
expected = widget.pulse.color(rl.Color(244, 247, 245, 255), current.observed_ns / 1e9)
|
||||
assert (color.r, color.g, color.b, color.a) == (expected.r, expected.g, expected.b, expected.a), case
|
||||
@@ -615,7 +634,8 @@ def test_both_sign_styles_contain_text_and_arrows_at_each_profile_scale():
|
||||
assert x+5*scale <= box[0] < box[2] <= x+123*scale, case
|
||||
assert y+7*scale <= box[1] < box[3] <= y+137*scale, case
|
||||
ink.append((text, box))
|
||||
nominal_size = size/widget.text_scale
|
||||
label = 1 if role in (FontRole.BOLD, FontRole.SET_SPEED) else LABEL_SCALE[profile]
|
||||
nominal_size = size/widget.text_scale / (VIENNA_SCALE if vienna and profile == Profile.LARGE else label)
|
||||
if role == FontRole.BOLD:
|
||||
assert 20 <= nominal_size <= (58 if vienna else 64)+.01, case
|
||||
elif role == FontRole.MEDIUM:
|
||||
@@ -632,13 +652,13 @@ def test_both_sign_styles_contain_text_and_arrows_at_each_profile_scale():
|
||||
left, top, right, bottom = glyph if direction>0 else (-glyph[2], -glyph[3], -glyph[0], -glyph[1])
|
||||
arrow = ax+left*arrow_scale, ay+top*arrow_scale, ax+right*arrow_scale, ay+bottom*arrow_scale
|
||||
label = next(box for text, box in ink if text == heading)
|
||||
assert abs(arrow[0] - label[2] - 6*scale) <= 1, case
|
||||
assert abs(arrow[0] - label[2] - 6*scale*(VIENNA_SCALE if vienna and profile == Profile.LARGE else 1)) <= 1, case
|
||||
assert abs((label[0] + arrow[2]) / 2 - (x+64*scale)) <= .5, case
|
||||
assert abs((label[1] + label[3]) / 2 - (arrow[1] + arrow[3]) / 2) <= 1, case
|
||||
if vienna:
|
||||
# The arrow's transparent bounding-box corners are not painted ink.
|
||||
pixels = painted_pixels[size] * (arrow_scale if direction > 0 else -arrow_scale) + (ax, ay)
|
||||
assert np.all(np.linalg.norm(pixels-(cx, cy), axis=1) <= 47*scale), case
|
||||
assert np.all(np.linalg.norm(pixels-(cx, cy), axis=1) <= 47*ring), case
|
||||
assert .95*(label[3]-label[1]) <= arrow[3]-arrow[1] <= 1.25*(label[3]-label[1]), case
|
||||
else:
|
||||
assert x+7*scale <= arrow[0] < arrow[2] <= x+121*scale, case
|
||||
@@ -657,7 +677,7 @@ def test_both_sign_styles_contain_text_and_arrows_at_each_profile_scale():
|
||||
|
||||
def test_sign_profiles_share_layout_and_keep_aligned_numbers():
|
||||
from unittest.mock import Mock, patch
|
||||
from openpilot.starpilot.ui.speed_limit_widget import SpeedLimitWidget
|
||||
from openpilot.starpilot.ui.speed_limit_widget import LABEL_SCALE, VIENNA_SCALE, SpeedLimitWidget
|
||||
from openpilot.starpilot.ui.tests.test_unified_speed_native import state
|
||||
owns_context = not rl.is_window_ready()
|
||||
if owns_context:
|
||||
@@ -680,14 +700,16 @@ def test_sign_profiles_share_layout_and_keep_aligned_numbers():
|
||||
calls = [call for call in calls if call[-1].a == 255]
|
||||
assert all(float(call[3]).is_integer() and float(call[4]).is_integer()
|
||||
for call in calls if call[1] != FontRole.SET_SPEED)
|
||||
# Large Vienna text grows with its ring; large US labels grow by LABEL_SCALE.
|
||||
heading = calls[0][2] / widget.text_scale / ((VIENNA_SCALE if fonts.profile == Profile.LARGE else 1) if vienna else LABEL_SCALE[fonts.profile])
|
||||
if not vienna:
|
||||
assert calls[0][2]/widget.text_scale <= 28
|
||||
assert heading <= 28
|
||||
elif fonts.profile == Profile.LARGE and not pending:
|
||||
assert 18 <= calls[0][2] / widget.text_scale <= 21
|
||||
assert 18 <= heading <= 21
|
||||
elif vienna and pending and source == 'vision':
|
||||
assert 14 <= round(calls[0][2] / widget.text_scale) <= 18
|
||||
assert 14 <= round(heading) <= 18
|
||||
else:
|
||||
assert abs(calls[0][2]/widget.text_scale-18) < 1e-9
|
||||
assert abs(heading-18) < 1e-9
|
||||
drawn.append((widget, calls))
|
||||
small_widget, small_calls = drawn[0]
|
||||
large_widget, large_calls = drawn[1]
|
||||
@@ -699,10 +721,21 @@ def test_sign_profiles_share_layout_and_keep_aligned_numbers():
|
||||
assert small_calls[1][1] == large_calls[1][1] == FontRole.SET_SPEED
|
||||
start = int(vienna and not pending)
|
||||
for a, b in zip(small_calls[start:], large_calls[start:], strict=True):
|
||||
assert abs(a[2]/small_widget.text_scale-b[2]/large_widget.text_scale) < 1e-9
|
||||
assert abs((a[3]-320)-(b[3]-318)/LARGE_SIGN_SCALE) <= 1
|
||||
assert abs((a[4]-small_center)-(b[4]-large_center)/LARGE_SIGN_SCALE) <= 1
|
||||
# The large Vienna ring and everything in it are VIENNA_SCALE larger.
|
||||
ring = VIENNA_SCALE if vienna else 1
|
||||
small_size, large_size = a[2]/small_widget.text_scale, b[2]/large_widget.text_scale/ring
|
||||
assert (a[-1].r, a[-1].g, a[-1].b, a[-1].a) == (b[-1].r, b[-1].g, b[-1].b, b[-1].a)
|
||||
if vienna or a[1] in (FontRole.SET_SPEED, FontRole.BOLD):
|
||||
# Numbers, and all Vienna text, share size and position relative to the sign on both profiles.
|
||||
assert abs(small_size-large_size) < 1e-9
|
||||
small_x, large_x = (fonts_x + sum(f.horizontal_ink(*call[:3])) / 2 for f, fonts_x, call in ((small, a[3], a), (large, b[3], b)))
|
||||
assert abs((small_x-320-64)-(large_x-318-64*LARGE_SIGN_SCALE)/LARGE_SIGN_SCALE/ring) <= 1
|
||||
# Except the large no-offset US sign, whose outline centers on its text rather than its 150-unit box.
|
||||
if vienna or offset:
|
||||
assert abs((a[4]+sum(small.vertical_ink(*a[:3]))/2-small_center)-(b[4]+sum(large.vertical_ink(*b[:3]))/2-large_center)/LARGE_SIGN_SCALE/ring) <= 1
|
||||
else:
|
||||
# Large labels are up to LABEL_SCALE larger, less when they shrink to fit the sign.
|
||||
assert small_size - 1e-9 <= large_size <= small_size * LABEL_SCALE[Profile.LARGE] + 1e-9
|
||||
if pending:
|
||||
for widget in (small_widget, large_widget):
|
||||
asset, x, y, _, _ = widget.shapes.arrow.call_args.args
|
||||
@@ -722,7 +755,7 @@ def test_v5_geometry_migrates_and_keeps_custom_actions_independent():
|
||||
doc['layouts']['large']['cruise_limits'].update(x=1550, y=638)
|
||||
doc['layouts']['large']['speed_limit_actions'].update(x=1550, y=954)
|
||||
migrated = validate_document(doc)
|
||||
assert migrated['version'] == 14
|
||||
assert migrated['version'] == 15
|
||||
assert migrated['layouts']['large']['cruise_limits'] == default_document()['layouts']['large']['cruise_limits']
|
||||
assert migrated['layouts']['large']['speed_limit_actions'] == {'x': 1550, 'y': 882, 'enabled': True}
|
||||
assert migrated['speedSources'] is True
|
||||
@@ -730,7 +763,7 @@ def test_v5_geometry_migrates_and_keeps_custom_actions_independent():
|
||||
assert validate_document(migrated) == migrated
|
||||
doc['layouts']['large']['cruise_limits'].update(x=88, y=75)
|
||||
doc['layouts']['large']['speed_limit_actions'].update(x=88, y=447)
|
||||
assert validate_document(doc)['layouts']['large']['speed_limit_actions']['y'] == 381
|
||||
assert validate_document(doc)['layouts']['large']['speed_limit_actions']['y'] == 449
|
||||
|
||||
|
||||
def test_pending_choices_use_the_sign_with_separated_horizontal_targets():
|
||||
@@ -749,8 +782,8 @@ def test_projection_v1_layout_migrates_without_losing_other_widgets():
|
||||
doc['widgets']['speed_limit_actions'].update(x=88, y=447)
|
||||
doc['widgets']['current_speed'].update(x=1400, y=100)
|
||||
migrated = validate_layout_for_viewport(doc, viewport)
|
||||
assert migrated['version'] == 6
|
||||
assert migrated['widgets']['speed_limit_actions']['y'] == 267
|
||||
assert migrated['version'] == 7
|
||||
assert migrated['widgets']['speed_limit_actions']['y'] == 325
|
||||
assert migrated['widgets']['current_speed'] == doc['widgets']['current_speed']
|
||||
assert validate_layout_for_viewport(migrated, viewport) == migrated
|
||||
|
||||
@@ -772,7 +805,7 @@ def test_committed_projection_v1_right_edge_is_preserved_and_clamped():
|
||||
@pytest.mark.parametrize('wheel_confirmation', [False, True])
|
||||
def test_chooser_binds_the_target_to_accept_and_keeps_all_native_ink_inside_its_control(wheel_confirmation):
|
||||
from unittest.mock import patch
|
||||
from openpilot.starpilot.ui.large_speed_geometry import CONFIRMATION_SCALE
|
||||
from openpilot.starpilot.ui.large_speed_geometry import PROMPT_SCALE
|
||||
from openpilot.starpilot.ui.speed_limit_widget import SpeedLimitWidget
|
||||
from openpilot.starpilot.ui.speed_limit_shapes import ATLAS_PATH, SPRITES, SPRITE_DENSITIES
|
||||
from openpilot.starpilot.ui.tests.test_slc_ui_actions import state
|
||||
@@ -781,7 +814,8 @@ def test_chooser_binds_the_target_to_accept_and_keeps_all_native_ink_inside_its_
|
||||
rl.init_window(128, 128, 'Confirmation typography fixture')
|
||||
try:
|
||||
for profile in Profile:
|
||||
scale = CONFIRMATION_SCALE[profile]
|
||||
# The open prompt is drawn at finger size, the device's physical scale.
|
||||
scale = PROMPT_SCALE[profile]
|
||||
with BitmapFonts(profile, default_font_directory()) as fonts:
|
||||
widget = SpeedLimitWidget(fonts, profile)
|
||||
try:
|
||||
|
||||
@@ -311,11 +311,11 @@ def test_gauge_box_shrinks_to_its_content_and_saved_positions_keep_the_drawing_i
|
||||
# Android Auto version 2 layouts move the same way.
|
||||
viewport = (2880, 1080)
|
||||
aa = default_layout_for_viewport(viewport)
|
||||
assert aa['version'] == 6
|
||||
assert aa['version'] == 7
|
||||
aa['version'] = 2
|
||||
aa['widgets'][CEM_GAUGE_WIDGET].update(x=900, y=200)
|
||||
moved = validate_layout_for_viewport(aa, viewport)
|
||||
assert moved['version'] == 6 and (moved['widgets'][CEM_GAUGE_WIDGET]['x'], moved['widgets'][CEM_GAUGE_WIDGET]['y']) == (944, 224)
|
||||
assert moved['version'] == 7 and (moved['widgets'][CEM_GAUGE_WIDGET]['x'], moved['widgets'][CEM_GAUGE_WIDGET]['y']) == (944, 224)
|
||||
assert validate_layout_for_viewport(moved, viewport) == moved
|
||||
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ def test_v12_portrait_upgrade_preserves_preferences_and_is_idempotent():
|
||||
before = copy.deepcopy(old)
|
||||
updated = validate_document(old)
|
||||
expected = copy.deepcopy(old)
|
||||
expected['version'] = 14
|
||||
expected['version'] = 15
|
||||
expected['layouts']['compact']['speed_limit'].update(x=320, y=16)
|
||||
assert old == before and updated == expected
|
||||
assert validate_document(updated) == updated
|
||||
@@ -68,7 +68,7 @@ def test_v12_edge_placements_remain_bounded_even_with_confirmation_disabled():
|
||||
old['layouts']['large']['cruise_limits']['y'] = 882
|
||||
old['layouts']['compact']['speed_limit'].update(x=358, y=108)
|
||||
updated = validate_document(old)
|
||||
assert updated['layouts']['large']['cruise_limits']['y'] == 856
|
||||
assert updated['layouts']['large']['cruise_limits']['y'] == 798
|
||||
assert updated['layouts']['compact']['speed_limit'] == {'x': 348, 'y': 96, 'enabled': True}
|
||||
assert validate_document(updated) == updated
|
||||
assert all(not layout['speed_limit_actions']['enabled'] for layout in updated['layouts'].values())
|
||||
@@ -86,7 +86,7 @@ def test_v13_notice_upgrade_preserves_preferences_and_only_moves_a_conflicting_s
|
||||
before = copy.deepcopy(old)
|
||||
updated = validate_document(old)
|
||||
expected = copy.deepcopy(old)
|
||||
expected['version'] = 14
|
||||
expected['version'] = 15
|
||||
expected['layouts']['compact']['speed_limit']['y'] = min(sign_y, 16)
|
||||
assert old == before and updated == expected
|
||||
assert validate_document(updated) == updated
|
||||
@@ -108,7 +108,7 @@ def test_v12_source_attachment_follows_the_new_row_without_moving_custom_actions
|
||||
actions = old['layouts']['large']['speed_limit_actions']
|
||||
actions['y'] = 367 if separate else 359
|
||||
updated = validate_document(old)
|
||||
assert updated['layouts']['large']['speed_limit_actions']['y'] == (389 if separate else 381)
|
||||
assert updated['layouts']['large']['speed_limit_actions']['y'] == (457 if separate else 449)
|
||||
assert validate_document(updated) == updated
|
||||
actions.update(x=600, y=400)
|
||||
assert validate_document(old)['layouts']['large']['speed_limit_actions'] == actions
|
||||
@@ -170,7 +170,7 @@ def test_source_attachment_saves_real_bounded_positions_without_changing_input(v
|
||||
assert placement(saved, 'large', 'speed_limit_actions') == actions
|
||||
assert actions['y'] == card['y'] + widget_size(saved, 'large', 'cruise_limits')[1] + 8
|
||||
assert actions['y'] + widget_size(saved, 'large', 'speed_limit_actions')[1] <= 1050
|
||||
assert actions['y'] == (389 if separate else 381)
|
||||
assert actions['y'] == (457 if separate else 449)
|
||||
|
||||
|
||||
def test_v7_speed_layout_migration_is_bounded_non_mutating_and_idempotent():
|
||||
@@ -192,8 +192,8 @@ def test_v7_speed_layout_migration_is_bounded_non_mutating_and_idempotent():
|
||||
original = copy.deepcopy(document)
|
||||
migrated = validate_document(document)
|
||||
assert document == original
|
||||
assert migrated['version'] == 14 and validate_document(migrated) == migrated
|
||||
assert migrated['layouts']['large']['cruise_limits']['x'] == 1437
|
||||
assert migrated['version'] == 15 and validate_document(migrated) == migrated
|
||||
assert migrated['layouts']['large']['cruise_limits']['x'] == 1391
|
||||
assert migrated['layouts']['large']['speed_limit_actions'] == {'x': 1510, 'y': 882, 'enabled': True}
|
||||
assert migrated['layouts']['large']['current_speed'] == original['layouts']['large']['current_speed']
|
||||
assert migrated['layouts']['large']['cem_gauge'] == {'x': 56, 'y': 536, 'enabled': True}
|
||||
@@ -222,7 +222,7 @@ def test_v8_restores_only_compact_speed_defaults_and_preserves_customizations(cu
|
||||
original = copy.deepcopy(document)
|
||||
migrated = validate_document(document)
|
||||
assert document == original
|
||||
assert migrated['version'] == 14 and validate_document(migrated) == migrated
|
||||
assert migrated['version'] == 15 and validate_document(migrated) == migrated
|
||||
assert migrated['layouts']['large'] == document['layouts']['large']
|
||||
assert migrated['widgetColors'] == document['widgetColors']
|
||||
assert migrated['widgetOrder'] == document['widgetOrder']
|
||||
@@ -263,7 +263,7 @@ def test_v8_actionless_layout_preserves_customizations_when_adding_compact_actio
|
||||
original = copy.deepcopy(document)
|
||||
migrated = validate_document(document)
|
||||
assert document == original
|
||||
assert migrated['version'] == 14 and validate_document(migrated) == migrated
|
||||
assert migrated['version'] == 15 and validate_document(migrated) == migrated
|
||||
assert migrated['layouts']['large'] == {**original['layouts']['large'], 'speed_limit_actions': large_actions}
|
||||
assert migrated['layouts']['compact']['speed_limit'] == default_document()['layouts']['compact']['speed_limit']
|
||||
assert migrated['layouts']['compact']['speed_limit_actions'] == {'x': 146, 'y': 44, 'enabled': True}
|
||||
@@ -382,7 +382,7 @@ def test_v3_layout_migrates_wheel_size_without_changing_saved_placement_or_color
|
||||
for profile in ("large", "compact"):
|
||||
del document["layouts"][profile]["steering_wheel"]["size"]
|
||||
migrated = validate_document(document)
|
||||
assert migrated["version"] == 14
|
||||
assert migrated["version"] == 15
|
||||
assert migrated["palette"] == document["palette"]
|
||||
assert migrated["layouts"]["large"]["steering_wheel"] == {"x": 1300, "y": 100, "enabled": False, "size": 192}
|
||||
assert migrated["layouts"]["compact"]["steering_wheel"] == {"x": 90, "y": 130, "enabled": True, "size": 50}
|
||||
@@ -416,7 +416,7 @@ def test_pre_action_saved_layout_migrates_without_losing_positions_or_palette(re
|
||||
assert migrated["layouts"][profile][key] == {
|
||||
**position, **({"size": customization_metadata()["profiles"][profile]["widgets"][key]["width"]}
|
||||
if key == "steering_wheel" else {})}
|
||||
assert migrated["layouts"]["large"]["speed_limit_actions"] == {"x": 312, "y": 367, "enabled": False}
|
||||
assert migrated["layouts"]["large"]["speed_limit_actions"] == {"x": 312, "y": 425, "enabled": False}
|
||||
assert migrated["layouts"]["compact"]["speed_limit_actions"] == default_document()["layouts"]["compact"]["speed_limit_actions"]
|
||||
|
||||
|
||||
@@ -434,7 +434,7 @@ def test_malformed_pre_action_cruise_placement_is_rejected():
|
||||
def test_duplicate_key_cannot_apply_otherwise_valid_placement():
|
||||
document = default_document()
|
||||
document["layouts"]["large"]["current_speed"]["x"] = 100
|
||||
raw = json.dumps(document).replace('"version": 14', '"version": 11, "version": 11').encode()
|
||||
raw = json.dumps(document).replace('"version": 15', '"version": 11, "version": 11').encode()
|
||||
with patch("openpilot.starpilot.ui.onroad_customization.read_saved", return_value=(raw, True)):
|
||||
assert read_customization(Mock()) == default_document()
|
||||
|
||||
@@ -450,7 +450,7 @@ def test_v9_large_sign_migration_preserves_customizations_and_clamps_bottom_edge
|
||||
before = deepcopy(old)
|
||||
updated = validate_document(old)
|
||||
assert old == before
|
||||
assert updated['version'] == 14
|
||||
assert updated['version'] == 15
|
||||
assert updated['layouts']['large']['cruise_limits']['y'] == default_document()['layouts']['large']['cruise_limits']['y']
|
||||
assert updated['layouts']['large']['speed_limit_actions'] == before['layouts']['large']['speed_limit_actions']
|
||||
assert updated['layouts']['compact'] == before['layouts']['compact']
|
||||
@@ -463,7 +463,7 @@ def test_v9_moves_only_actions_paired_with_the_old_large_speed_group():
|
||||
old['layouts']['large']['cruise_limits'].update(x=188, y=95)
|
||||
old['layouts']['large']['speed_limit_actions'].update(x=200, y=268)
|
||||
updated = validate_document(old)
|
||||
assert updated['layouts']['large']['speed_limit_actions'] == {'x': 212, 'y': 287, 'enabled': True}
|
||||
assert updated['layouts']['large']['speed_limit_actions'] == {'x': 212, 'y': 345, 'enabled': True}
|
||||
assert validate_document(updated) == updated
|
||||
|
||||
|
||||
@@ -560,7 +560,7 @@ def test_large_draw_origins_and_wheel_input_move_together():
|
||||
with patch("openpilot.starpilot.ui.onroad_large_widgets.draw_control_card") as card, patch.object(rl, "draw_line_ex"):
|
||||
UnifiedSpeedWidget(Mock(spec=BitmapFonts, **vars(fonts))).render(content, state)
|
||||
card.assert_not_called()
|
||||
assert foreground_calls(fonts.draw)[0].args[3:5] == pytest.approx((275, 138.27), abs=.01)
|
||||
assert foreground_calls(fonts.draw)[0].args[3:5] == pytest.approx((275, 145.55), abs=.01)
|
||||
CurrentSpeedHud(Mock(spec=BitmapFonts, **vars(fonts))).render(content, state)
|
||||
assert foreground_calls(fonts.draw)[-2].args[3:5] == (965, 112)
|
||||
wheel = SteeringWheelWidget(Path('/unused'))
|
||||
@@ -593,7 +593,7 @@ def test_frozen_default_draw_geometry_and_neutral_colors():
|
||||
UnifiedSpeedWidget(Mock(spec=BitmapFonts, **vars(fonts))).render(content, state)
|
||||
card.assert_not_called()
|
||||
assert fonts.draw.call_args_list[0].args[0] == 'SET'
|
||||
assert foreground_calls(fonts.draw)[0].args[3:5] == pytest.approx((175, 118.27), abs=.01)
|
||||
assert foreground_calls(fonts.draw)[0].args[3:5] == pytest.approx((175, 125.55), abs=.01)
|
||||
CurrentSpeedHud(Mock(spec=BitmapFonts, **vars(fonts))).render(content, state)
|
||||
assert foreground_calls(fonts.draw)[-2].args[3:5] == (925, 72)
|
||||
assert foreground_calls(fonts.draw)[-1].args[3:5] == pytest.approx((925, 215.2))
|
||||
@@ -706,7 +706,7 @@ def test_v1_palette_positions_and_visibility_migrate_without_mutating_source():
|
||||
original = copy.deepcopy(old)
|
||||
result = decode_document(json.dumps(old).encode())
|
||||
assert old == original
|
||||
assert result['version'] == 14
|
||||
assert result['version'] == 15
|
||||
assert result['palette'] == old['palette']
|
||||
for profile, layout in old['layouts'].items():
|
||||
for key, position in layout.items():
|
||||
|
||||
@@ -5,7 +5,7 @@ from dataclasses import replace
|
||||
|
||||
import pytest
|
||||
|
||||
from openpilot.starpilot.ui.large_speed_geometry import CONFIRMATION_SCALE
|
||||
from openpilot.starpilot.ui.large_speed_geometry import CONFIRMATION_SCALE, PROMPT_SCALE
|
||||
from openpilot.starpilot.ui.onroad_customization import default_document, validate_document
|
||||
from openpilot.starpilot.ui.onroad_state import AlertSize, OnroadAlert, OnroadInput, manual_slc_confirmation, slc_controls, speed_limit_bounds
|
||||
from openpilot.starpilot.ui.presentation import Profile
|
||||
@@ -51,12 +51,14 @@ def test_closed_and_open_card_share_anchor_and_physically_scaled_targets(profile
|
||||
after = speed_limit_bounds(profile, opened)
|
||||
assert before is not None and after is not None
|
||||
assert before[1] == after[1]
|
||||
assert before[3] - after[3] == pytest.approx(7 if profile == Profile.COMPACT else 0)
|
||||
# The notices are taller than their open buttons; their boxes are transparent.
|
||||
assert before[3] - after[3] == pytest.approx(7 if profile == Profile.COMPACT else 16 * CONFIRMATION_SCALE[profile])
|
||||
assert after[0] <= before[0] < before[2] <= after[2]
|
||||
first, last = slc_controls(profile, opened)
|
||||
scale = CONFIRMATION_SCALE[profile]
|
||||
# Button widths stay at finger size; their height follows the notice they open from.
|
||||
scale, height_scale = PROMPT_SCALE[profile], CONFIRMATION_SCALE[profile]
|
||||
assert (first.bounds[2] - first.bounds[0]) / scale == pytest.approx(180 if profile == Profile.LARGE else 150)
|
||||
assert (first.bounds[3] - first.bounds[1]) / scale == pytest.approx(128 if profile == Profile.LARGE else 112)
|
||||
assert (first.bounds[3] - first.bounds[1]) / height_scale == pytest.approx(128 if profile == Profile.LARGE else 112)
|
||||
assert (last.bounds[0] - first.bounds[2]) / scale == pytest.approx(12)
|
||||
assert (first.bounds[0] - after[0]) / scale == pytest.approx(8)
|
||||
assert (after[2] - last.bounds[2]) / scale == pytest.approx(8)
|
||||
@@ -154,7 +156,7 @@ def test_new_layouts_reject_torque_overlap_and_legacy_migration_is_targeted(prof
|
||||
original = deepcopy(doc)
|
||||
migrated = validate_document(doc)
|
||||
assert doc == original
|
||||
assert migrated['version'] == 14
|
||||
assert migrated['version'] == 15
|
||||
assert migrated['palette'] == doc['palette']
|
||||
assert migrated['layouts']['large']['current_speed'] == doc['layouts']['large']['current_speed']
|
||||
assert migrated['layouts'][str(profile)][owner]['y'] == default_document()['layouts'][str(profile)][owner]['y']
|
||||
@@ -166,7 +168,7 @@ def test_legacy_sources_keep_the_saved_action_area_below_the_row():
|
||||
doc.update(version=11, speedSources=True, speedSourcesCard=True)
|
||||
doc['layouts']['large']['speed_limit_actions']['y'] = 351
|
||||
migrated = validate_document(doc)
|
||||
assert migrated['layouts']['large']['speed_limit_actions']['y'] == 389
|
||||
assert migrated['layouts']['large']['speed_limit_actions']['y'] == 457
|
||||
assert validate_document(migrated) == migrated
|
||||
|
||||
|
||||
|
||||
@@ -52,9 +52,9 @@ def test_v4_migration_preserves_settings_and_clamps_only_enlarged_widgets():
|
||||
doc['layouts']['large']['speed_limit_actions'].update(x=1654, y=500)
|
||||
old_speed = dict(doc['layouts']['large']['current_speed'])
|
||||
migrated = validate_document(doc)
|
||||
assert migrated['version'] == 14
|
||||
assert migrated['layouts']['large']['cruise_limits']['x'] == 1437
|
||||
assert migrated['layouts']['large']['speed_limit_actions'] == {'x': 1678, 'y': 267, 'enabled': True}
|
||||
assert migrated['version'] == 15
|
||||
assert migrated['layouts']['large']['cruise_limits']['x'] == 1391
|
||||
assert migrated['layouts']['large']['speed_limit_actions'] == {'x': 1678, 'y': 325, 'enabled': True}
|
||||
assert migrated['layouts']['large']['current_speed'] == old_speed
|
||||
assert migrated['speedSources'] is True
|
||||
assert rgba(migrated, 'cardFill', 'large', 'cruise_limits') == (18, 52, 86, 120)
|
||||
|
||||
@@ -315,7 +315,7 @@ def test_wheel_cues_follow_confirmation_availability(profile, available, drawing
|
||||
if available:
|
||||
bounds = speed_limit_bounds(profile, current)
|
||||
assert bounds is not None
|
||||
hint_y = bounds[1] + (12 if profile == Profile.LARGE else 8) + (142 if profile == Profile.LARGE else 136.75) * CONFIRMATION_SCALE[profile]
|
||||
hint_y = bounds[1] + (12 if profile == Profile.LARGE else 8) + (161 if profile == Profile.LARGE else 136.75) * CONFIRMATION_SCALE[profile]
|
||||
assert all(call.args[2] == pytest.approx(hint_y) for call in calls)
|
||||
assert bounds[0] < calls[0].args[1] < calls[1].args[1] < bounds[2]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user