mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-10-29 17:43:47 +08:00
Minor initial set speed fixes (#39099)
This commit is contained in:
committed by
firestar5683
parent
c103cb5722
commit
d69c052bb8
@@ -7,14 +7,14 @@ from openpilot.common.params import Params
|
||||
from openpilot.selfdrive.car.cruise import V_CRUISE_INITIAL, V_CRUISE_MAX, validated_initial_cruise_speed
|
||||
from openpilot.system.ui.lib.application import FontWeight, TextAlignment
|
||||
from openpilot.system.ui.lib.multilang import tr
|
||||
from openpilot.system.ui.widgets.button import Button
|
||||
from openpilot.system.ui.widgets.button import Button, ButtonStyle
|
||||
from openpilot.system.ui.widgets.label import gui_label
|
||||
from openpilot.system.ui.widgets.list_view import ItemAction
|
||||
|
||||
|
||||
class RepeatButton(Button):
|
||||
def __init__(self, text, callback, font_size):
|
||||
super().__init__(text, callback, font_size=font_size, border_radius=16, text_padding=0)
|
||||
super().__init__(text, callback, font_size=font_size, button_style=ButtonStyle.PILL, border_radius=16, text_padding=0)
|
||||
self._repeat_at: float | None = None
|
||||
self._repeated = False
|
||||
|
||||
|
||||
@@ -15,11 +15,19 @@ PERSONALITY_TO_INT = log.LongitudinalPersonality.schema.enumerants
|
||||
|
||||
class InitialCruiseSpeedButton(BigButton):
|
||||
def __init__(self):
|
||||
super().__init__("initial max speed", " ")
|
||||
self._long_press_callback = None
|
||||
super().__init__("initial max speed", " ", description="Max speed when engaging openpilot.\n" +
|
||||
"If you are already driving faster, your current speed is used.\n" +
|
||||
"Resume restores the previous max speed.")
|
||||
self._control = self._child(InitialCruiseSpeedControl(compact=True))
|
||||
self._control.set_enabled(lambda: self.enabled)
|
||||
self._control.set_touch_valid_callback(self._touch_valid)
|
||||
self._show_description = self._long_press_callback
|
||||
self.set_long_press_callback(self._on_long_press)
|
||||
|
||||
def _on_long_press(self):
|
||||
# a hold on the speed control repeats a step
|
||||
if not self._control.is_pressed and self._show_description is not None:
|
||||
self._show_description()
|
||||
|
||||
def _get_label_font_size(self):
|
||||
return 36
|
||||
|
||||
@@ -21,6 +21,7 @@ class ButtonStyle(IntEnum):
|
||||
NO_EFFECT = 6
|
||||
KEYBOARD = 7
|
||||
FORGET_WIFI = 8
|
||||
PILL = 11 # For pill buttons in list items, for example the multiple button selector
|
||||
|
||||
|
||||
ICON_PADDING = 15
|
||||
@@ -39,10 +40,12 @@ BUTTON_TEXT_COLOR = {
|
||||
ButtonStyle.NO_EFFECT: rl.Color(228, 228, 228, 255),
|
||||
ButtonStyle.KEYBOARD: rl.Color(221, 221, 221, 255),
|
||||
ButtonStyle.FORGET_WIFI: rl.Color(51, 51, 51, 255),
|
||||
ButtonStyle.PILL: rl.Color(228, 228, 228, 255),
|
||||
}
|
||||
|
||||
BUTTON_DISABLED_TEXT_COLORS = {
|
||||
ButtonStyle.TRANSPARENT_WHITE_TEXT: rl.WHITE,
|
||||
ButtonStyle.PILL: rl.Color(150, 150, 150, 255),
|
||||
}
|
||||
|
||||
BUTTON_BACKGROUND_COLORS = {
|
||||
@@ -57,6 +60,7 @@ BUTTON_BACKGROUND_COLORS = {
|
||||
ButtonStyle.NO_EFFECT: rl.Color(51, 51, 51, 255),
|
||||
ButtonStyle.KEYBOARD: rl.Color(68, 68, 68, 255),
|
||||
ButtonStyle.FORGET_WIFI: rl.Color(189, 189, 189, 255),
|
||||
ButtonStyle.PILL: rl.Color(57, 57, 57, 255),
|
||||
}
|
||||
|
||||
BUTTON_PRESSED_BACKGROUND_COLORS = {
|
||||
@@ -71,10 +75,12 @@ BUTTON_PRESSED_BACKGROUND_COLORS = {
|
||||
ButtonStyle.NO_EFFECT: rl.Color(51, 51, 51, 255),
|
||||
ButtonStyle.KEYBOARD: rl.Color(51, 51, 51, 255),
|
||||
ButtonStyle.FORGET_WIFI: rl.Color(130, 130, 130, 255),
|
||||
ButtonStyle.PILL: rl.Color(74, 74, 74, 255),
|
||||
}
|
||||
|
||||
BUTTON_DISABLED_BACKGROUND_COLORS = {
|
||||
ButtonStyle.TRANSPARENT_WHITE_TEXT: rl.BLANK,
|
||||
ButtonStyle.PILL: rl.Color(57, 57, 57, 150),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ from openpilot.system.ui.lib.application import gui_app, FontWeight, MousePos, T
|
||||
from openpilot.system.ui.lib.multilang import tr
|
||||
from openpilot.system.ui.lib.text_measure import measure_text_cached
|
||||
from openpilot.system.ui.widgets import Widget
|
||||
from openpilot.system.ui.widgets.button import Button, ButtonStyle
|
||||
from openpilot.system.ui.widgets.button import (Button, ButtonStyle, BUTTON_TEXT_COLOR, BUTTON_DISABLED_TEXT_COLORS, BUTTON_BACKGROUND_COLORS,
|
||||
BUTTON_PRESSED_BACKGROUND_COLORS, BUTTON_DISABLED_BACKGROUND_COLORS)
|
||||
from openpilot.system.ui.widgets.toggle import Toggle, WIDTH as TOGGLE_WIDTH, HEIGHT as TOGGLE_HEIGHT
|
||||
from openpilot.system.ui.widgets.label import gui_label
|
||||
from openpilot.system.ui.widgets.html_render import HtmlRenderer, ElementType
|
||||
@@ -242,12 +243,12 @@ class MultipleButtonAction(ItemAction):
|
||||
if is_selected:
|
||||
bg_color = rl.Color(51, 171, 76, 255) # Green
|
||||
elif is_pressed:
|
||||
bg_color = rl.Color(74, 74, 74, 255) # Dark gray
|
||||
bg_color = BUTTON_PRESSED_BACKGROUND_COLORS[ButtonStyle.PILL]
|
||||
else:
|
||||
bg_color = rl.Color(57, 57, 57, 255) # Gray
|
||||
bg_color = BUTTON_BACKGROUND_COLORS[ButtonStyle.PILL]
|
||||
|
||||
if not self.enabled:
|
||||
bg_color = rl.Color(bg_color.r, bg_color.g, bg_color.b, 150) # Dim
|
||||
bg_color = rl.Color(bg_color.r, bg_color.g, bg_color.b, BUTTON_DISABLED_BACKGROUND_COLORS[ButtonStyle.PILL].a)
|
||||
|
||||
# Draw button
|
||||
rl.draw_rectangle_rounded(button_rect, 1.0, 20, bg_color)
|
||||
@@ -257,7 +258,7 @@ class MultipleButtonAction(ItemAction):
|
||||
text_size = measure_text_cached(self._font, text, 40)
|
||||
text_x = button_x + (self.button_width - text_size.x) / 2
|
||||
text_y = button_y + (BUTTON_HEIGHT - text_size.y) / 2
|
||||
text_color = rl.Color(228, 228, 228, 255) if self.enabled else rl.Color(150, 150, 150, 255)
|
||||
text_color = BUTTON_TEXT_COLOR[ButtonStyle.PILL] if self.enabled else BUTTON_DISABLED_TEXT_COLORS[ButtonStyle.PILL]
|
||||
rl.draw_text_ex(self._font, text, rl.Vector2(text_x, text_y), 40, 0, text_color)
|
||||
|
||||
def _handle_mouse_release(self, mouse_pos: MousePos):
|
||||
|
||||
Reference in New Issue
Block a user