summaryrefslogtreecommitdiffstats
path: root/options/m_option.h
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2023-11-19 21:22:24 +0100
committerKacper Michajłow <kasper93@gmail.com>2024-03-21 03:50:11 +0100
commit8708f4dc918b1bc005149c50abb3d54d66ed3047 (patch)
treea542bb97e54ba7f6287c755ece5fe1d73bd4b910 /options/m_option.h
parentc84bb1ce67f2dd3adb974c49a66d28c0cf55d39d (diff)
downloadmpv-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_option.h')
-rw-r--r--options/m_option.h13
1 files changed, 10 insertions, 3 deletions
diff --git a/options/m_option.h b/options/m_option.h
index 891b51794e..530c0a3d50 100644
--- a/options/m_option.h
+++ b/options/m_option.h
@@ -463,6 +463,9 @@ char *format_file_size(int64_t size);
// type channels: disallow "auto" (still accept ""), limit list to at most 1 item.
#define M_OPT_CHANNELS_LIMITED (1 << 27)
+// type_float/type_double: controls if pretty print should trim trailing zeros
+#define M_OPT_FIXED_LEN_PRINT (1 << 28)
+
// Like M_OPT_TYPE_OPTIONAL_PARAM.
#define M_OPT_OPTIONAL_PARAM (1 << 30)
@@ -536,12 +539,16 @@ static inline char *m_option_print(const m_option_t *opt, const void *val_ptr)
}
static inline char *m_option_pretty_print(const m_option_t *opt,
- const void *val_ptr)
+ const void *val_ptr,
+ bool fixed_len)
{
+ m_option_t o = *opt;
+ if (fixed_len)
+ o.flags |= M_OPT_FIXED_LEN_PRINT;
if (opt->type->pretty_print)
- return opt->type->pretty_print(opt, val_ptr);
+ return opt->type->pretty_print(&o, val_ptr);
else
- return m_option_print(opt, val_ptr);
+ return m_option_print(&o, val_ptr);
}
// Helper around \ref m_option_type::copy.