summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWoochanlee <wc0917.lee@samsung.com>2020-02-19 21:09:15 +0900
committerJaehyun Cho <jae_hyun.cho@samsung.com>2020-02-19 21:09:15 +0900
commitb8a24679a6f7995ccc1da19eb86c6c2ef6826d1a (patch)
tree3e558e07fa4d30149b98577235d78c8d0048ba13
parentdf0715a9aa27903dd549c2b4516ab2cba0274413 (diff)
elm_spinner: Fixed to apply the %d format.
Summary: The part object does not apply the logic in efl_ui_format, so it does not work correctly when you format it with %d. This is the commit that gets the necessary part of the logic of efl_ui_format. Test Plan: elementary_test Reviewers: Jaehyun_Cho Reviewed By: Jaehyun_Cho Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D11378
-rw-r--r--src/lib/elementary/elm_slider.c102
-rw-r--r--src/lib/elementary/elm_widget_slider.h1
2 files changed, 97 insertions, 6 deletions
diff --git a/src/lib/elementary/elm_slider.c b/src/lib/elementary/elm_slider.c
index 2c6c26b84d..a533fd5188 100644
--- a/src/lib/elementary/elm_slider.c
+++ b/src/lib/elementary/elm_slider.c
@@ -1349,16 +1349,44 @@ _elm_slider_part_indicator_efl_ui_format_format_cb_set(Eo *obj, void *_pd EINA_U
1349} 1349}
1350 1350
1351static Eina_Bool 1351static Eina_Bool
1352_do_format_string(Elm_Slider_Data *sd, Eina_Strbuf *str, const Eina_Value value)
1353{
1354 switch (sd->indi_format_int)
1355 {
1356 case 0:
1357 {
1358 double v = 0.0;
1359 if (!eina_value_double_convert(&value, &v))
1360 ERR("Format conversion failed");
1361 eina_strbuf_append_printf(str, sd->indi_template, v);
1362 break;
1363 }
1364 case 1:
1365 {
1366 int v = 0;
1367 if (!eina_value_int_convert(&value, &v))
1368 ERR("Format conversion failed");
1369 eina_strbuf_append_printf(str, sd->indi_template, v);
1370 break;
1371 }
1372 default:
1373 return EINA_FALSE;
1374 }
1375 return EINA_TRUE;
1376}
1377
1378static Eina_Bool
1352_indi_default_format_cb(void *data, Eina_Strbuf *str, const Eina_Value value) 1379_indi_default_format_cb(void *data, Eina_Strbuf *str, const Eina_Value value)
1353{ 1380{
1354 const Eina_Value_Type *type = eina_value_type_get(&value);
1355 Elm_Slider_Data *sd = efl_data_scope_get(data, ELM_SLIDER_CLASS); 1381 Elm_Slider_Data *sd = efl_data_scope_get(data, ELM_SLIDER_CLASS);
1356 double v;
1357
1358 if (type != EINA_VALUE_TYPE_DOUBLE) return EINA_FALSE;
1359 1382
1360 eina_value_get(&value, &v); 1383 if (!_do_format_string(sd, str, value))
1361 eina_strbuf_append_printf(str, sd->indi_template, v); 1384 {
1385 /* Fallback to just printing the value if format string fails (legacy behavior) */
1386 char *v = eina_value_to_string(&value);
1387 eina_strbuf_append(str, v);
1388 free(v);
1389 }
1362 1390
1363 return EINA_TRUE; 1391 return EINA_TRUE;
1364} 1392}
@@ -1375,6 +1403,67 @@ _indi_default_format_free_cb(void *data)
1375 } 1403 }
1376} 1404}
1377 1405
1406static Eina_Bool
1407_is_valid_digit(char x)
1408{
1409 return ((x >= '0' && x <= '9') || (x == '.')) ? EINA_TRUE : EINA_FALSE;
1410}
1411
1412static Eina_Bool
1413_format_string_check(const char *fmt)
1414{
1415 const char *itr;
1416 Eina_Bool found = EINA_FALSE;
1417 Eina_Bool ret = EINA_FALSE;
1418
1419 for (itr = fmt; *itr; itr++)
1420 {
1421 if (itr[0] != '%') continue;
1422 if (itr[1] == '%')
1423 {
1424 itr++;
1425 continue;
1426 }
1427
1428 if (!found)
1429 {
1430 found = EINA_TRUE;
1431 for (itr++; *itr; itr++)
1432 {
1433 // FIXME: This does not properly support int64 or unsigned.
1434 if ((*itr == 'd') || (*itr == 'u') || (*itr == 'i') ||
1435 (*itr == 'o') || (*itr == 'x') || (*itr == 'X'))
1436 {
1437 ret = EINA_TRUE;
1438 break;
1439 }
1440 else if ((*itr == 'f') || (*itr == 'F'))
1441 {
1442 ret = EINA_FALSE;
1443 break;
1444 }
1445 else if (_is_valid_digit(*itr))
1446 {
1447 continue;
1448 }
1449 else
1450 {
1451 ERR("Format string '%s' has unknown format element '%c' in format. It must have one format element of type 's', 'f', 'F', 'd', 'u', 'i', 'o', 'x' or 'X'", fmt, *itr);
1452 found = EINA_FALSE;
1453 break;
1454 }
1455 }
1456 if (!(*itr)) break;
1457 }
1458 else
1459 {
1460 break;
1461 }
1462 }
1463
1464 return ret;
1465}
1466
1378EOLIAN static void 1467EOLIAN static void
1379_elm_slider_part_indicator_efl_ui_format_format_string_set(Eo *obj, void *_pd EINA_UNUSED, const char *template, Efl_Ui_Format_String_Type type EINA_UNUSED) 1468_elm_slider_part_indicator_efl_ui_format_format_string_set(Eo *obj, void *_pd EINA_UNUSED, const char *template, Efl_Ui_Format_String_Type type EINA_UNUSED)
1380{ 1469{
@@ -1383,6 +1472,7 @@ _elm_slider_part_indicator_efl_ui_format_format_string_set(Eo *obj, void *_pd EI
1383 1472
1384 if (!template) return; 1473 if (!template) return;
1385 eina_stringshare_replace(&sd->indi_template, template); 1474 eina_stringshare_replace(&sd->indi_template, template);
1475 sd->indi_format_int = _format_string_check(sd->indi_template);
1386 1476
1387 efl_ui_format_func_set(efl_part(pd->obj, "indicator"), pd->obj, _indi_default_format_cb, _indi_default_format_free_cb); 1477 efl_ui_format_func_set(efl_part(pd->obj, "indicator"), pd->obj, _indi_default_format_cb, _indi_default_format_free_cb);
1388} 1478}
diff --git a/src/lib/elementary/elm_widget_slider.h b/src/lib/elementary/elm_widget_slider.h
index 8290045f8d..c18f554e8c 100644
--- a/src/lib/elementary/elm_widget_slider.h
+++ b/src/lib/elementary/elm_widget_slider.h
@@ -53,6 +53,7 @@ struct _Elm_Slider_Data
53 void *indi_format_cb_data; 53 void *indi_format_cb_data;
54 Eina_Strbuf *indi_format_strbuf; 54 Eina_Strbuf *indi_format_strbuf;
55 const char *indi_template; 55 const char *indi_template;
56 Eina_Bool indi_format_int;
56 57
57 58
58 Eina_Bool indicator_show : 1; 59 Eina_Bool indicator_show : 1;