From d8faa2a6ea026e782b5a8a68d664ef7bd96b4ece Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Mon, 6 Nov 2023 16:15:07 -0500 Subject: [PATCH] ui: SLC: Common description builder --- .../speed_limit_control_settings.cc | 2 +- .../sunnypilot/speed_limit_control_settings.h | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/selfdrive/ui/qt/offroad/sunnypilot/speed_limit_control_settings.cc b/selfdrive/ui/qt/offroad/sunnypilot/speed_limit_control_settings.cc index 9bc6c1b57f..9df335be1a 100644 --- a/selfdrive/ui/qt/offroad/sunnypilot/speed_limit_control_settings.cc +++ b/selfdrive/ui/qt/offroad/sunnypilot/speed_limit_control_settings.cc @@ -66,7 +66,7 @@ void SlcSettings::updateToggles() { auto custom_stock_long_param = params.getBool("CustomStockLong"); auto speed_limit_control = params.getBool("EnableSlc"); - speed_limit_control_policy->setDescription(slcPolicyDescriptionBuilder("SpeedLimitControlPolicy")); + speed_limit_control_policy->setDescription(slcDescriptionBuilder("SpeedLimitControlPolicy", speed_limit_control_policy_descriptions)); if (!cp_bytes.empty()) { AlignedBuffer aligned_buf; diff --git a/selfdrive/ui/qt/offroad/sunnypilot/speed_limit_control_settings.h b/selfdrive/ui/qt/offroad/sunnypilot/speed_limit_control_settings.h index 5d8b2c7a7e..3e61f5375d 100644 --- a/selfdrive/ui/qt/offroad/sunnypilot/speed_limit_control_settings.h +++ b/selfdrive/ui/qt/offroad/sunnypilot/speed_limit_control_settings.h @@ -41,20 +41,24 @@ private: ButtonParamControl *speed_limit_offset_settings; ParamWatcher *param_watcher; - QString slcPolicyDescriptionBuilder(QString param) { + QString slcDescriptionBuilder(QString param, std::vector descriptions) { std::string key = param.toStdString(); int value = atoi(params.get(key).c_str()); - QString description = tr("Select the precedence order of sources used to adapt cruise speed to road limits:"); - description += "

"; + value += 1; // always bump one due to first line being generic description + QString description = ""; - for (int i = 0; i < speed_limit_control_policy_descriptions.size(); i++) { - if (i == value) { - description += "" + speed_limit_control_policy_descriptions[i] + ""; - } else { - description += speed_limit_control_policy_descriptions[i]; + for (int i = 0; i < descriptions.size(); i++) { + if (i == 1) { + description += "

"; } - if (i < speed_limit_control_policy_descriptions.size() - 1) { + if (i == value) { + description += "" + descriptions[i] + ""; + } else { + description += descriptions[i]; + } + + if ((i > 0) && (i < descriptions.size() - 1)) { description += "
"; } } @@ -74,6 +78,7 @@ inline const std::vector SlcSettings::speed_limit_control_policy_texts{ }; inline const std::vector SlcSettings::speed_limit_control_policy_descriptions{ + tr("Select the precedence order of sources used to adapt cruise speed to road limits:"), tr("Nav Only: Data from Mapbox active navigation only."), tr("Map Only: Data from OpenStreetMap only."), tr("Car Only: Data from the car's built-in sources (if available)."),