Skip to content

Commit a3daca8

Browse files
authored
ui: implement PrimeAdWidget (#35496)
implement PrimeAdWidget
1 parent 6d09b24 commit a3daca8

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

selfdrive/ui/layouts/home.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from enum import IntEnum
55
from openpilot.common.params import Params
66
from openpilot.selfdrive.ui.widgets.offroad_alerts import UpdateAlert, OffroadAlert
7+
from openpilot.selfdrive.ui.widgets.prime import PrimeAdWidget
78
from openpilot.system.ui.lib.text_measure import measure_text_cached
89
from openpilot.system.ui.lib.label import gui_label
910
from openpilot.system.ui.lib.application import gui_app, FontWeight, DEFAULT_TEXT_COLOR, Widget
@@ -47,6 +48,8 @@ def __init__(self):
4748
self.update_notif_rect = rl.Rectangle(0, 0, 200, HEADER_HEIGHT - 10)
4849
self.alert_notif_rect = rl.Rectangle(0, 0, 220, HEADER_HEIGHT - 10)
4950

51+
self._prime_ad_widget = PrimeAdWidget()
52+
5053
self._setup_callbacks()
5154

5255
def _setup_callbacks(self):
@@ -171,7 +174,7 @@ def _render_alerts_view(self):
171174

172175
def _render_left_column(self):
173176
rl.draw_rectangle_rounded(self.left_column_rect, 0.02, 10, PRIME_BG_COLOR)
174-
gui_label(self.left_column_rect, "Prime Widget", 48, alignment=rl.GuiTextAlignment.TEXT_ALIGN_CENTER)
177+
self._prime_ad_widget.render(self.left_column_rect)
175178

176179
def _render_right_column(self):
177180
widget_height = (self.right_column_rect.height - SPACING) // 2

selfdrive/ui/widgets/prime.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pyray as rl
2+
from openpilot.system.ui.lib.application import gui_app, Widget, FontWeight
3+
from openpilot.system.ui.lib.label import gui_label
4+
from openpilot.system.ui.lib.wrap_text import wrap_text
5+
from openpilot.system.ui.lib.text_measure import measure_text_cached
6+
7+
8+
class PrimeAdWidget(Widget):
9+
"""Advertisement widget for non-Prime users."""
10+
11+
def __init__(self):
12+
super().__init__()
13+
14+
def _render(self, rect):
15+
# Layout
16+
x, y = rect.x + 80, rect.y + 90
17+
w = rect.width - 160
18+
19+
# Title
20+
gui_label(rl.Rectangle(x, y, w, 90), "Upgrade Now", 75, font_weight=FontWeight.BOLD)
21+
22+
# Description with wrapping
23+
desc_y = y + 140
24+
font = gui_app.font(FontWeight.LIGHT)
25+
wrapped_text = "\n".join(wrap_text(font, "Become a comma prime member at connect.comma.ai", 56, w))
26+
text_size = measure_text_cached(font, wrapped_text, 56)
27+
rl.draw_text_ex(font, wrapped_text, rl.Vector2(x, desc_y), 56, 0, rl.Color(255, 255, 255, 255))
28+
29+
# Features section
30+
features_y = desc_y + text_size.y + 50
31+
gui_label(rl.Rectangle(x, features_y, w, 50), "PRIME FEATURES:", 41, font_weight=FontWeight.BOLD)
32+
33+
# Feature list
34+
features = ["Remote access", "24/7 LTE connectivity", "1 year of drive storage", "Remote snapshots"]
35+
for i, feature in enumerate(features):
36+
item_y = features_y + 80 + i * 65
37+
gui_label(rl.Rectangle(x, item_y, 50, 60), "✓", 50, color=rl.Color(70, 91, 234, 255))
38+
gui_label(rl.Rectangle(x + 60, item_y, w - 60, 60), feature, 50)

system/ui/lib/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def _load_fonts(self):
252252
for layout in KEYBOARD_LAYOUTS.values():
253253
all_chars.update(key for row in layout for key in row)
254254
all_chars = "".join(all_chars)
255-
all_chars += "-"
255+
all_chars += "-"
256256

257257
codepoint_count = rl.ffi.new("int *", 1)
258258
codepoints = rl.load_codepoints(all_chars, codepoint_count)

0 commit comments

Comments
 (0)