diff options
author | Kacper Michajłow <kasper93@gmail.com> | 2023-11-19 21:22:24 +0100 |
---|---|---|
committer | Kacper Michajłow <kasper93@gmail.com> | 2024-03-21 03:50:11 +0100 |
commit | 8708f4dc918b1bc005149c50abb3d54d66ed3047 (patch) | |
tree | a542bb97e54ba7f6287c755ece5fe1d73bd4b910 /options/m_property.c | |
parent | c84bb1ce67f2dd3adb974c49a66d28c0cf55d39d (diff) | |
download | mpv-8708f4dc918b1bc005149c50abb3d54d66ed3047.tar.bz2 mpv-8708f4dc918b1bc005149c50abb3d54d66ed3047.tar.xz |
m_property: add `>` for fixed precision floating-point expansion
This enhancement makes it easier to create constant width property
expansions, useful for the `--term-status-msg`. Additionally, it changes
to `%f` printing with manual zero trimming, which is easier to control
than `%g`. With this method, we can directly specify precision, not just
significant numbers. This approach also avoids overly high precision for
values less than 1, which is not necessary for a generic floating-point
print function.
A new print helper function is added, which can be used with adjusted
precision for specific cases where a different default is needed. This
also unifies the code slightly.
Diffstat (limited to 'options/m_property.c')
-rw-r--r-- | options/m_property.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/options/m_property.c b/options/m_property.c index 1b76f05e7d..eb3f78e847 100644 --- a/options/m_property.c +++ b/options/m_property.c @@ -108,13 +108,14 @@ int m_property_do(struct mp_log *log, const struct m_property *prop_list, assert(opt.type); switch (action) { + case M_PROPERTY_FIXED_LEN_PRINT: case M_PROPERTY_PRINT: { - if ((r = do_action(prop_list, name, M_PROPERTY_PRINT, arg, ctx)) >= 0) + if ((r = do_action(prop_list, name, action, arg, ctx)) >= 0) return r; // Fallback to m_option if ((r = do_action(prop_list, name, M_PROPERTY_GET, &val, ctx)) <= 0) return r; - char *str = m_option_pretty_print(&opt, &val); + char *str = m_option_pretty_print(&opt, &val, action == M_PROPERTY_FIXED_LEN_PRINT); m_option_free(&opt, &val); *(char **)arg = str; return str != NULL; @@ -258,11 +259,13 @@ static int expand_property(const struct m_property *prop_list, char **ret, bool cond_no = !cond_yes && bstr_eatstart0(&prop, "!"); bool test = cond_yes || cond_no; bool raw = bstr_eatstart0(&prop, "="); + bool fixed_len = !raw && bstr_eatstart0(&prop, ">"); bstr comp_with = {0}; bool comp = test && bstr_split_tok(prop, "==", &prop, &comp_with); if (test && !comp) raw = true; int method = raw ? M_PROPERTY_GET_STRING : M_PROPERTY_PRINT; + method = fixed_len ? M_PROPERTY_FIXED_LEN_PRINT : method; char *s = NULL; int r = m_property_do_bstr(prop_list, prop, method, &s, ctx); |