User Preferences: Numbers string 3/4 digit grouping #116710
|
@ -276,7 +276,8 @@ class USERPREF_PT_interface_editors(InterfacePanel, CenterAlignMixIn, Panel):
|
|||
col.prop(view, "show_navigate_ui")
|
||||
col.prop(view, "color_picker_type")
|
||||
col.row().prop(view, "header_align")
|
||||
col.prop(view, "factor_display_type")
|
||||
col.prop(view, "factor_display_type")
|
||||
col.prop(view, "numbers_format")
|
||||
|
||||
|
||||
class USERPREF_PT_interface_temporary_windows(InterfacePanel, CenterAlignMixIn, Panel):
|
||||
|
|
|
@ -281,9 +281,11 @@ const char *BLI_str_escape_find_quote(const char *str) ATTR_NONNULL(1);
|
|||
*
|
||||
* \param dst: The resulting string.
|
||||
* \param num: Number to format.
|
||||
* \param numbers_format: numbers grouping mode, default value USER_NUMBERS_FORMAT_3 == 0,
|
||||
* see eUserpref_NumbersFormat.
|
||||
* \return The length of \a dst
|
||||
*/
|
||||
size_t BLI_str_format_int_grouped(char dst[BLI_STR_FORMAT_INT32_GROUPED_SIZE], int num)
|
||||
size_t BLI_str_format_int_grouped_n(char dst[BLI_STR_FORMAT_INT32_GROUPED_SIZE], int num, int numbers_format)
|
||||
ATTR_NONNULL(1);
|
||||
/**
|
||||
* Format uint64_t with decimal grouping.
|
||||
|
@ -291,10 +293,16 @@ size_t BLI_str_format_int_grouped(char dst[BLI_STR_FORMAT_INT32_GROUPED_SIZE], i
|
|||
*
|
||||
* \param dst: The resulting string.
|
||||
* \param num: Number to format.
|
||||
* \param numbers_format: numbers grouping mode, default value USER_NUMBERS_FORMAT_3 == 0,
|
||||
* see eUserpref_NumbersFormat.
|
||||
* \return The length of \a dst.
|
||||
*/
|
||||
size_t BLI_str_format_uint64_grouped(char dst[BLI_STR_FORMAT_UINT64_GROUPED_SIZE], uint64_t num)
|
||||
size_t BLI_str_format_uint64_grouped_n(char dst[BLI_STR_FORMAT_UINT64_GROUPED_SIZE], uint64_t num, int numbers_format)
|
||||
ATTR_NONNULL(1);
|
||||
|
||||
#define BLI_str_format_int_grouped(dst,num) BLI_str_format_int_grouped_n(dst,num,USER_NUMBERS_FORMAT_3)
|
||||
#define BLI_str_format_uint64_grouped(dst,num) BLI_str_format_uint64_grouped_n(dst,num,USER_NUMBERS_FORMAT_3)
|
||||
|
||||
/**
|
||||
* Format a size in bytes using binary units.
|
||||
* 1000 -> 1 KB
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
#include "BLI_strict_flags.h"
|
||||
|
||||
#include "DNA_userdef_types.h" /* For eUserpref_NumbersFormat. */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name String Duplicate/Copy
|
||||
* \{ */
|
||||
|
@ -1121,7 +1123,7 @@ int BLI_string_find_split_words(
|
|||
/** \name String Formatting (Numeric)
|
||||
* \{ */
|
||||
|
||||
static size_t BLI_str_format_int_grouped_ex(char *src, char *dst, int num_len)
|
||||
static size_t BLI_str_format_int_grouped_ex(char *src, char *dst, int num_len, int numbers_format)
|
||||
{
|
||||
char *p_src = src;
|
||||
char *p_dst = dst;
|
||||
|
@ -1134,7 +1136,12 @@ static size_t BLI_str_format_int_grouped_ex(char *src, char *dst, int num_len)
|
|||
num_len--;
|
||||
}
|
||||
|
||||
for (commas = 2 - num_len % 3; *p_src; commas = (commas + 1) % 3) {
|
||||
|
||||
int group=3;
|
||||
if (numbers_format == USER_NUMBERS_FORMAT_3){ group=3; }
|
||||
else if (numbers_format == USER_NUMBERS_FORMAT_4){ group=4; }
|
||||
|
||||
for (commas = 2 - num_len % group; *p_src; commas = (commas + 1) % group) {
|
||||
*p_dst++ = *p_src++;
|
||||
if (commas == 1) {
|
||||
*p_dst++ = separator;
|
||||
|
@ -1145,7 +1152,7 @@ static size_t BLI_str_format_int_grouped_ex(char *src, char *dst, int num_len)
|
|||
return (size_t)(p_dst - dst);
|
||||
}
|
||||
|
||||
size_t BLI_str_format_int_grouped(char dst[BLI_STR_FORMAT_INT32_GROUPED_SIZE], int num)
|
||||
size_t BLI_str_format_int_grouped_n(char dst[BLI_STR_FORMAT_INT32_GROUPED_SIZE], int num, int numbers_format)
|
||||
{
|
||||
const size_t dst_maxncpy = BLI_STR_FORMAT_INT32_GROUPED_SIZE;
|
||||
BLI_string_debug_size(dst, dst_maxncpy);
|
||||
|
@ -1154,10 +1161,10 @@ size_t BLI_str_format_int_grouped(char dst[BLI_STR_FORMAT_INT32_GROUPED_SIZE], i
|
|||
char src[BLI_STR_FORMAT_INT32_GROUPED_SIZE];
|
||||
const int num_len = (int)SNPRINTF(src, "%d", num);
|
||||
|
||||
return BLI_str_format_int_grouped_ex(src, dst, num_len);
|
||||
return BLI_str_format_int_grouped_ex(src, dst, num_len, numbers_format);
|
||||
}
|
||||
|
||||
size_t BLI_str_format_uint64_grouped(char dst[BLI_STR_FORMAT_UINT64_GROUPED_SIZE], uint64_t num)
|
||||
size_t BLI_str_format_uint64_grouped_n(char dst[BLI_STR_FORMAT_UINT64_GROUPED_SIZE], uint64_t num, int numbers_format)
|
||||
{
|
||||
const size_t dst_maxncpy = BLI_STR_FORMAT_UINT64_GROUPED_SIZE;
|
||||
BLI_string_debug_size(dst, dst_maxncpy);
|
||||
|
@ -1166,7 +1173,7 @@ size_t BLI_str_format_uint64_grouped(char dst[BLI_STR_FORMAT_UINT64_GROUPED_SIZE
|
|||
char src[BLI_STR_FORMAT_UINT64_GROUPED_SIZE];
|
||||
const int num_len = (int)SNPRINTF(src, "%" PRIu64 "", num);
|
||||
|
||||
return BLI_str_format_int_grouped_ex(src, dst, num_len);
|
||||
return BLI_str_format_int_grouped_ex(src, dst, num_len, numbers_format);
|
||||
}
|
||||
|
||||
void BLI_str_format_byte_unit(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE],
|
||||
|
|
|
@ -499,7 +499,7 @@ static bool format_stats(
|
|||
SceneStats *stats = *stats_p;
|
||||
|
||||
/* Generate formatted numbers. */
|
||||
#define SCENE_STATS_FMT_INT(_id) BLI_str_format_uint64_grouped(stats_fmt->_id, stats->_id)
|
||||
#define SCENE_STATS_FMT_INT(_id) BLI_str_format_uint64_grouped_n(stats_fmt->_id, stats->_id, U.numbers_format)
|
||||
|
||||
SCENE_STATS_FMT_INT(totvert);
|
||||
SCENE_STATS_FMT_INT(totvertsel);
|
||||
|
|
|
@ -1029,7 +1029,8 @@ typedef struct UserDef {
|
|||
|
||||
float collection_instance_empty_size;
|
||||
char text_flag;
|
||||
char _pad10[1];
|
||||
|
||||
char numbers_format; /* eUserpref_NumbersFormat */
|
||||
|
||||
char file_preview_type; /* eUserpref_File_Preview_Type */
|
||||
char statusbar_flag; /* eUserpref_StatusBar_Flag */
|
||||
|
@ -1508,3 +1509,8 @@ enum {
|
|||
ULANGUAGE_AUTO = 0,
|
||||
ULANGUAGE_ENGLISH = 1,
|
||||
};
|
||||
|
||||
typedef enum eUserpref_NumbersFormat{
|
||||
USER_NUMBERS_FORMAT_3 = 0,
|
||||
USER_NUMBERS_FORMAT_4 = 1,
|
||||
}eUserpref_NumbersFormat;
|
||||
|
|
|
@ -5042,6 +5042,13 @@ static void rna_def_userdef_view(BlenderRNA *brna)
|
|||
{0, nullptr, 0, nullptr, nullptr},
|
||||
};
|
||||
|
||||
/* Numbers format. */
|
||||
static const EnumPropertyItem numbers_format_items[] = {
|
||||
{USER_NUMBERS_FORMAT_3, "FORMAT_3", 0, "3-Digit Groups", ""},
|
||||
{USER_NUMBERS_FORMAT_4, "FORMAT_4", 0, "4-Digit Groups", ""},
|
||||
{0, nullptr, 0, nullptr, nullptr},
|
||||
};
|
||||
|
||||
prop = RNA_def_property(srna, "mini_axis_type", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_items(prop, mini_axis_type_items);
|
||||
RNA_def_property_ui_text(
|
||||
|
@ -5227,6 +5234,12 @@ static void rna_def_userdef_view(BlenderRNA *brna)
|
|||
RNA_def_property_boolean_sdna(prop, nullptr, "statusbar_flag", STATUSBAR_SHOW_SCENE_DURATION);
|
||||
RNA_def_property_ui_text(prop, "Show Scene Duration", "Show scene duration");
|
||||
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_INFO, "rna_userdef_update");
|
||||
|
||||
prop = RNA_def_property(srna, "numbers_format", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_items(prop, numbers_format_items);
|
||||
RNA_def_property_ui_text(
|
||||
prop, "Numbers Format", "How to group long numbers");
|
||||
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_INFO, "rna_userdef_update");
|
||||
}
|
||||
|
||||
static void rna_def_userdef_edit(BlenderRNA *brna)
|
||||
|
|
Loading…
Reference in New Issue