Mark a per-stick dead zone row as default at the shared value, and unset it when stepped back onto that value.

This commit is contained in:
Wellington Dias committed 2026-11-01 13:53:53 -03:00
1 parent 2215c3fc2f
commit 88e044dcd3
2 files changed
+8 -3

No files matched your search

+6 -2
View File
@@ -353,7 +353,10 @@ bool opt_slider(const char *key, UiTextId label, float lo, float hi, UiTextId de
const char *set = cfg_get(key);
const char *src = fallback && !(set && *set) ? fallback : key; // unset: show the value in effect, the fallback's
const CfgMeta *m = cfg_meta(src);
double v = cfg_double(src), def = m ? strtod(m->def, NULL) : lo;
// A key without a table default of its own (the per-stick dead zones) defaults to its fallback: the "default" mark
// follows the fallback's default, not 0, even once the key is set.
if (fallback && m && !m->def[0]) m = cfg_meta(fallback);
double v = cfg_double(src), def = m && m->def[0] ? strtod(m->def, NULL) : lo;
char shown[48];
snprintf(shown, sizeof shown, fmt, v);
RowView rv = {shown, fabs(v - def) < step * 0.01, true, note};
@@ -367,7 +370,8 @@ bool opt_slider(const char *key, UiTextId label, float lo, float hi, UiTextId de
char out[32];
if (step >= 1) snprintf(out, sizeof out, "%d", (int)lround(n));
else snprintf(out, sizeof out, "%g", round(n / step) * step);
apply(key, out);
// Landing on the fallback's value unsets the key (its line leaves totk.ini), so the row follows the fallback again.
apply(key, fallback && fabs(n - cfg_double(fallback)) < step * 0.01 ? "" : out);
return true;
}
+2 -1
View File
@@ -61,7 +61,8 @@ void opt_group_text(const char *title);
void opt_text_str(const char *text, bool warn = false);
// lo..hi in steps of step (left and right held for a second go ten times as fast); fmt formats the value ("%.0f %%").
// note: a short line under the value in place of the "default" mark (NULL: none). fallback: the setting that applies
// while key is unset; the row shows its value then, and a change sets key.
// while key is unset; the row shows its value then, and a change sets key. A key with no table default of its own takes
// the "default" mark from the fallback's default, and a step onto the fallback's value unsets key again.
bool opt_slider(const char *key, UiTextId label, float lo, float hi, UiTextId desc, float step = 1,
const char *fmt = "%g", const char *note = nullptr, const char *fallback = nullptr);