Added gauge label format function
@@ -84,6 +84,7 @@ lv_obj_t * lv_gauge_create(lv_obj_t * par, const lv_obj_t * copy)
ext->values = NULL;
ext->needle_colors = NULL;
ext->label_count = LV_GAUGE_DEF_LABEL_COUNT;
+ ext->value_format_cb = NULL;
ext->needle_img = 0;
ext->needle_img_pivot.x = 0;
@@ -118,6 +119,7 @@ lv_obj_t * lv_gauge_create(lv_obj_t * par, const lv_obj_t * copy)
ext->values[i] = copy_ext->values[i];
}
ext->label_count = copy_ext->label_count;
+ ext->value_format_cb = copy_ext->value_format_cb;
/*Refresh the style with new signal function*/
lv_obj_refresh_style(new_gauge, LV_STYLE_PROP_ALL);
@@ -237,6 +239,20 @@ void lv_gauge_set_needle_img(lv_obj_t * gauge, const void * img, lv_coord_t pivo
lv_obj_invalidate(gauge);
}
+/**
+ * Assign a function to format gauge values
+ * @param gauge pointer to a gauge object
+ * @param value_format_fn pointer to function of value_format_type
+ */
+void lv_gauge_set_formatter(lv_obj_t * gauge, value_format_type value_format_fn)
+{
+ LV_ASSERT_OBJ(gauge, LV_OBJX_NAME);
+
+ lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge);
+
+ ext->value_format_cb = value_format_fn;
+}
+
/*=====================
* Getter functions
*====================*/
@@ -474,7 +490,10 @@ static void lv_gauge_draw_labels(lv_obj_t * gauge, const lv_area_t * mask)
int16_t scale_act = (int32_t)((int32_t)(max - min) * i) / (label_num - 1);
scale_act += min;
+ if(ext->value_format_cb == NULL)
lv_utils_num_to_str(scale_act, scale_txt);
+ else
+ ext->value_format_cb(gauge, scale_txt, sizeof(scale_txt), scale_act);
lv_area_t label_cord;
lv_point_t label_size;
