summaryrefslogtreecommitdiff
path: root/src/lib/elementary/efl_ui_spin_button.c
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-07-05 19:09:43 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-07-08 19:56:40 +0200
commitd8f32042c46e0090178249c6556d26277650313c (patch)
tree5235a13bb51e4e48b6747468d68e3004d83b8895 /src/lib/elementary/efl_ui_spin_button.c
parent7ddd286f7b3c454b9499f2a1357f8e4f7335710e (diff)
efl_ui_spin_button: make theme consistent
this reduces the amount of code needed in the widget itself, additionally, the theme now follows a scheme. Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Differential Revision: https://phab.enlightenment.org/D9230
Diffstat (limited to 'src/lib/elementary/efl_ui_spin_button.c')
-rw-r--r--src/lib/elementary/efl_ui_spin_button.c75
1 files changed, 9 insertions, 66 deletions
diff --git a/src/lib/elementary/efl_ui_spin_button.c b/src/lib/elementary/efl_ui_spin_button.c
index fa45e84..34de0b7 100644
--- a/src/lib/elementary/efl_ui_spin_button.c
+++ b/src/lib/elementary/efl_ui_spin_button.c
@@ -357,10 +357,6 @@ _toggle_entry(Evas_Object *obj)
357 // filter feature implemented. 357 // filter feature implemented.
358 // (Current efl_ui_text has missed filter feature.) 358 // (Current efl_ui_text has missed filter feature.)
359 sd->ent = elm_entry_add(obj); 359 sd->ent = elm_entry_add(obj);
360 Eina_Strbuf *buf = eina_strbuf_new();
361 eina_strbuf_append_printf(buf, "spinner/%s", elm_widget_style_get(obj));
362 elm_widget_style_set(sd->ent, eina_strbuf_string_get(buf));
363 eina_strbuf_free(buf);
364 evas_object_event_callback_add 360 evas_object_event_callback_add
365 (sd->ent, EVAS_CALLBACK_SHOW, _entry_show_cb, obj); 361 (sd->ent, EVAS_CALLBACK_SHOW, _entry_show_cb, obj);
366 elm_entry_single_line_set(sd->ent, EINA_TRUE); 362 elm_entry_single_line_set(sd->ent, EINA_TRUE);
@@ -371,6 +367,7 @@ _toggle_entry(Evas_Object *obj)
371 elm_entry_markup_filter_append(sd->ent, _min_max_validity_filter, obj); 367 elm_entry_markup_filter_append(sd->ent, _min_max_validity_filter, obj);
372 efl_event_callback_add(sd->ent, ELM_ENTRY_EVENT_ACTIVATED, 368 efl_event_callback_add(sd->ent, ELM_ENTRY_EVENT_ACTIVATED,
373 _entry_activated_cb, obj); 369 _entry_activated_cb, obj);
370 elm_widget_element_update(obj, sd->ent, "entry");
374 } 371 }
375 372
376 efl_event_callback_add(sd->ent, EFL_UI_FOCUS_OBJECT_EVENT_FOCUS_CHANGED, 373 efl_event_callback_add(sd->ent, EFL_UI_FOCUS_OBJECT_EVENT_FOCUS_CHANGED,
@@ -602,71 +599,21 @@ _access_spinner_register(Evas_Object *obj, Eina_Bool is_access)
602 } 599 }
603} 600}
604 601
605static const char * 602static void
606_theme_group_modify_pos_get(const char *cur_group, const char *search, size_t len) 603_sync_widget_theme_klass(Eo *obj, Efl_Ui_Spin_Button_Data *pd)
607{
608 const char *pos = NULL;
609 const char *temp_str = NULL;
610
611 temp_str = cur_group + len - strlen(search);
612 if (temp_str >= cur_group)
613 {
614 if (!strcmp(temp_str, search))
615 pos = temp_str;
616 }
617
618 return pos;
619}
620
621static char *
622_efl_ui_spin_button_theme_group_get(Evas_Object *obj, Efl_Ui_Spin_Button_Data *sd)
623{ 604{
624 const char *pos = NULL; 605 if (efl_ui_layout_orientation_is_horizontal(pd->dir, EINA_TRUE))
625 const char *cur_group = elm_widget_theme_element_get(obj); 606 elm_widget_theme_klass_set(obj, "spin_button/horizontal");
626 Eina_Strbuf *new_group = eina_strbuf_new();
627 size_t len = 0;
628
629 if (cur_group)
630 {
631 len = strlen(cur_group);
632 pos = _theme_group_modify_pos_get(cur_group, "horizontal", len);
633 if (!pos)
634 pos = _theme_group_modify_pos_get(cur_group, "vertical", len);
635
636 // TODO: change separator when it is decided.
637 // can skip when prev_group == cur_group
638 if (!pos)
639 {
640 eina_strbuf_append(new_group, cur_group);
641 eina_strbuf_append(new_group, "/");
642 }
643 else
644 {
645 eina_strbuf_append_length(new_group, cur_group, pos - cur_group);
646 }
647 }
648
649 if (efl_ui_layout_orientation_is_horizontal(sd->dir, EINA_TRUE))
650 eina_strbuf_append(new_group, "horizontal");
651 else 607 else
652 eina_strbuf_append(new_group, "vertical"); 608 elm_widget_theme_klass_set(obj, "spin_button/vertical");
653
654 return eina_strbuf_release(new_group);
655} 609}
656 610
657
658EOLIAN static Eina_Error 611EOLIAN static Eina_Error
659_efl_ui_spin_button_efl_ui_widget_theme_apply(Eo *obj, Efl_Ui_Spin_Button_Data *sd EINA_UNUSED) 612_efl_ui_spin_button_efl_ui_widget_theme_apply(Eo *obj, Efl_Ui_Spin_Button_Data *sd EINA_UNUSED)
660{ 613{
661 Eina_Error int_ret = EFL_UI_THEME_APPLY_ERROR_GENERIC; 614 Eina_Error int_ret = EFL_UI_THEME_APPLY_ERROR_GENERIC;
662 char *group;
663 615
664 group = _efl_ui_spin_button_theme_group_get(obj, sd); 616 _sync_widget_theme_klass(obj, sd);
665 if (group)
666 {
667 elm_widget_theme_element_set(obj, group);
668 free(group);
669 }
670 617
671 int_ret = efl_ui_widget_theme_apply(efl_super(obj, MY_CLASS)); 618 int_ret = efl_ui_widget_theme_apply(efl_super(obj, MY_CLASS));
672 if (int_ret == EFL_UI_THEME_APPLY_ERROR_GENERIC) return int_ret; 619 if (int_ret == EFL_UI_THEME_APPLY_ERROR_GENERIC) return int_ret;
@@ -694,23 +641,19 @@ _efl_ui_spin_button_efl_ui_widget_theme_apply(Eo *obj, Efl_Ui_Spin_Button_Data *
694EOLIAN static Eo * 641EOLIAN static Eo *
695_efl_ui_spin_button_efl_object_constructor(Eo *obj, Efl_Ui_Spin_Button_Data *sd) 642_efl_ui_spin_button_efl_object_constructor(Eo *obj, Efl_Ui_Spin_Button_Data *sd)
696{ 643{
697 char *group;
698 644
699 obj = efl_constructor(efl_super(obj, MY_CLASS)); 645 obj = efl_constructor(efl_super(obj, MY_CLASS));
700 elm_widget_theme_klass_set(obj, "spin_button"); 646 _sync_widget_theme_klass(obj, sd);
701 647
702 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, NULL); 648 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, NULL);
703 649
704 group = _efl_ui_spin_button_theme_group_get(obj, sd);
705 if (elm_widget_theme_object_set(obj, wd->resize_obj, 650 if (elm_widget_theme_object_set(obj, wd->resize_obj,
706 elm_widget_theme_klass_get(obj), 651 elm_widget_theme_klass_get(obj),
707 group, 652 elm_widget_theme_element_get(obj),
708 elm_widget_theme_style_get(obj)) == EFL_UI_THEME_APPLY_ERROR_GENERIC) 653 elm_widget_theme_style_get(obj)) == EFL_UI_THEME_APPLY_ERROR_GENERIC)
709 CRI("Failed to set layout!"); 654 CRI("Failed to set layout!");
710 655
711 656
712 free(group);
713
714 sd->inc_button = efl_add(EFL_UI_BUTTON_CLASS, obj, 657 sd->inc_button = efl_add(EFL_UI_BUTTON_CLASS, obj,
715 efl_ui_autorepeat_enabled_set(efl_added, EINA_TRUE), 658 efl_ui_autorepeat_enabled_set(efl_added, EINA_TRUE),
716 efl_ui_autorepeat_initial_timeout_set(efl_added, _elm_config->longpress_timeout), 659 efl_ui_autorepeat_initial_timeout_set(efl_added, _elm_config->longpress_timeout),