[Bf-blender-cvs] [f712c243a45] temp-angavrilov: RNA: add a property flag to display exact integer values without fraction.

Alexander Gavrilov noreply at git.blender.org
Wed Jan 12 21:09:12 CET 2022


Commit: f712c243a4541c34371386d2e05d22e576582e08
Author: Alexander Gavrilov
Date:   Sun Dec 26 18:09:19 2021 +0300
Branches: temp-angavrilov
https://developer.blender.org/rBf712c243a4541c34371386d2e05d22e576582e08

RNA: add a property flag to display exact integer values without fraction.

Add a flag to display exact integer values of a floating point field
without a fraction, for use in case when the value can technically be
fractional, but most commonly is supposed to be integer.

The fraction is discarded in the normal display mode and when copying
the value to clipboard, but not when editing to remind the user that
the field allows fractions.

Also, fix a precision issue when stepping down from 1 to 0 via the
left decrement button and step 100 results in a small nonzero value.

Differential Revision: https://developer.blender.org/D13753

===================================================================

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/makesrna/RNA_types.h
M	source/blender/makesrna/intern/rna_action.c
M	source/blender/python/intern/bpy_props.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 9ce07cd2e07..56a01b78f06 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -311,6 +311,9 @@ enum {
 
   /* Draw the checkbox buttons inverted. */
   UI_BUT_CHECKBOX_INVERT = 1 << 25,
+
+  /** Hide float fraction if the value is an exact integer. */
+  UI_BUT_HIDE_NULL_FRACTION = 1 << 26,
 };
 
 /* scale fixed button widths by this to account for DPI */
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index a275a59a4e7..93f4df6f2cb 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -661,8 +661,17 @@ static float ui_but_get_float_precision(uiBut *but)
   return but->a2;
 }
 
+static bool ui_but_hide_fraction(uiBut *but, double value)
+{
+  return (but->drawflag & UI_BUT_HIDE_NULL_FRACTION) && floor(value) == value;
+}
+
 static int ui_but_calc_float_precision(uiBut *but, double value)
 {
+  if (ui_but_hide_fraction(but, value)) {
+    return 0;
+  }
+
   int prec = (int)ui_but_get_float_precision(but);
 
   /* first check for various special cases:
@@ -2813,8 +2822,11 @@ void ui_but_string_get_ex(uiBut *but,
     }
 
     if (ui_but_is_float(but)) {
-      int prec = (float_precision == -1) ? ui_but_calc_float_precision(but, value) :
-                                           float_precision;
+      int prec = float_precision;
+
+      if (float_precision == -1 || (!use_exp_float && ui_but_hide_fraction(but, value))) {
+        prec = ui_but_calc_float_precision(but, value);
+      }
 
       if (ui_but_is_unit(but)) {
         ui_get_but_string_unit(but, str, maxlen, value, false, prec);
@@ -4569,6 +4581,10 @@ static uiBut *ui_def_but_rna(uiBlock *block,
     /* Set default values, can be overridden later. */
     UI_but_number_step_size_set(but, a1);
     UI_but_number_precision_set(but, a2);
+
+    if (RNA_property_flag(prop) & PROP_HIDE_NULL_FRACTION) {
+      but->drawflag |= UI_BUT_HIDE_NULL_FRACTION;
+    }
   }
 
   but->rnapoin = *ptr;
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 6ecaead67ce..905fd452b6c 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -5484,7 +5484,7 @@ static int ui_do_but_NUM(
                                 log10f(number_but->step_size));
         }
         else {
-          value_step = (double)number_but->step_size * UI_PRECISION_FLOAT_SCALE;
+          value_step = (double)(number_but->step_size * UI_PRECISION_FLOAT_SCALE);
         }
         BLI_assert(value_step > 0.0f);
         const double value_test = (but->drawflag & UI_BUT_ACTIVE_LEFT) ?
diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h
index 2d499dd113f..209aa4b26fa 100644
--- a/source/blender/makesrna/RNA_types.h
+++ b/source/blender/makesrna/RNA_types.h
@@ -193,7 +193,7 @@ typedef enum PropertySubType {
 
 /* Make sure enums are updated with these */
 /* HIGHEST FLAG IN USE: 1 << 31
- * FREE FLAGS: 2, 9, 11, 13, 14, 15, 30 */
+ * FREE FLAGS: 2, 9, 11, 13, 14 */
 typedef enum PropertyFlag {
   /**
    * Editable means the property is editable in the user
@@ -236,6 +236,9 @@ typedef enum PropertyFlag {
   /** Each value is related proportionally (object scale, image size). */
   PROP_PROPORTIONAL = (1 << 26),
 
+  /** When a float property value is an exact integer, hide the fraction. */
+  PROP_HIDE_NULL_FRACTION = (1 << 15),
+
   /* pointers */
   PROP_ID_REFCOUNT = (1 << 6),
 
diff --git a/source/blender/makesrna/intern/rna_action.c b/source/blender/makesrna/intern/rna_action.c
index 90d5b0f3686..36b41f63dc7 100644
--- a/source/blender/makesrna/intern/rna_action.c
+++ b/source/blender/makesrna/intern/rna_action.c
@@ -916,18 +916,20 @@ static void rna_def_action(BlenderRNA *brna)
 
   prop = RNA_def_property(srna, "frame_start", PROP_FLOAT, PROP_TIME);
   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+  RNA_def_property_flag(prop, PROP_HIDE_NULL_FRACTION);
   RNA_def_property_float_sdna(prop, NULL, "frame_start");
   RNA_def_property_float_funcs(prop, NULL, "rna_Action_start_frame_set", NULL);
-  RNA_def_property_ui_range(prop, MINFRAME, MAXFRAME, 100, 0);
+  RNA_def_property_ui_range(prop, MINFRAME, MAXFRAME, 100, 2);
   RNA_def_property_ui_text(
       prop, "Start Frame", "The start frame of the manually set intended playback range");
   RNA_def_property_update(prop, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL);
 
   prop = RNA_def_property(srna, "frame_end", PROP_FLOAT, PROP_TIME);
   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+  RNA_def_property_flag(prop, PROP_HIDE_NULL_FRACTION);
   RNA_def_property_float_sdna(prop, NULL, "frame_end");
   RNA_def_property_float_funcs(prop, NULL, "rna_Action_end_frame_set", NULL);
-  RNA_def_property_ui_range(prop, MINFRAME, MAXFRAME, 100, 0);
+  RNA_def_property_ui_range(prop, MINFRAME, MAXFRAME, 100, 2);
   RNA_def_property_ui_text(
       prop, "End Frame", "The end frame of the manually set intended playback range");
   RNA_def_property_update(prop, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL);
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c
index ed9547ee13f..dfac1e7c991 100644
--- a/source/blender/python/intern/bpy_props.c
+++ b/source/blender/python/intern/bpy_props.c
@@ -59,6 +59,7 @@ static const EnumPropertyItem property_flag_items[] = {
     {PROP_ANIMATABLE, "ANIMATABLE", 0, "Animatable", ""},
     {PROP_LIB_EXCEPTION, "LIBRARY_EDITABLE", 0, "Library Editable", ""},
     {PROP_PROPORTIONAL, "PROPORTIONAL", 0, "Adjust values proportionally to eachother", ""},
+    {PROP_HIDE_NULL_FRACTION, "HIDE_NULL_FRACTION", 0, "Hide float fraction if the value is an exact integer", ""},
     {PROP_TEXTEDIT_UPDATE,
      "TEXTEDIT_UPDATE",
      0,



More information about the Bf-blender-cvs mailing list