|
20 | 20 | */
|
21 | 21 |
|
22 | 22 | #include "mpm_settings.h"
|
| 23 | +#include "choice.h" |
23 | 24 | #include "opentx.h"
|
24 | 25 |
|
25 | 26 | #include "multi_rfprotos.h"
|
@@ -148,9 +149,31 @@ void MPMProtoOption::update(const MultiRfProtocols::RfProto* rfProto, ModuleData
|
148 | 149 | }
|
149 | 150 | }
|
150 | 151 |
|
| 152 | +struct MPMSubtypeChoice : public Choice { |
| 153 | + MPMSubtypeChoice(Window* parent, std::function<int()> get, |
| 154 | + std::function<void(int)> set) : |
| 155 | + Choice(parent, rect_t{}, 0, 0, get, set) |
| 156 | + { |
| 157 | + } |
| 158 | + |
| 159 | + std::string getLabelText() override |
| 160 | + { |
| 161 | + if (_getValue) { |
| 162 | + int val = _getValue(); |
| 163 | + val -= vmin; |
| 164 | + if (val >= 0 && val < (int)values.size()) { |
| 165 | + return values[val]; |
| 166 | + } else { |
| 167 | + return std::to_string(val); |
| 168 | + } |
| 169 | + } |
| 170 | + return std::string(); |
| 171 | + } |
| 172 | +}; |
| 173 | + |
151 | 174 | struct MPMSubtype : public FormWindow::Line
|
152 | 175 | {
|
153 |
| - Choice* choice; |
| 176 | + MPMSubtypeChoice* choice; |
154 | 177 |
|
155 | 178 | MPMSubtype(FormWindow* form, FlexGridLayout *layout, uint8_t moduleIdx);
|
156 | 179 | void update(const MultiRfProtocols::RfProto* rfProto, uint8_t moduleIdx);
|
@@ -198,11 +221,11 @@ MPMSubtype::MPMSubtype(FormWindow* form, FlexGridLayout *layout, uint8_t moduleI
|
198 | 221 | new StaticText(this, rect_t{}, STR_RF_PROTOCOL, 0, COLOR_THEME_PRIMARY1);
|
199 | 222 |
|
200 | 223 | auto md = &g_model.moduleData[moduleIdx];
|
201 |
| - choice = new Choice( |
202 |
| - this, rect_t{}, 0, 0, [=]() { return md->subType; }, |
| 224 | + choice = new MPMSubtypeChoice( |
| 225 | + this, [=]() { return md->subType; }, |
203 | 226 | [=](int16_t newValue) {
|
204 | 227 | md->subType = newValue;
|
205 |
| - if(!DSM2autoUpdated) // reset MPM options only if user triggered |
| 228 | + if(!DSM2autoUpdated) // reset MPM options only if user triggered |
206 | 229 | resetMultiProtocolsOptions(moduleIdx);
|
207 | 230 | DSM2autoUpdated = false;
|
208 | 231 | SET_DIRTY();
|
|
0 commit comments