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
This commit is contained in:
Marcel Hollerbach 2019-07-05 19:09:43 +02:00
parent 7ddd286f7b
commit d8f32042c4
2 changed files with 16 additions and 73 deletions

View File

@ -202,7 +202,7 @@ group { "efl/spin_button/vertical";
}
}
group { "efl/spin_button/inc_button";
group { "efl/spin_button/horizontal/inc_button";
images.image: "sym_right_light_normal.png" COMP;
images.image: "sym_right_glow_normal.png" COMP;
images.image: "sym_right_dark_normal.png" COMP;
@ -352,13 +352,13 @@ group { "efl/spin_button/inc_button";
}
}
group { "efl/spin_button/entry";
group { "efl/spin_button/horizontal/entry";
alias: "efl/spin_button/vertical/entry";
inherit: "efl/text";
}
group { "efl/spin_button/dec_button";
inherit: "efl/spin_button/inc_button";
group { "efl/spin_button/horizontal/dec_button";
inherit: "efl/spin_button/horizontal/inc_button";
images.image: "sym_left_light_normal.png" COMP;
images.image: "sym_left_glow_normal.png" COMP;
images.image: "sym_left_dark_normal.png" COMP;
@ -382,7 +382,7 @@ group { "efl/spin_button/dec_button";
}
}
group { "efl/spin_button/text_button";
group { "efl/spin_button/horizontal/text_button";
alias: "efl/spin_button/vertical/text_button";
parts {
part { name: "bg";
@ -460,7 +460,7 @@ group { "efl/spin_button/text_button";
}
group { "efl/spin_button/vertical/inc_button";
inherit: "efl/spin_button/inc_button";
inherit: "efl/spin_button/horizontal/inc_button";
images.image: "sym_up_light_normal.png" COMP;
images.image: "sym_up_glow_normal.png" COMP;
images.image: "sym_up_dark_normal.png" COMP;
@ -485,7 +485,7 @@ group { "efl/spin_button/vertical/inc_button";
}
group { "efl/spin_button/vertical/dec_button";
inherit: "efl/spin_button/dec_button";
inherit: "efl/spin_button/horizontal/dec_button";
images.image: "sym_down_light_normal.png" COMP;
images.image: "sym_down_glow_normal.png" COMP;
images.image: "sym_down_dark_normal.png" COMP;

View File

@ -357,10 +357,6 @@ _toggle_entry(Evas_Object *obj)
// filter feature implemented.
// (Current efl_ui_text has missed filter feature.)
sd->ent = elm_entry_add(obj);
Eina_Strbuf *buf = eina_strbuf_new();
eina_strbuf_append_printf(buf, "spinner/%s", elm_widget_style_get(obj));
elm_widget_style_set(sd->ent, eina_strbuf_string_get(buf));
eina_strbuf_free(buf);
evas_object_event_callback_add
(sd->ent, EVAS_CALLBACK_SHOW, _entry_show_cb, obj);
elm_entry_single_line_set(sd->ent, EINA_TRUE);
@ -371,6 +367,7 @@ _toggle_entry(Evas_Object *obj)
elm_entry_markup_filter_append(sd->ent, _min_max_validity_filter, obj);
efl_event_callback_add(sd->ent, ELM_ENTRY_EVENT_ACTIVATED,
_entry_activated_cb, obj);
elm_widget_element_update(obj, sd->ent, "entry");
}
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)
}
}
static const char *
_theme_group_modify_pos_get(const char *cur_group, const char *search, size_t len)
static void
_sync_widget_theme_klass(Eo *obj, Efl_Ui_Spin_Button_Data *pd)
{
const char *pos = NULL;
const char *temp_str = NULL;
temp_str = cur_group + len - strlen(search);
if (temp_str >= cur_group)
{
if (!strcmp(temp_str, search))
pos = temp_str;
}
return pos;
}
static char *
_efl_ui_spin_button_theme_group_get(Evas_Object *obj, Efl_Ui_Spin_Button_Data *sd)
{
const char *pos = NULL;
const char *cur_group = elm_widget_theme_element_get(obj);
Eina_Strbuf *new_group = eina_strbuf_new();
size_t len = 0;
if (cur_group)
{
len = strlen(cur_group);
pos = _theme_group_modify_pos_get(cur_group, "horizontal", len);
if (!pos)
pos = _theme_group_modify_pos_get(cur_group, "vertical", len);
// TODO: change separator when it is decided.
// can skip when prev_group == cur_group
if (!pos)
{
eina_strbuf_append(new_group, cur_group);
eina_strbuf_append(new_group, "/");
}
else
{
eina_strbuf_append_length(new_group, cur_group, pos - cur_group);
}
}
if (efl_ui_layout_orientation_is_horizontal(sd->dir, EINA_TRUE))
eina_strbuf_append(new_group, "horizontal");
if (efl_ui_layout_orientation_is_horizontal(pd->dir, EINA_TRUE))
elm_widget_theme_klass_set(obj, "spin_button/horizontal");
else
eina_strbuf_append(new_group, "vertical");
return eina_strbuf_release(new_group);
elm_widget_theme_klass_set(obj, "spin_button/vertical");
}
EOLIAN static Eina_Error
_efl_ui_spin_button_efl_ui_widget_theme_apply(Eo *obj, Efl_Ui_Spin_Button_Data *sd EINA_UNUSED)
{
Eina_Error int_ret = EFL_UI_THEME_APPLY_ERROR_GENERIC;
char *group;
group = _efl_ui_spin_button_theme_group_get(obj, sd);
if (group)
{
elm_widget_theme_element_set(obj, group);
free(group);
}
_sync_widget_theme_klass(obj, sd);
int_ret = efl_ui_widget_theme_apply(efl_super(obj, MY_CLASS));
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 *
EOLIAN static Eo *
_efl_ui_spin_button_efl_object_constructor(Eo *obj, Efl_Ui_Spin_Button_Data *sd)
{
char *group;
obj = efl_constructor(efl_super(obj, MY_CLASS));
elm_widget_theme_klass_set(obj, "spin_button");
_sync_widget_theme_klass(obj, sd);
ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, NULL);
group = _efl_ui_spin_button_theme_group_get(obj, sd);
if (elm_widget_theme_object_set(obj, wd->resize_obj,
elm_widget_theme_klass_get(obj),
group,
elm_widget_theme_element_get(obj),
elm_widget_theme_style_get(obj)) == EFL_UI_THEME_APPLY_ERROR_GENERIC)
CRI("Failed to set layout!");
free(group);
sd->inc_button = efl_add(EFL_UI_BUTTON_CLASS, obj,
efl_ui_autorepeat_enabled_set(efl_added, EINA_TRUE),
efl_ui_autorepeat_initial_timeout_set(efl_added, _elm_config->longpress_timeout),