edje: update a style when a style is added as class's member
Summary: If there is no member styles when a text_class is updated, newly added styles can't be updated. So, newly added styles as member of text_class should be updated. @fix Test Plan: Test case is included. 1. Run "elementary_test -to "font overlay"" 2. Press Next button. Check the font size. 3. Press Prev button. 4. Put font_size as 50 5. Click Apply button. 6. Press Next button. Check the font size is not changed. Reviewers: cedric, tasn, herdsman, raster Subscribers: jpeg, z-wony, Blackmole Differential Revision: https://phab.enlightenment.org/D4125
This commit is contained in:
parent
5b791420ea
commit
8e93b88175
|
@ -833,4 +833,31 @@ group { name: "page_layout";
|
|||
}
|
||||
}
|
||||
}
|
||||
group { name: "font_overlay_layout";
|
||||
styles {
|
||||
style { name: "test_class_style";
|
||||
base: "font=Sans font_size=20 color=#fff text_class=font_overlay_test wrap=mixed";
|
||||
}
|
||||
}
|
||||
parts {
|
||||
part { name: "bg";
|
||||
type: RECT;
|
||||
scale: 1;
|
||||
description { state: "default" 0.0;
|
||||
min: 400 300;
|
||||
color: 0 0 0 0;
|
||||
}
|
||||
}
|
||||
part { name: "elm.text";
|
||||
type: TEXTBLOCK;
|
||||
scale: 1;
|
||||
description { state: "default" 0.0;
|
||||
fixed: 1 1;
|
||||
text {
|
||||
style: "test_class_style";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -266,6 +266,7 @@ void test_external_video(void *data, Evas_Object *obj, void *event_info);
|
|||
void test_external_icon(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_external_combobox(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_config(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_config_font_overlay(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_video(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_eio(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_web(void *data, Evas_Object *obj, void *event_info);
|
||||
|
@ -916,6 +917,7 @@ add_tests:
|
|||
ADD_TEST(NULL, "Miscellaneous", "Accessibility", test_access);
|
||||
ADD_TEST(NULL, "Miscellaneous", "Accessibility2", test_access2);
|
||||
ADD_TEST(NULL, "Miscellaneous", "Accessibility3", test_access3);
|
||||
ADD_TEST(NULL, "Miscellaneous", "Font overlay", test_config_font_overlay);
|
||||
|
||||
//------------------------------//
|
||||
ADD_TEST(NULL, "Application client/server", "Task switcher", test_task_switcher);
|
||||
|
|
|
@ -532,3 +532,122 @@ test_config(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
|
|||
evas_object_resize(win, 400, 500);
|
||||
evas_object_show(win);
|
||||
}
|
||||
|
||||
static void
|
||||
_font_overlay_page_next(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||
{
|
||||
Evas_Object *layout;
|
||||
Evas_Object *nf = (Evas_Object *)data;
|
||||
char buf[255];
|
||||
|
||||
layout = elm_layout_add(nf);
|
||||
snprintf(buf, sizeof(buf), "%s/objects/test.edj", elm_app_data_dir_get());
|
||||
elm_layout_file_set(layout, buf, "font_overlay_layout");
|
||||
elm_layout_text_set(layout, "elm.text", "TEXTBLOCK part of test_class");
|
||||
evas_object_show(layout);
|
||||
|
||||
elm_naviframe_item_push(nf, "Font Overlay", NULL, NULL, layout, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
_apply_font_overlay_btn_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||
{
|
||||
Evas_Object *nf = (Evas_Object *)data;
|
||||
Evas_Object *entry;
|
||||
const char *font;
|
||||
const char *font_size_temp;
|
||||
int font_size;
|
||||
|
||||
entry = (Evas_Object *)evas_object_data_get(nf, "font_entry");
|
||||
font = elm_entry_entry_get(entry);
|
||||
entry = (Evas_Object *)evas_object_data_get(nf, "font_size_entry");
|
||||
font_size_temp = elm_entry_entry_get(entry);
|
||||
font_size = atoi(font_size_temp);
|
||||
|
||||
printf("Font overlay set: Font [%s], FontSize [%d]\n", font, font_size);
|
||||
elm_config_font_overlay_set("font_overlay_test", font, font_size);
|
||||
elm_config_font_overlay_apply();
|
||||
}
|
||||
|
||||
void
|
||||
test_config_font_overlay(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||
{
|
||||
Evas_Object *win, *nf, *box, *horizon_box, *label, *btn, *entry;
|
||||
Elm_Object_Item *it;
|
||||
|
||||
win = elm_win_util_standard_add("naviframe", "Naviframe");
|
||||
elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
|
||||
elm_win_autodel_set(win, EINA_TRUE);
|
||||
|
||||
nf = elm_naviframe_add(win);
|
||||
evas_object_size_hint_weight_set(nf, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
elm_win_resize_object_add(win, nf);
|
||||
evas_object_show(nf);
|
||||
|
||||
box = elm_box_add(nf);
|
||||
evas_object_show(box);
|
||||
|
||||
horizon_box = elm_box_add(box);
|
||||
elm_box_horizontal_set(horizon_box, EINA_TRUE);
|
||||
evas_object_size_hint_align_set(horizon_box, EVAS_HINT_FILL, -1);
|
||||
evas_object_size_hint_weight_set(horizon_box, EVAS_HINT_EXPAND, -1);
|
||||
elm_box_pack_end(box, horizon_box);
|
||||
evas_object_show(horizon_box);
|
||||
|
||||
label = elm_label_add(horizon_box);
|
||||
elm_object_text_set(label, "Font:");
|
||||
elm_box_pack_end(horizon_box, label);
|
||||
evas_object_show(label);
|
||||
|
||||
entry = elm_entry_add(horizon_box);
|
||||
elm_entry_single_line_set(entry, EINA_TRUE);
|
||||
elm_entry_scrollable_set(entry, EINA_TRUE);
|
||||
evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, -1);
|
||||
evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, -1);
|
||||
elm_object_part_text_set(entry, "elm.guide", "Input Font");
|
||||
elm_box_pack_end(horizon_box, entry);
|
||||
evas_object_show(entry);
|
||||
evas_object_data_set(nf, "font_entry", entry);
|
||||
|
||||
horizon_box = elm_box_add(box);
|
||||
elm_box_horizontal_set(horizon_box, EINA_TRUE);
|
||||
evas_object_size_hint_align_set(horizon_box, EVAS_HINT_FILL, -1);
|
||||
evas_object_size_hint_weight_set(horizon_box, EVAS_HINT_EXPAND, -1);
|
||||
elm_box_pack_end(box, horizon_box);
|
||||
evas_object_show(horizon_box);
|
||||
|
||||
label = elm_label_add(horizon_box);
|
||||
elm_object_text_set(label, "Size:");
|
||||
elm_box_pack_end(horizon_box, label);
|
||||
evas_object_show(label);
|
||||
|
||||
entry = elm_entry_add(horizon_box);
|
||||
elm_entry_single_line_set(entry, EINA_TRUE);
|
||||
elm_entry_scrollable_set(entry, EINA_TRUE);
|
||||
evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, -1);
|
||||
evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, -1);
|
||||
elm_object_part_text_set(entry, "elm.guide", "Input Font Size");
|
||||
elm_box_pack_end(horizon_box, entry);
|
||||
evas_object_show(entry);
|
||||
evas_object_data_set(nf, "font_size_entry", entry);
|
||||
|
||||
btn = elm_button_add(box);
|
||||
elm_object_text_set(btn, "Apply Font Overlay");
|
||||
evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, -1);
|
||||
evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, -1);
|
||||
evas_object_smart_callback_add(btn, "clicked", _apply_font_overlay_btn_clicked_cb, nf);
|
||||
elm_box_pack_end(box, btn);
|
||||
evas_object_show(btn);
|
||||
|
||||
btn = elm_button_add(nf);
|
||||
evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_smart_callback_add(btn, "clicked", _font_overlay_page_next, nf);
|
||||
elm_object_text_set(btn, "Next");
|
||||
evas_object_show(btn);
|
||||
|
||||
it = elm_naviframe_item_push(nf, "Font Overlay", NULL, btn, box, NULL);
|
||||
evas_object_data_set(nf, "page1", it);
|
||||
|
||||
evas_object_resize(win, 400, 400);
|
||||
evas_object_show(win);
|
||||
}
|
||||
|
|
|
@ -149,6 +149,121 @@ _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag **tag_ret)
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* Update the given evas_style
|
||||
*
|
||||
* @param ed The edje containing the given style which need to be updated
|
||||
* @param style The style which need to be updated
|
||||
* @param force Update the given style forcely or not
|
||||
*/
|
||||
void
|
||||
_edje_textblock_style_update(Edje *ed, Edje_Style *stl, Eina_Bool force)
|
||||
{
|
||||
Eina_List *l;
|
||||
Eina_Strbuf *txt = NULL;
|
||||
Edje_Style_Tag *tag;
|
||||
Edje_Text_Class *tc;
|
||||
int found = 0;
|
||||
char *fontset = NULL, *fontsource = NULL;
|
||||
|
||||
if (!ed->file) return;
|
||||
|
||||
/* Make sure the style is already defined */
|
||||
if (!stl->style) return;
|
||||
|
||||
/* No need to compute it again and again and again */
|
||||
if (!force && stl->cache) return;
|
||||
|
||||
/* Make sure the style contains a text_class */
|
||||
EINA_LIST_FOREACH(stl->tags, l, tag)
|
||||
{
|
||||
if (tag->text_class)
|
||||
{
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* No text classes , goto next style */
|
||||
if (!found) return;
|
||||
if (!txt)
|
||||
txt = eina_strbuf_new();
|
||||
|
||||
if (_edje_fontset_append)
|
||||
fontset = eina_str_escape(_edje_fontset_append);
|
||||
fontsource = eina_str_escape(ed->file->path);
|
||||
|
||||
/* Build the style from each tag */
|
||||
EINA_LIST_FOREACH(stl->tags, l, tag)
|
||||
{
|
||||
if (!tag->key) continue;
|
||||
|
||||
/* Add Tag Key */
|
||||
eina_strbuf_append(txt, tag->key);
|
||||
eina_strbuf_append(txt, "='");
|
||||
|
||||
/* Configure fonts from text class if it exists */
|
||||
tc = _edje_text_class_find(ed, tag->text_class);
|
||||
|
||||
/* Add and Handle tag parsed data */
|
||||
eina_strbuf_append(txt, tag->value);
|
||||
|
||||
if (!strcmp(tag->key, "DEFAULT"))
|
||||
{
|
||||
if (fontset)
|
||||
{
|
||||
eina_strbuf_append(txt, " ");
|
||||
eina_strbuf_append(txt, "font_fallbacks=");
|
||||
eina_strbuf_append(txt, fontset);
|
||||
}
|
||||
eina_strbuf_append(txt, " ");
|
||||
eina_strbuf_append(txt, "font_source=");
|
||||
eina_strbuf_append(txt, fontsource);
|
||||
}
|
||||
if (tag->font_size != 0)
|
||||
{
|
||||
char font_size[32];
|
||||
|
||||
if (tc && tc->size)
|
||||
snprintf(font_size, sizeof(font_size), "%f",
|
||||
(double)_edje_text_size_calc(tag->font_size, tc));
|
||||
else
|
||||
snprintf(font_size, sizeof(font_size), "%f",
|
||||
tag->font_size);
|
||||
|
||||
eina_strbuf_append(txt, " ");
|
||||
eina_strbuf_append(txt, "font_size=");
|
||||
eina_strbuf_append(txt, font_size);
|
||||
}
|
||||
/* Add font name last to save evas from multiple loads */
|
||||
if (tag->font)
|
||||
{
|
||||
const char *f;
|
||||
char *sfont = NULL;
|
||||
|
||||
eina_strbuf_append(txt, " ");
|
||||
eina_strbuf_append(txt, "font=");
|
||||
|
||||
if (tc) f = _edje_text_font_get(tag->font, tc->font, &sfont);
|
||||
else f = tag->font;
|
||||
|
||||
eina_strbuf_append_escaped(txt, f);
|
||||
|
||||
if (sfont) free(sfont);
|
||||
}
|
||||
|
||||
eina_strbuf_append(txt, "'");
|
||||
}
|
||||
if (fontset) free(fontset);
|
||||
if (fontsource) free(fontsource);
|
||||
|
||||
/* Configure the style */
|
||||
stl->cache = EINA_TRUE;
|
||||
evas_textblock_style_set(stl->style, eina_strbuf_string_get(txt));
|
||||
if (txt)
|
||||
eina_strbuf_free(txt);
|
||||
}
|
||||
|
||||
/* Update all evas_styles which are in an edje
|
||||
*
|
||||
* @param ed The edje containing styles which need to be updated
|
||||
|
@ -156,115 +271,13 @@ _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag **tag_ret)
|
|||
void
|
||||
_edje_textblock_style_all_update(Edje *ed)
|
||||
{
|
||||
Eina_List *l, *ll;
|
||||
Eina_List *l;
|
||||
Edje_Style *stl;
|
||||
Eina_Strbuf *txt = NULL;
|
||||
|
||||
if (!ed->file) return;
|
||||
|
||||
EINA_LIST_FOREACH(ed->file->styles, l, stl)
|
||||
{
|
||||
Edje_Style_Tag *tag;
|
||||
Edje_Text_Class *tc;
|
||||
int found = 0;
|
||||
char *fontset = NULL, *fontsource = NULL;
|
||||
|
||||
/* Make sure the style is already defined */
|
||||
if (!stl->style) break;
|
||||
|
||||
/* No need to compute it again and again and again */
|
||||
if (stl->cache) continue;
|
||||
|
||||
/* Make sure the style contains a text_class */
|
||||
EINA_LIST_FOREACH(stl->tags, ll, tag)
|
||||
{
|
||||
if (tag->text_class)
|
||||
{
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* No text classes , goto next style */
|
||||
if (!found) continue;
|
||||
if (!txt)
|
||||
txt = eina_strbuf_new();
|
||||
|
||||
if (_edje_fontset_append)
|
||||
fontset = eina_str_escape(_edje_fontset_append);
|
||||
fontsource = eina_str_escape(ed->file->path);
|
||||
|
||||
/* Build the style from each tag */
|
||||
EINA_LIST_FOREACH(stl->tags, ll, tag)
|
||||
{
|
||||
if (!tag->key) continue;
|
||||
|
||||
/* Add Tag Key */
|
||||
eina_strbuf_append(txt, tag->key);
|
||||
eina_strbuf_append(txt, "='");
|
||||
|
||||
/* Configure fonts from text class if it exists */
|
||||
tc = _edje_text_class_find(ed, tag->text_class);
|
||||
|
||||
/* Add and Handle tag parsed data */
|
||||
eina_strbuf_append(txt, tag->value);
|
||||
|
||||
if (!strcmp(tag->key, "DEFAULT"))
|
||||
{
|
||||
if (fontset)
|
||||
{
|
||||
eina_strbuf_append(txt, " ");
|
||||
eina_strbuf_append(txt, "font_fallbacks=");
|
||||
eina_strbuf_append(txt, fontset);
|
||||
}
|
||||
eina_strbuf_append(txt, " ");
|
||||
eina_strbuf_append(txt, "font_source=");
|
||||
eina_strbuf_append(txt, fontsource);
|
||||
}
|
||||
if (tag->font_size != 0)
|
||||
{
|
||||
char font_size[32];
|
||||
|
||||
if (tc && tc->size)
|
||||
snprintf(font_size, sizeof(font_size), "%f",
|
||||
(double)_edje_text_size_calc(tag->font_size, tc));
|
||||
else
|
||||
snprintf(font_size, sizeof(font_size), "%f",
|
||||
tag->font_size);
|
||||
|
||||
eina_strbuf_append(txt, " ");
|
||||
eina_strbuf_append(txt, "font_size=");
|
||||
eina_strbuf_append(txt, font_size);
|
||||
}
|
||||
/* Add font name last to save evas from multiple loads */
|
||||
if (tag->font)
|
||||
{
|
||||
const char *f;
|
||||
char *sfont = NULL;
|
||||
|
||||
eina_strbuf_append(txt, " ");
|
||||
eina_strbuf_append(txt, "font=");
|
||||
|
||||
if (tc) f = _edje_text_font_get(tag->font, tc->font, &sfont);
|
||||
else f = tag->font;
|
||||
|
||||
eina_strbuf_append_escaped(txt, f);
|
||||
|
||||
if (sfont) free(sfont);
|
||||
}
|
||||
|
||||
eina_strbuf_append(txt, "'");
|
||||
}
|
||||
if (fontset) free(fontset);
|
||||
if (fontsource) free(fontsource);
|
||||
|
||||
/* Configure the style */
|
||||
stl->cache = EINA_TRUE;
|
||||
evas_textblock_style_set(stl->style, eina_strbuf_string_get(txt));
|
||||
eina_strbuf_reset(txt);
|
||||
}
|
||||
if (txt)
|
||||
eina_strbuf_free(txt);
|
||||
_edje_textblock_style_update(ed, stl, EINA_FALSE);
|
||||
}
|
||||
|
||||
static inline Edje_Style *
|
||||
|
@ -296,7 +309,13 @@ _edje_textblock_style_member_add(Edje *ed, Edje_Style *stl)
|
|||
EINA_LIST_FOREACH(stl->tags, l, tag)
|
||||
{
|
||||
if (tag->text_class)
|
||||
_edje_text_class_member_add(ed, tag->text_class);
|
||||
{
|
||||
_edje_text_class_member_add(ed, tag->text_class);
|
||||
|
||||
/* Newly added text_class member should be updated
|
||||
according to the latest text_class's status. */
|
||||
_edje_textblock_style_update(ed, stl, EINA_TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue