36 bool is_string =
false;
39 bool is_float =
false;
41 bool is_samplerate =
false;
46 bool is_range =
false;
47 bool is_range_noslider =
false;
48 bool is_range_list =
false;
51 std::vector<double> list;
52 std::vector<std::string> list_string;
53 std::array<double, 3> range;
57 std::string _string =
"";
61 std::shared_ptr<widgets::DoubleList> _samplerate;
65 std::vector<OptHolder> opts;
67 inline void get_val(OptHolder &v, nlohmann::json &j)
73 else if (v.is_uint || v.is_freq)
79 else if (v.is_samplerate)
80 j = v._samplerate->get_value();
82 throw satdump_exception(
"Invalid options or JSON value! (GET " + v.id +
")");
86 void add_options(nlohmann::ordered_json options)
89 for (
auto &v : options.items())
96 if (!vv.contains(
"type"))
97 throw satdump_exception(
"Option " + v.key() +
" does not have type!");
100 if (vv.contains(
"hide"))
101 if (vv[
"hide"].get<bool>())
104 if (vv.contains(
"disable"))
105 h.disable = vv[
"disable"].get<
bool>();
107 if (vv.contains(
"name"))
112 h.is_bool = vv[
"type"] ==
"bool";
113 h.is_string = vv[
"type"] ==
"string";
114 h.is_uint = vv[
"type"] ==
"uint";
115 h.is_int = vv[
"type"] ==
"int";
116 h.is_float = vv[
"type"] ==
"float";
117 h.is_freq = vv[
"type"] ==
"freq";
118 h.is_samplerate = vv[
"type"] ==
"samplerate";
120 h.is_list = vv.contains(
"list");
124 h.list_string = vv[
"list"].get<std::vector<std::string>>();
126 h.list = vv[
"list"].get<std::vector<double>>();
129 h.is_range = vv.contains(
"range");
132 h.range = vv[
"range"].get<std::array<double, 3>>();
133 if (vv.contains(
"range_noslider"))
134 h.is_range_noslider = vv[
"range_noslider"];
137 h.is_range_list = h.is_list && h.is_range;
141 h._samplerate = std::make_shared<widgets::DoubleList>(h.name);
142 h._samplerate->set_list(vv[
"list"], getValueOrDefault(vv[
"allow_manual"],
false));
146 if (vv.contains(
"default"))
149 h._bool = vv[
"default"];
150 else if (h.is_string)
151 h._string = vv[
"default"];
153 h._uint = vv[
"default"];
155 h._int = vv[
"default"];
157 h._float = vv[
"default"];
172 void set_values(nlohmann::json vals)
177 if (vals.contains(v.id))
179 auto &j = vals[v.id];
180 if (v.is_bool && j.is_boolean())
182 else if (v.is_string && j.is_string())
184 else if ((v.is_uint || v.is_freq) && j.is_number())
186 else if (v.is_int && j.is_number())
188 else if (v.is_float && j.is_number())
190 else if (v.is_samplerate && j.is_number())
191 v._samplerate->set_value(j);
193 logger->error(
"Invalid options or JSON value! (SET " + v.id +
" => " + j.dump() +
")");
199 nlohmann::json get_values()
204 get_val(v, vals[v.id]);
209 nlohmann::json draw()
217 std::string
id = std::string(v.name +
"##" + std::to_string((
size_t)
this));
218 std::string id_n = std::string(v.name);
221 style::beginDisabled();
225 u |= ImGui::Checkbox(
id.c_str(), &v._bool);
227 else if (v.is_list && v.is_string)
229 if (ImGui::BeginCombo(
id.c_str(), v._string.c_str()))
231 for (
auto &i : v.list_string)
232 if (ImGui::Selectable(i.c_str(), i == v._string))
233 u =
true, v._string = i;
237 else if (v.is_string)
239 ImGui::InputText(
id.c_str(), &v._string);
240 u |= ImGui::IsItemDeactivatedAfterEdit();
242 else if (v.is_range && v.is_int)
246 u |= widgets::SteppedSliderInt(id_n.c_str(), &lv, v.range[0], v.range[1], v.range[2]);
249 else if (v.is_range && v.is_uint)
253 if (v.is_range_noslider)
255 u |= ImGui::InputInt(id_n.c_str(), &lv);
262 u |= widgets::SteppedSliderInt(id_n.c_str(), &lv, v.range[0], v.range[1], v.range[2]);
265 else if (v.is_range && v.is_float)
269 u |= widgets::SteppedSliderFloat(id_n.c_str(), &lv, v.range[0], v.range[1], v.range[2]);
272 else if (v.is_list && v.is_int)
275 if (ImGui::BeginCombo(
id.c_str(), std::to_string(v._int).c_str()))
277 for (
auto &i : v.list)
278 if (ImGui::Selectable(std::to_string(i).c_str(), i == v._int))
279 u =
true, v._int = i;
283 else if (v.is_list && v.is_uint)
286 if (ImGui::BeginCombo(
id.c_str(), std::to_string(v._uint).c_str()))
288 for (
auto &i : v.list)
289 if (ImGui::Selectable(std::to_string(i).c_str(), i == v._uint))
290 u =
true, v._uint = i;
294 else if (v.is_list && v.is_float)
297 if (ImGui::BeginCombo(
id.c_str(), std::to_string(v._float).c_str()))
299 for (
auto &i : v.list)
300 if (ImGui::Selectable(std::to_string(i).c_str(), i == v._float))
301 u =
true, v._float = i;
309 ImGui::InputInt(
id.c_str(), &lv);
310 u |= ImGui::IsItemDeactivatedAfterEdit();
317 ImGui::InputInt(
id.c_str(), &lv);
318 u |= ImGui::IsItemDeactivatedAfterEdit();
324 ImGui::InputDouble(
id.c_str(), &v._float);
325 u |= ImGui::IsItemDeactivatedAfterEdit();
329 u |= widgets::FrequencyInput(
id.c_str(), &v._uint, 0,
false);
332 else if (v.is_samplerate)
334 u |= v._samplerate->render();
338 ImGui::Text(
"Unimplemented : %s",
id.c_str());
342 if (ImGui::Checkbox((
"Manual " + v.name).c_str(), &v.is_range))
343 v.is_list = !v.is_range;
346 style::endDisabled();
349 get_val(v, vals[v.id]);