improve and simplify font preview.

Allow user-defined text to be used, some letters are a pain like zero
x "o", "l" x "1"...

I've simplified the preview to use a single edje object and text
class, but the item is not growing as expected on updates... Edje bug?



SVN revision: 72320
This commit is contained in:
Gustavo Sverzut Barbieri 2012-06-17 22:30:07 +00:00
parent b220b1e468
commit d2321e4f65
3 changed files with 146 additions and 118 deletions

View File

@ -86,21 +86,28 @@ collections {
description { state: "default" 0.0; description { state: "default" 0.0;
fixed: 1 1; fixed: 1 1;
min: 80 80; min: 80 80;
align: 0.0 0.5; align: 1.0 0.5;
visible: 0;
rel1 { rel1 {
relative: 1.0 0.02; relative: 1.0 0.02;
offset: 8 8; offset: 8 8;
} }
rel2 { rel2 {
relative: 1.0 0.98; relative: 2.0 0.98;
offset: 8 -9; offset: -9 -9;
} }
} }
description { state: "visible" 0.0; description { state: "visible" 0.0;
inherit: "default" 0.0; inherit: "default" 0.0;
align: 1.0 0.5; visible: 1;
rel1.offset: -9 8; rel1 {
rel2.offset: -9 -9; relative: 0.0 0.02;
offset: 8 8;
}
rel2 {
relative: 1.0 0.98;
offset: -9 -9;
}
} }
} }
programs { programs {
@ -222,34 +229,48 @@ collections {
part { name: "shadow"; part { name: "shadow";
mouse_events: 0; mouse_events: 0;
description { state: "default" 0.0; description { state: "default" 0.0;
rel1.offset: -2 -1; rel1 {
rel1.to: "base"; offset: -2 -1;
rel2.offset: 1 2; to: "base";
rel2.to: "base"; }
image.normal: "fn_shadow.png"; rel2 {
image.border: 5 5 5 5; offset: 1 2;
to: "base";
}
image {
normal: "fn_shadow.png";
border: 5 5 5 5;
}
fill.smooth: 0; fill.smooth: 0;
} }
} }
part { name: "base"; type: RECT; part { name: "base"; type: RECT;
mouse_events: 1; mouse_events: 1;
description { state: "default" 0.0; description { state: "default" 0.0;
rel1.offset: 2 2;
rel2.offset: -3 -3;
color: 255 255 255 255; color: 255 255 255 255;
rel1 {
offset: -2 -2;
to: "terminology.text.preview";
}
rel2 {
offset: 3 3;
to: "terminology.text.preview";
}
} }
} }
part { name: "clip"; type: RECT; part { name: "terminology.text.preview"; type: TEXT;
mouse_events: 1;
description { state: "default" 0.0; description { state: "default" 0.0;
color: 255 255 255 255; color: 0 0 0 255;
} rel1.offset: 5 5;
} rel2.offset: -6 -6;
part { name: "terminology.content"; type: SWALLOW; text {
clip_to: "clip"; text: "test";
description { state: "default" 0.0; text_class: "terminology.preview";
rel1.offset: 4 4; font: "Monospace";
rel2.offset: -5 -5; size: 14;
min: 1 1;
align: 0.0 0.5;
}
} }
} }
} }

View File

@ -46,21 +46,28 @@ collections {
description { state: "default" 0.0; description { state: "default" 0.0;
fixed: 1 1; fixed: 1 1;
min: 80 80; min: 80 80;
align: 0.0 0.5; align: 1.0 0.5;
visible: 0;
rel1 { rel1 {
relative: 1.0 0.02; relative: 1.0 0.02;
offset: 8 8; offset: 8 8;
} }
rel2 { rel2 {
relative: 1.0 0.98; relative: 2.0 0.98;
offset: 8 -9; offset: -9 -9;
} }
} }
description { state: "visible" 0.0; description { state: "visible" 0.0;
inherit: "default" 0.0; inherit: "default" 0.0;
align: 1.0 0.5; visible: 1;
rel1.offset: -9 8; rel1 {
rel2.offset: -9 -9; relative: 0.0 0.02;
offset: 8 8;
}
rel2 {
relative: 1.0 0.98;
offset: -9 -9;
}
} }
} }
programs { programs {
@ -182,34 +189,48 @@ collections {
part { name: "shadow"; part { name: "shadow";
mouse_events: 0; mouse_events: 0;
description { state: "default" 0.0; description { state: "default" 0.0;
rel1.offset: -2 -1; rel1 {
rel1.to: "base"; offset: -2 -1;
rel2.offset: 1 2; to: "base";
rel2.to: "base"; }
image.normal: "fn_shadow.png"; rel2 {
image.border: 5 5 5 5; offset: 1 2;
to: "base";
}
image {
normal: "fn_shadow.png";
border: 5 5 5 5;
}
fill.smooth: 0; fill.smooth: 0;
} }
} }
part { name: "base"; type: RECT; part { name: "base"; type: RECT;
mouse_events: 1; mouse_events: 1;
description { state: "default" 0.0; description { state: "default" 0.0;
rel1.offset: 2 2;
rel2.offset: -3 -3;
color: 255 255 255 255; color: 255 255 255 255;
rel1 {
offset: -2 -2;
to: "terminology.text.preview";
}
rel2 {
offset: 3 3;
to: "terminology.text.preview";
}
} }
} }
part { name: "clip"; type: RECT; part { name: "terminology.text.preview"; type: TEXT;
mouse_events: 1;
description { state: "default" 0.0; description { state: "default" 0.0;
color: 255 255 255 255; color: 0 0 0 255;
} rel1.offset: 5 5;
} rel2.offset: -6 -6;
part { name: "terminology.content"; type: SWALLOW; text {
clip_to: "clip"; text: "test";
description { state: "default" 0.0; text_class: "terminology.preview";
rel1.offset: 4 4; font: "Monospace";
rel2.offset: -5 -5; size: 14;
min: 1 1;
align: 0.0 0.5;
}
} }
} }
} }

View File

@ -12,14 +12,25 @@ typedef struct _Font Font;
struct _Font struct _Font
{ {
Elm_Object_Item *item;
const char *name; const char *name;
Evas_Object *term; Evas_Object *term;
Evas_Object *preview; /* TODO: move preview and term to a parent struct */
Eina_Bool bitmap : 1; Eina_Bool bitmap : 1;
}; };
static Eina_List *fonts = NULL; static Eina_List *fonts = NULL;
static Eina_Hash *fonthash = NULL; static Eina_Hash *fonthash = NULL;
static void
_update_preview(void)
{
const Eina_List *l;
const Font *f;
EINA_LIST_FOREACH(fonts, l, f)
elm_genlist_item_update(f->item);
}
static void static void
_update_sizing(Evas_Object *term) _update_sizing(Evas_Object *term)
{ {
@ -63,6 +74,7 @@ _cb_op_fontsize_sel(void *data, Evas_Object *obj, void *event __UNUSED__)
_update_sizing(term); _update_sizing(term);
elm_genlist_realized_items_update(op_fontlist); elm_genlist_realized_items_update(op_fontlist);
config_save(config, NULL); config_save(config, NULL);
_update_preview();
} }
static int static int
@ -71,81 +83,36 @@ _cb_op_font_sort(const void *d1, const void *d2)
return strcasecmp(d1, d2); return strcasecmp(d1, d2);
} }
static void
_cb_op_font_preview_del(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
{
Evas_Object *o;
o = edje_object_part_swallow_get(obj, "terminology.content");
if (o) evas_object_del(o);
}
static void
_cb_op_font_preview_eval(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
{
Font *f = data;
Evas_Object *o;
Evas_Coord ox, oy, ow, oh, vx, vy, vw, vh;
char buf[4096];
Config *config = termio_config_get(f->term);
if (!evas_object_visible_get(obj)) return;
if (edje_object_part_swallow_get(obj, "terminology.content")) return;
evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
if ((ow < 2) || (oh < 2)) return;
evas_output_viewport_get(evas_object_evas_get(obj), &vx, &vy, &vw, &vh);
if (ELM_RECTS_INTERSECT(ox, oy, ow, oh, vx, vy, vw, vh))
{
o = evas_object_text_add(evas_object_evas_get(obj));
evas_object_color_set(o, 0, 0, 0, 255);
if (evas_object_data_get(obj, "_f"))
evas_object_text_text_set(o, "Abc");
else
evas_object_text_text_set(o, "123");
if (f->bitmap)
{
snprintf(buf, sizeof(buf), "%s/fonts/%s",
elm_app_data_dir_get(), f->name);
evas_object_text_font_set(o, buf, config->font.size);
}
else
evas_object_text_font_set(o, f->name, config->font.size);
evas_object_geometry_get(o, NULL, NULL, &ow, &oh);
evas_object_size_hint_min_set(o, ow, oh);
edje_object_part_swallow(obj, "terminology.content", o);
}
}
static Evas_Object * static Evas_Object *
_cb_op_font_content_get(void *data, Evas_Object *obj, const char *part) _cb_op_font_content_get(void *data, Evas_Object *obj, const char *part)
{ {
Font *f = data; Font *f = data;
Config *config = termio_config_get(f->term); Config *config = termio_config_get(f->term);
Evas_Object *o;
const char *font, *s = elm_object_text_get(f->preview);
char buf[PATH_MAX];
if ((!strcmp(part, "elm.swallow.icon")) || if (strcmp(part, "elm.swallow.end") != 0) return NULL;
(!strcmp(part, "elm.swallow.end")))
o = edje_object_add(evas_object_evas_get(obj));
edje_object_file_set(o, config_theme_path_get(config),
"terminology/fontpreview");
if (!f->bitmap)
font = f->name;
else
{ {
Evas_Object *o; snprintf(buf, sizeof(buf), "%s/fonts/%s",
elm_app_data_dir_get(), f->name);
o = edje_object_add(evas_object_evas_get(obj)); font = buf;
edje_object_file_set(o, config_theme_path_get(config),
"terminology/fontpreview");
evas_object_size_hint_min_set(o,
40 * elm_config_scale_get(),
40 * elm_config_scale_get());
evas_object_event_callback_add(o, EVAS_CALLBACK_MOVE,
_cb_op_font_preview_eval, f);
evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE,
_cb_op_font_preview_eval, f);
evas_object_event_callback_add(o, EVAS_CALLBACK_SHOW,
_cb_op_font_preview_eval, f);
evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
_cb_op_font_preview_del, f);
if (!strcmp(part, "elm.swallow.icon"))
evas_object_data_set(o, "_f", o);
return o;
} }
return NULL;
edje_object_text_class_set(o, "terminology.preview",
font, config->font.size);
edje_object_part_text_set(o, "terminology.text.preview", s);
edje_object_update_hints_set(o, EINA_TRUE);
return o;
} }
static char * static char *
@ -167,6 +134,12 @@ _cb_op_font_group_text_get(void *data, Evas_Object *obj __UNUSED__, const char *
return strdup(data); return strdup(data);
} }
static void
_cb_op_text_changed(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
{
_update_preview();
}
void void
options_font_clear(void) options_font_clear(void)
{ {
@ -187,7 +160,7 @@ options_font_clear(void)
void void
options_font(Evas_Object *opbox, Evas_Object *term) options_font(Evas_Object *opbox, Evas_Object *term)
{ {
Evas_Object *o, *bx; Evas_Object *o, *bx, *preview;
char buf[4096], *file, *fname, *s; char buf[4096], *file, *fname, *s;
Eina_List *files, *fontlist, *l; Eina_List *files, *fontlist, *l;
Font *f; Font *f;
@ -226,6 +199,17 @@ options_font(Evas_Object *opbox, Evas_Object *term)
elm_box_pack_end(opbox, bx); elm_box_pack_end(opbox, bx);
evas_object_show(bx); evas_object_show(bx);
preview = o = elm_entry_add(opbox);
elm_entry_scrollable_set(o, EINA_TRUE);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
elm_entry_scrollbar_policy_set(o, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
elm_entry_single_line_set(o, EINA_TRUE);
elm_object_text_set(o, "Abc-123, O0, l1");
evas_object_smart_callback_add(o, "changed,user", _cb_op_text_changed, NULL);
elm_box_pack_end(opbox, o);
evas_object_show(o);
it_class = elm_genlist_item_class_new(); it_class = elm_genlist_item_class_new();
it_class->item_style = "default"; it_class->item_style = "default";
@ -259,10 +243,11 @@ options_font(Evas_Object *opbox, Evas_Object *term)
f = calloc(1, sizeof(Font)); f = calloc(1, sizeof(Font));
f->name = eina_stringshare_add(file); f->name = eina_stringshare_add(file);
f->term = term; f->term = term;
f->preview = preview;
f->bitmap = EINA_TRUE; f->bitmap = EINA_TRUE;
fonts = eina_list_append(fonts, f); fonts = eina_list_append(fonts, f);
it = elm_genlist_item_append(o, it_class, f, grp_it, f->item = it = elm_genlist_item_append(o, it_class, f, grp_it,
ELM_GENLIST_ITEM_NONE, ELM_GENLIST_ITEM_NONE,
_cb_op_font_sel, f); _cb_op_font_sel, f);
if ((config->font.bitmap) && (config->font.name) && if ((config->font.bitmap) && (config->font.name) &&
@ -298,10 +283,11 @@ options_font(Evas_Object *opbox, Evas_Object *term)
f = calloc(1, sizeof(Font)); f = calloc(1, sizeof(Font));
f->name = eina_stringshare_add(fname); f->name = eina_stringshare_add(fname);
f->term = term; f->term = term;
f->preview = preview;
f->bitmap = EINA_FALSE; f->bitmap = EINA_FALSE;
eina_hash_add(fonthash, fname, f); eina_hash_add(fonthash, fname, f);
fonts = eina_list_append(fonts, f); fonts = eina_list_append(fonts, f);
it = elm_genlist_item_append(o, it_class, f, grp_it, f->item = it = elm_genlist_item_append(o, it_class, f, grp_it,
ELM_GENLIST_ITEM_NONE, ELM_GENLIST_ITEM_NONE,
_cb_op_font_sel, f); _cb_op_font_sel, f);
if ((!config->font.bitmap) && (config->font.name) && if ((!config->font.bitmap) && (config->font.name) &&