mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 10:33:43 +08:00
Center SET and the speed limit sign on one line on the large UI
This commit is contained in:
@@ -22,8 +22,10 @@ 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
|
||||
# Ink-centered rows, shared by SET, the portrait sign and the confirmation notice.
|
||||
HEADING_ROW, NUMBER_ROW, SOURCE_ROW = 16.75, 61, 114.5
|
||||
# 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
|
||||
|
||||
|
||||
def draw_text(fonts, text, role, size, x, y, color=INK):
|
||||
@@ -59,13 +61,13 @@ 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,
|
||||
top + HEADING_ROW * scale, color, 'SET')
|
||||
top + SET_HEADING_ROW * scale, color, 'SET')
|
||||
if shown.max_text == '–':
|
||||
draw_line(fonts.profile, rl.Vector2(center - 20 * scale, top + NUMBER_ROW * scale),
|
||||
rl.Vector2(center + 20 * scale, top + NUMBER_ROW * scale), 5 * scale, color)
|
||||
draw_line(fonts.profile, rl.Vector2(center - 20 * scale, top + SET_NUMBER_ROW * scale),
|
||||
rl.Vector2(center + 20 * scale, top + SET_NUMBER_ROW * scale), 5 * scale, color)
|
||||
else:
|
||||
draw_speed_row(fonts, shown.max_text, FontRole.SET_SPEED, NUMBER_SIZE * text_scale, center,
|
||||
top + NUMBER_ROW * scale, color, '0123456789')
|
||||
top + SET_NUMBER_ROW * scale, color, '0123456789')
|
||||
|
||||
|
||||
def draw_set_status(fonts, label, center, top, color):
|
||||
@@ -73,7 +75,7 @@ def draw_set_status(fonts, label, center, top, color):
|
||||
size = 22 * 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))
|
||||
draw_speed_row(fonts, label, FontRole.MEDIUM, size, center, top + SOURCE_ROW * scale, color, label)
|
||||
draw_speed_row(fonts, label, FontRole.MEDIUM, size, center, top + SET_STATUS_ROW * scale, color, label)
|
||||
|
||||
|
||||
def speed_status(shown):
|
||||
@@ -281,6 +283,9 @@ class SpeedLimitWidget:
|
||||
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)
|
||||
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,
|
||||
scale=scale * sign_scale, width_scale=SIGN_HEIGHT * 4 / 5 / SIGN_WIDTH)
|
||||
|
||||
@@ -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, 86.07, places=2)
|
||||
self.assertAlmostEqual(y, 118.27, 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()
|
||||
|
||||
@@ -47,8 +47,9 @@ 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
|
||||
assert widget.shapes.outline.call_args.args[:2] == (bounds[0]+12+SIGN_WIDTH/2*scale,
|
||||
bounds[1]+12+(SIGN_HEIGHT*sign_scale/2-9)*scale)
|
||||
# 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
|
||||
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
|
||||
|
||||
|
||||
@@ -121,9 +121,10 @@ def test_large_set_and_limit_share_typography_at_the_saved_position():
|
||||
assert not any('mph' in call[0] or 'km/h' in call[0] for call in calls)
|
||||
if show_set and value is None:
|
||||
start, end, stroke, color = lines.call_args.args
|
||||
from openpilot.starpilot.ui.speed_limit_widget import SET_NUMBER_ROW
|
||||
assert (start.x, start.y, end.x, end.y, stroke) == pytest.approx(
|
||||
(280 - 20 * LARGE_SIGN_SCALE, 95 + 61 * LARGE_SIGN_SCALE,
|
||||
280 + 20 * LARGE_SIGN_SCALE, 95 + 61 * LARGE_SIGN_SCALE, 5 * LARGE_SIGN_SCALE))
|
||||
(280 - 20 * LARGE_SIGN_SCALE, 95 + SET_NUMBER_ROW * LARGE_SIGN_SCALE,
|
||||
280 + 20 * LARGE_SIGN_SCALE, 95 + SET_NUMBER_ROW * LARGE_SIGN_SCALE, 5 * LARGE_SIGN_SCALE))
|
||||
assert (color.r, color.g, color.b, color.a) == (255, 255, 255, 255)
|
||||
assert all(call[0] not in ('–', '?') for call in calls)
|
||||
else:
|
||||
@@ -179,14 +180,7 @@ def test_set_and_slc_keep_their_profile_specific_typography(pending):
|
||||
for a, b in (('SET', 'OSM'), ('140', str(value))):
|
||||
assert rows[a][1] == rows[b][1]
|
||||
assert rows[a][2] == pytest.approx(rows[b][2])
|
||||
# Only the confirmation notice shares SET's rows; the posted sign keeps its own.
|
||||
if not pending:
|
||||
continue
|
||||
if rows[a][1] == FontRole.SET_SPEED:
|
||||
assert rows[a][4] == pytest.approx(rows[b][4])
|
||||
else:
|
||||
assert rows[a][4] + sum(fonts.vertical_ink(*rows[a][:3])) / 2 == pytest.approx(
|
||||
rows[b][4] + sum(fonts.vertical_ink(*rows[b][:3])) / 2)
|
||||
# SET centers on the sign beside it, so neither the sign nor the notice shares its rows.
|
||||
assert not any('mph' in text or 'km/h' in text for text in rows)
|
||||
finally:
|
||||
widget.close()
|
||||
@@ -697,6 +691,9 @@ def test_sign_profiles_share_layout_and_keep_aligned_numbers():
|
||||
drawn.append((widget, calls))
|
||||
small_widget, small_calls = drawn[0]
|
||||
large_widget, large_calls = drawn[1]
|
||||
# Large centers the sign on its tap area, so compare text against each sign's own center.
|
||||
small_center, large_center = (next(getattr(w.shapes, name).call_args.args[1] for name in ('outline', 'thick_outline', 'circle')
|
||||
if getattr(w.shapes, name).call_args) for w in (small_widget, large_widget))
|
||||
assert [call[0] for call in small_calls] == [call[0] for call in large_calls]
|
||||
if not vienna:
|
||||
assert small_calls[1][1] == large_calls[1][1] == FontRole.SET_SPEED
|
||||
@@ -704,10 +701,7 @@ def test_sign_profiles_share_layout_and_keep_aligned_numbers():
|
||||
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
|
||||
small_bounds = speed_limit_bounds(Profile.COMPACT, current)
|
||||
large_bounds = speed_limit_bounds(Profile.LARGE, current)
|
||||
assert small_bounds is not None and large_bounds is not None
|
||||
assert abs((a[4]-small_bounds[1]-12)-(b[4]-large_bounds[1]-12)/LARGE_SIGN_SCALE) <= 1
|
||||
assert abs((a[4]-small_center)-(b[4]-large_center)/LARGE_SIGN_SCALE) <= 1
|
||||
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 pending:
|
||||
for widget in (small_widget, large_widget):
|
||||
|
||||
@@ -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, 106.07), abs=.01)
|
||||
assert foreground_calls(fonts.draw)[0].args[3:5] == pytest.approx((275, 138.27), 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, 86.07), abs=.01)
|
||||
assert foreground_calls(fonts.draw)[0].args[3:5] == pytest.approx((175, 118.27), 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))
|
||||
|
||||
Reference in New Issue
Block a user