ui: replace close button text with icon (#36492)

pull/36494/head
Adeeb Shihadeh 2 weeks ago committed by GitHub
parent cf5bb4e16e
commit a974deeb59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 25
      selfdrive/ui/layouts/settings/settings.py

@ -14,13 +14,10 @@ from openpilot.system.ui.lib.wifi_manager import WifiManager
from openpilot.system.ui.widgets import Widget from openpilot.system.ui.widgets import Widget
from openpilot.system.ui.widgets.network import NetworkUI from openpilot.system.ui.widgets.network import NetworkUI
# Settings close button
SETTINGS_CLOSE_TEXT = "×"
SETTINGS_CLOSE_TEXT_Y_OFFSET = 8 # The '×' character isn't quite vertically centered in the font so we need to offset it a bit to fully center it
# Constants # Constants
SIDEBAR_WIDTH = 500 SIDEBAR_WIDTH = 500
CLOSE_BTN_SIZE = 200 CLOSE_BTN_SIZE = 200
CLOSE_ICON_SIZE = 70
NAV_BTN_HEIGHT = 110 NAV_BTN_HEIGHT = 110
PANEL_MARGIN = 50 PANEL_MARGIN = 50
@ -68,6 +65,7 @@ class SettingsLayout(Widget):
} }
self._font_medium = gui_app.font(FontWeight.MEDIUM) self._font_medium = gui_app.font(FontWeight.MEDIUM)
self._close_icon = gui_app.texture("icons/close2.png", CLOSE_ICON_SIZE, CLOSE_ICON_SIZE)
# Callbacks # Callbacks
self._close_callback: Callable | None = None self._close_callback: Callable | None = None
@ -97,12 +95,21 @@ class SettingsLayout(Widget):
close_color = CLOSE_BTN_PRESSED if pressed else CLOSE_BTN_COLOR close_color = CLOSE_BTN_PRESSED if pressed else CLOSE_BTN_COLOR
rl.draw_rectangle_rounded(close_btn_rect, 1.0, 20, close_color) rl.draw_rectangle_rounded(close_btn_rect, 1.0, 20, close_color)
close_text_size = measure_text_cached(self._font_medium, SETTINGS_CLOSE_TEXT, 140) icon_color = rl.Color(255, 255, 255, 255) if not pressed else rl.Color(220, 220, 220, 255)
close_text_pos = rl.Vector2( icon_dest = rl.Rectangle(
close_btn_rect.x + (close_btn_rect.width - close_text_size.x) / 2, close_btn_rect.x + (close_btn_rect.width - self._close_icon.width) / 2,
close_btn_rect.y + (close_btn_rect.height - close_text_size.y) / 2 - SETTINGS_CLOSE_TEXT_Y_OFFSET, close_btn_rect.y + (close_btn_rect.height - self._close_icon.height) / 2,
self._close_icon.width,
self._close_icon.height,
)
rl.draw_texture_pro(
self._close_icon,
rl.Rectangle(0, 0, self._close_icon.width, self._close_icon.height),
icon_dest,
rl.Vector2(0, 0),
0,
icon_color,
) )
rl.draw_text_ex(self._font_medium, SETTINGS_CLOSE_TEXT, close_text_pos, 140, 0, TEXT_SELECTED)
# Store close button rect for click detection # Store close button rect for click detection
self._close_btn_rect = close_btn_rect self._close_btn_rect = close_btn_rect

Loading…
Cancel
Save