From 70ccc648315c25c2cc34be43702cdcf87d54c34a Mon Sep 17 00:00:00 2001 From: whoisdomi Date: Thu, 14 May 2026 10:28:36 -0500 Subject: [PATCH] SLC abbreviated icons Gives the options to display SLC sources as abbreviated and the option to only show sources with data in them to give a cleaner UI look. --- common/params_keys.h | 2 + starpilot/common/starpilot_variables.py | 2 + .../ui/qt/offroad/longitudinal_settings.cc | 4 +- .../ui/qt/offroad/longitudinal_settings.h | 2 +- .../qt/onroad/starpilot_annotated_camera.cc | 85 +++++++++++++------ .../ui/qt/onroad/starpilot_annotated_camera.h | 2 + 6 files changed, 71 insertions(+), 26 deletions(-) diff --git a/common/params_keys.h b/common/params_keys.h index 32b277664..ff52dce53 100644 --- a/common/params_keys.h +++ b/common/params_keys.h @@ -491,6 +491,8 @@ inline static std::unordered_map keys = { {"SignalMetrics", {PERSISTENT, BOOL, "0", "0", 3}}, {"SignalToDownload", {CLEAR_ON_MANAGER_START, STRING, "", ""}}, {"SimpleMode", {PERSISTENT, BOOL, "0", "0", 0}}, + {"SLCAbbreviatedSources", {PERSISTENT, BOOL, "0", "0", 3}}, + {"SLCActiveSourcesOnly", {PERSISTENT, BOOL, "0", "0", 3}}, {"SLCConfirmation", {PERSISTENT, BOOL, "0", "0", 0}}, {"SLCConfirmationHigher", {PERSISTENT, BOOL, "0", "0", 0}}, {"SLCConfirmationLower", {PERSISTENT, BOOL, "0", "0", 0}}, diff --git a/starpilot/common/starpilot_variables.py b/starpilot/common/starpilot_variables.py index 807e02627..4b6e07973 100644 --- a/starpilot/common/starpilot_variables.py +++ b/starpilot/common/starpilot_variables.py @@ -1162,6 +1162,8 @@ class StarPilotVariables: toggle.speed_limit_priority_highest = toggle.speed_limit_priority1 == "Highest" toggle.speed_limit_priority_lowest = toggle.speed_limit_priority1 == "Lowest" toggle.speed_limit_sources = self.get_value("SpeedLimitSources", condition=speed_limit_display) or toggle.debug_mode + toggle.slc_abbreviated_sources = self.get_value("SLCAbbreviatedSources", condition=speed_limit_display) + toggle.slc_active_sources_only = self.get_value("SLCActiveSourcesOnly", condition=speed_limit_display) toggle.speed_limit_filler = self.get_value("SpeedLimitFiller") toggle.vision_speed_limit_detection = self.get_value("VisionSpeedLimitDetection") diff --git a/starpilot/ui/qt/offroad/longitudinal_settings.cc b/starpilot/ui/qt/offroad/longitudinal_settings.cc index ddf4ee3fd..ef8c2f0fd 100644 --- a/starpilot/ui/qt/offroad/longitudinal_settings.cc +++ b/starpilot/ui/qt/offroad/longitudinal_settings.cc @@ -210,7 +210,9 @@ StarPilotLongitudinalPanel::StarPilotLongitudinalPanel(StarPilotSettingsWindow * {"Offset7", tr("Speed Offset (75–99 mph)"), tr("How much to offset posted speed-limits between 75 and 99 mph."), ""}, {"SLCVisuals", tr("Visual Settings"), tr("Visual \"Speed Limit Controller\" changes to fine-tune how the driving screen looks."), ""}, {"ShowSLCOffset", tr("Show Speed Limit Offset"), tr("Show the current offset from the posted limit on the driving screen."), ""}, - {"SpeedLimitSources", tr("Show Speed Limit Sources"), tr("Display the speed-limit sources and their current values on the driving screen."), ""} + {"SpeedLimitSources", tr("Show Speed Limit Sources"), tr("Display the speed-limit sources and their current values on the driving screen."), ""}, + {"SLCAbbreviatedSources", tr("Show Abbreviated Icon Sources"), tr("Render the speed-limit sources as compact text labels (e.g. \"Dash-45\", \"MapD-30\") without icons."), ""}, + {"SLCActiveSourcesOnly", tr("Only Show Sources With Speed Limits"), tr("Hide source rows that have no current speed limit reading. Works with both abbreviated and full display."), ""} }; for (const auto &[param, title, desc, icon] : longitudinalToggles) { diff --git a/starpilot/ui/qt/offroad/longitudinal_settings.h b/starpilot/ui/qt/offroad/longitudinal_settings.h index daab66f0d..d8af0afa7 100644 --- a/starpilot/ui/qt/offroad/longitudinal_settings.h +++ b/starpilot/ui/qt/offroad/longitudinal_settings.h @@ -39,7 +39,7 @@ private: QSet speedLimitControllerKeys = {"SLCOffsets", "SLCFallback", "SLCOverride", "SLCPriority", "SLCQOL", "SLCVisuals"}; QSet speedLimitControllerOffsetsKeys = {"Offset1", "Offset2", "Offset3", "Offset4", "Offset5", "Offset6", "Offset7"}; QSet speedLimitControllerQOLKeys = {"SetSpeedLimit", "SLCConfirmation", "SLCLookaheadHigher", "SLCLookaheadLower", "SLCMapboxFiller", "VisionSpeedLimitDetection"}; - QSet speedLimitControllerVisualKeys = {"ShowSLCOffset", "SpeedLimitSources"}; + QSet speedLimitControllerVisualKeys = {"ShowSLCOffset", "SLCAbbreviatedSources", "SLCActiveSourcesOnly", "SpeedLimitSources"}; QSet standardPersonalityKeys = {"StandardFollow", "StandardFollowHigh", "StandardJerkAcceleration", "StandardJerkDeceleration", "StandardJerkDanger", "StandardJerkSpeed", "StandardJerkSpeedDecrease", "ResetStandardPersonality"}; QSet trafficPersonalityKeys = {"TrafficFollow", "TrafficJerkAcceleration", "TrafficJerkDeceleration", "TrafficJerkDanger", "TrafficJerkSpeed", "TrafficJerkSpeedDecrease", "ResetTrafficPersonality"}; QSet weatherKeys = {"LowVisibilityOffsets", "RainOffsets", "RainStormOffsets", "SetWeatherKey", "SnowOffsets"}; diff --git a/starpilot/ui/qt/onroad/starpilot_annotated_camera.cc b/starpilot/ui/qt/onroad/starpilot_annotated_camera.cc index b865dbf0f..d825043e8 100644 --- a/starpilot/ui/qt/onroad/starpilot_annotated_camera.cc +++ b/starpilot/ui/qt/onroad/starpilot_annotated_camera.cc @@ -167,6 +167,8 @@ void StarPilotAnnotatedCameraWidget::updateState(const UIState &s, const StarPil cachedSimpleMode = starpilot_toggles.value("simple_mode").toBool(); cachedSpeedLimitController = starpilot_toggles.value("speed_limit_controller").toBool(); cachedSpeedLimitSources = starpilot_toggles.value("speed_limit_sources").toBool(); + cachedSlcAbbreviatedSources = starpilot_toggles.value("slc_abbreviated_sources").toBool(); + cachedSlcActiveSourcesOnly = starpilot_toggles.value("slc_active_sources_only").toBool(); cachedSpeedLimitVienna = starpilot_toggles.value("speed_limit_vienna").toBool(); cachedStaticPedalsOnUi = starpilot_toggles.value("static_pedals_on_ui").toBool(); cachedStoppedTimer = starpilot_toggles.value("stopped_timer").toBool(); @@ -1030,7 +1032,11 @@ void StarPilotAnnotatedCameraWidget::paintSpeedLimit(QPainter &p) { void StarPilotAnnotatedCameraWidget::paintSpeedLimitSources(QPainter &p) { p.save(); - std::function drawSource = [&](QRect &rect, QPixmap &icon, const QString &title, double speedLimitValue) { + const bool abbreviated = cachedSlcAbbreviatedSources; + const bool activeOnly = cachedSlcActiveSourcesOnly; + + std::function drawSource = + [&](QRect &rect, QPixmap &icon, const QString &title, const QString &abbrev, double speedLimitValue) { bool isActive = QString::fromUtf8(speedLimitSource.c_str()) == title && speedLimitValue != 0; if (isActive) { @@ -1043,29 +1049,38 @@ void StarPilotAnnotatedCameraWidget::paintSpeedLimitSources(QPainter &p) { p.setPen(QPen(blackColor(), 10)); } - QSize size(img_size / 4, img_size / 4); - QRect iconRect = QStyle::alignedRect(Qt::LeftToRight, Qt::AlignLeft | Qt::AlignVCenter, size, rect.adjusted(20, 0, 0, 0)); - - QString speedText; - if (speedLimitValue != 0) { - speedText = QString::number(std::nearbyint(speedLimitValue)) + speedUnit; + QString fullText; + if (abbreviated) { + if (speedLimitValue != 0) { + fullText = abbrev + "-" + QString::number(std::nearbyint(speedLimitValue)); + } else { + fullText = abbrev + "-X"; + } } else { - speedText = "N/A"; + QString speedText = (speedLimitValue != 0) + ? QString::number(std::nearbyint(speedLimitValue)) + speedUnit + : "N/A"; + fullText = tr(title.toUtf8().constData()) + " - " + speedText; } - QString fullText = tr(title.toUtf8().constData()) + " - " + speedText; - p.setOpacity(1.0); p.drawRoundedRect(rect, 24, 24); - p.drawPixmap(iconRect, icon); + + QRect textRect; + if (abbreviated) { + textRect = QRect(rect.x() + 20, rect.y(), rect.width() - 40, rect.height()); + } else { + QSize size(img_size / 4, img_size / 4); + QRect iconRect = QStyle::alignedRect(Qt::LeftToRight, Qt::AlignLeft | Qt::AlignVCenter, size, rect.adjusted(20, 0, 0, 0)); + p.drawPixmap(iconRect, icon); + textRect = QRect(iconRect.right() + 10, rect.y(), rect.width() - iconRect.width() - 30, rect.height()); + } p.setPen(QPen(whiteColor(), 6)); - QRect textRect(iconRect.right() + 10, rect.y(), rect.width() - iconRect.width() - 30, rect.height()); if (isActive) { QFontMetrics fm(p.font()); int textYPosition = textRect.y() + (textRect.height() - fm.height()) / 2 + fm.ascent(); - QPainterPath path; path.addText(textRect.x(), textYPosition, p.font(), fullText); p.strokePath(path, QPen(Qt::black, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); @@ -1075,19 +1090,41 @@ void StarPilotAnnotatedCameraWidget::paintSpeedLimitSources(QPainter &p) { } }; - int signMargin = 12; + struct SrcEntry { QPixmap *icon; QString title; QString abbrev; double value; }; + std::vector sources = { + {&dashboardIcon, "Dashboard", "Dash", dashboardSpeedLimit * speedConversion}, + {&mapDataIcon, "Map Data", "MapD", mapSpeedLimit * speedConversion}, + {&visionIcon, "Vision", "Vision", visionSpeedLimit * speedConversion}, + {&mapboxIcon, "Mapbox", "MapB", mapboxSpeedLimit * speedConversion}, + {&nextMapsIcon, "Upcoming", "Next", nextSpeedLimit * speedConversion}, + }; - QRect dashboardRect(speedLimitRect.x() - signMargin, speedLimitRect.y() + speedLimitRect.height() + UI_BORDER_SIZE, 450, 60); - QRect mapDataRect(dashboardRect.x(), dashboardRect.y() + dashboardRect.height() + UI_BORDER_SIZE / 2, 450, 60); - QRect visionRect(mapDataRect.x(), mapDataRect.y() + mapDataRect.height() + UI_BORDER_SIZE / 2, 450, 60); - QRect mapboxRect(visionRect.x(), visionRect.y() + visionRect.height() + UI_BORDER_SIZE / 2, 450, 60); - QRect nextLimitRect(mapboxRect.x(), mapboxRect.y() + mapboxRect.height() + UI_BORDER_SIZE / 2, 450, 60); + const int signMargin = 12; + const int rectH = 60; + const int gap = UI_BORDER_SIZE / 2; + const int xPos = abbreviated ? speedLimitRect.x() : speedLimitRect.x() - signMargin; + int yPos = speedLimitRect.y() + speedLimitRect.height() + UI_BORDER_SIZE; - drawSource(dashboardRect, dashboardIcon, "Dashboard", dashboardSpeedLimit * speedConversion); - drawSource(mapDataRect, mapDataIcon, "Map Data", mapSpeedLimit * speedConversion); - drawSource(visionRect, visionIcon, "Vision", visionSpeedLimit * speedConversion); - drawSource(mapboxRect, mapboxIcon, "Mapbox", mapboxSpeedLimit * speedConversion); - drawSource(nextLimitRect, nextMapsIcon, "Upcoming", nextSpeedLimit * speedConversion); + int rectW = abbreviated ? speedLimitRect.width() : 450; + if (abbreviated) { + // Pre-compute the widest label across all visible rows so every box is the same width. + QFontMetrics fm(InterFont(35, QFont::DemiBold)); + for (auto &s : sources) { + if (activeOnly && s.value == 0) continue; + QString label = s.value != 0 + ? s.abbrev + "-" + QString::number(std::nearbyint(s.value)) + : s.abbrev + "-na"; + int needed = fm.horizontalAdvance(label) + 40; + if (needed > rectW) rectW = needed; + } + } + + for (auto &s : sources) { + if (activeOnly && s.value == 0) continue; + QRect rect(xPos, yPos, rectW, rectH); + drawSource(rect, *s.icon, s.title, s.abbrev, s.value); + yPos += rectH + gap; + } p.restore(); } diff --git a/starpilot/ui/qt/onroad/starpilot_annotated_camera.h b/starpilot/ui/qt/onroad/starpilot_annotated_camera.h index 08596445a..7ba9ac052 100644 --- a/starpilot/ui/qt/onroad/starpilot_annotated_camera.h +++ b/starpilot/ui/qt/onroad/starpilot_annotated_camera.h @@ -114,6 +114,8 @@ private: bool cachedSimpleMode = false; bool cachedSpeedLimitController = false; bool cachedSpeedLimitSources = false; + bool cachedSlcAbbreviatedSources = false; + bool cachedSlcActiveSourcesOnly = false; bool cachedSpeedLimitVienna = false; bool cachedStaticPedalsOnUi = false; bool cachedStoppedTimer = false;