summaryrefslogtreecommitdiff
path: root/src/bin/options_font.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2012-06-17 22:30:07 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2012-06-17 22:30:07 +0000
commitd2321e4f655cb48a8f64c66632808c5f012727cd (patch)
treef71914bee8a050df005cc679ecbf02533a87bbb9 /src/bin/options_font.c
parentb220b1e468df2b9e4a26fe65947e8d3644e17365 (diff)
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
Diffstat (limited to 'src/bin/options_font.c')
-rw-r--r--src/bin/options_font.c126
1 files changed, 56 insertions, 70 deletions
diff --git a/src/bin/options_font.c b/src/bin/options_font.c
index 08b8f2f..d1feaac 100644
--- a/src/bin/options_font.c
+++ b/src/bin/options_font.c
@@ -12,8 +12,10 @@ typedef struct _Font Font;
12 12
13struct _Font 13struct _Font
14{ 14{
15 Elm_Object_Item *item;
15 const char *name; 16 const char *name;
16 Evas_Object *term; 17 Evas_Object *term;
18 Evas_Object *preview; /* TODO: move preview and term to a parent struct */
17 Eina_Bool bitmap : 1; 19 Eina_Bool bitmap : 1;
18}; 20};
19 21
@@ -21,6 +23,15 @@ static Eina_List *fonts = NULL;
21static Eina_Hash *fonthash = NULL; 23static Eina_Hash *fonthash = NULL;
22 24
23static void 25static void
26_update_preview(void)
27{
28 const Eina_List *l;
29 const Font *f;
30 EINA_LIST_FOREACH(fonts, l, f)
31 elm_genlist_item_update(f->item);
32}
33
34static void
24_update_sizing(Evas_Object *term) 35_update_sizing(Evas_Object *term)
25{ 36{
26 Evas_Coord ow = 0, oh = 0, mw = 1, mh = 1, w, h; 37 Evas_Coord ow = 0, oh = 0, mw = 1, mh = 1, w, h;
@@ -63,6 +74,7 @@ _cb_op_fontsize_sel(void *data, Evas_Object *obj, void *event __UNUSED__)
63 _update_sizing(term); 74 _update_sizing(term);
64 elm_genlist_realized_items_update(op_fontlist); 75 elm_genlist_realized_items_update(op_fontlist);
65 config_save(config, NULL); 76 config_save(config, NULL);
77 _update_preview();
66} 78}
67 79
68static int 80static int
@@ -71,81 +83,36 @@ _cb_op_font_sort(const void *d1, const void *d2)
71 return strcasecmp(d1, d2); 83 return strcasecmp(d1, d2);
72} 84}
73 85
74static void
75_cb_op_font_preview_del(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
76{
77 Evas_Object *o;
78
79 o = edje_object_part_swallow_get(obj, "terminology.content");
80 if (o) evas_object_del(o);
81}
82
83static void
84_cb_op_font_preview_eval(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
85{
86 Font *f = data;
87 Evas_Object *o;
88 Evas_Coord ox, oy, ow, oh, vx, vy, vw, vh;
89 char buf[4096];
90 Config *config = termio_config_get(f->term);
91
92 if (!evas_object_visible_get(obj)) return;
93 if (edje_object_part_swallow_get(obj, "terminology.content")) return;
94 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
95 if ((ow < 2) || (oh < 2)) return;
96 evas_output_viewport_get(evas_object_evas_get(obj), &vx, &vy, &vw, &vh);
97 if (ELM_RECTS_INTERSECT(ox, oy, ow, oh, vx, vy, vw, vh))
98 {
99 o = evas_object_text_add(evas_object_evas_get(obj));
100 evas_object_color_set(o, 0, 0, 0, 255);
101 if (evas_object_data_get(obj, "_f"))
102 evas_object_text_text_set(o, "Abc");
103 else
104 evas_object_text_text_set(o, "123");
105 if (f->bitmap)
106 {
107 snprintf(buf, sizeof(buf), "%s/fonts/%s",
108 elm_app_data_dir_get(), f->name);
109 evas_object_text_font_set(o, buf, config->font.size);
110 }
111 else
112 evas_object_text_font_set(o, f->name, config->font.size);
113 evas_object_geometry_get(o, NULL, NULL, &ow, &oh);
114 evas_object_size_hint_min_set(o, ow, oh);
115 edje_object_part_swallow(obj, "terminology.content", o);
116 }
117}
118
119static Evas_Object * 86static Evas_Object *
120_cb_op_font_content_get(void *data, Evas_Object *obj, const char *part) 87_cb_op_font_content_get(void *data, Evas_Object *obj, const char *part)
121{ 88{
122 Font *f = data; 89 Font *f = data;
123 Config *config = termio_config_get(f->term); 90 Config *config = termio_config_get(f->term);
91 Evas_Object *o;
92 const char *font, *s = elm_object_text_get(f->preview);
93 char buf[PATH_MAX];
124 94
125 if ((!strcmp(part, "elm.swallow.icon")) || 95 if (strcmp(part, "elm.swallow.end") != 0) return NULL;
126 (!strcmp(part, "elm.swallow.end")))
127 {
128 Evas_Object *o;
129 96
130 o = edje_object_add(evas_object_evas_get(obj)); 97 o = edje_object_add(evas_object_evas_get(obj));
131 edje_object_file_set(o, config_theme_path_get(config), 98 edje_object_file_set(o, config_theme_path_get(config),
132 "terminology/fontpreview"); 99 "terminology/fontpreview");
133 evas_object_size_hint_min_set(o, 100
134 40 * elm_config_scale_get(), 101 if (!f->bitmap)
135 40 * elm_config_scale_get()); 102 font = f->name;
136 evas_object_event_callback_add(o, EVAS_CALLBACK_MOVE, 103 else
137 _cb_op_font_preview_eval, f); 104 {
138 evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, 105 snprintf(buf, sizeof(buf), "%s/fonts/%s",
139 _cb_op_font_preview_eval, f); 106 elm_app_data_dir_get(), f->name);
140 evas_object_event_callback_add(o, EVAS_CALLBACK_SHOW, 107 font = buf;
141 _cb_op_font_preview_eval, f);
142 evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
143 _cb_op_font_preview_del, f);
144 if (!strcmp(part, "elm.swallow.icon"))
145 evas_object_data_set(o, "_f", o);
146 return o;
147 } 108 }
148 return NULL; 109
110 edje_object_text_class_set(o, "terminology.preview",
111 font, config->font.size);
112 edje_object_part_text_set(o, "terminology.text.preview", s);
113 edje_object_update_hints_set(o, EINA_TRUE);
114
115 return o;
149} 116}
150 117
151static char * 118static char *
@@ -167,6 +134,12 @@ _cb_op_font_group_text_get(void *data, Evas_Object *obj __UNUSED__, const char *
167 return strdup(data); 134 return strdup(data);
168} 135}
169 136
137static void
138_cb_op_text_changed(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
139{
140 _update_preview();
141}
142
170void 143void
171options_font_clear(void) 144options_font_clear(void)
172{ 145{
@@ -187,7 +160,7 @@ options_font_clear(void)
187void 160void
188options_font(Evas_Object *opbox, Evas_Object *term) 161options_font(Evas_Object *opbox, Evas_Object *term)
189{ 162{
190 Evas_Object *o, *bx; 163 Evas_Object *o, *bx, *preview;
191 char buf[4096], *file, *fname, *s; 164 char buf[4096], *file, *fname, *s;
192 Eina_List *files, *fontlist, *l; 165 Eina_List *files, *fontlist, *l;
193 Font *f; 166 Font *f;
@@ -226,6 +199,17 @@ options_font(Evas_Object *opbox, Evas_Object *term)
226 199
227 elm_box_pack_end(opbox, bx); 200 elm_box_pack_end(opbox, bx);
228 evas_object_show(bx); 201 evas_object_show(bx);
202
203 preview = o = elm_entry_add(opbox);
204 elm_entry_scrollable_set(o, EINA_TRUE);
205 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
206 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
207 elm_entry_scrollbar_policy_set(o, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
208 elm_entry_single_line_set(o, EINA_TRUE);
209 elm_object_text_set(o, "Abc-123, O0, l1");
210 evas_object_smart_callback_add(o, "changed,user", _cb_op_text_changed, NULL);
211 elm_box_pack_end(opbox, o);
212 evas_object_show(o);
229 213
230 it_class = elm_genlist_item_class_new(); 214 it_class = elm_genlist_item_class_new();
231 it_class->item_style = "default"; 215 it_class->item_style = "default";
@@ -259,10 +243,11 @@ options_font(Evas_Object *opbox, Evas_Object *term)
259 f = calloc(1, sizeof(Font)); 243 f = calloc(1, sizeof(Font));
260 f->name = eina_stringshare_add(file); 244 f->name = eina_stringshare_add(file);
261 f->term = term; 245 f->term = term;
246 f->preview = preview;
262 f->bitmap = EINA_TRUE; 247 f->bitmap = EINA_TRUE;
263 fonts = eina_list_append(fonts, f); 248 fonts = eina_list_append(fonts, f);
264 249
265 it = elm_genlist_item_append(o, it_class, f, grp_it, 250 f->item = it = elm_genlist_item_append(o, it_class, f, grp_it,
266 ELM_GENLIST_ITEM_NONE, 251 ELM_GENLIST_ITEM_NONE,
267 _cb_op_font_sel, f); 252 _cb_op_font_sel, f);
268 if ((config->font.bitmap) && (config->font.name) && 253 if ((config->font.bitmap) && (config->font.name) &&
@@ -298,10 +283,11 @@ options_font(Evas_Object *opbox, Evas_Object *term)
298 f = calloc(1, sizeof(Font)); 283 f = calloc(1, sizeof(Font));
299 f->name = eina_stringshare_add(fname); 284 f->name = eina_stringshare_add(fname);
300 f->term = term; 285 f->term = term;
286 f->preview = preview;
301 f->bitmap = EINA_FALSE; 287 f->bitmap = EINA_FALSE;
302 eina_hash_add(fonthash, fname, f); 288 eina_hash_add(fonthash, fname, f);
303 fonts = eina_list_append(fonts, f); 289 fonts = eina_list_append(fonts, f);
304 it = elm_genlist_item_append(o, it_class, f, grp_it, 290 f->item = it = elm_genlist_item_append(o, it_class, f, grp_it,
305 ELM_GENLIST_ITEM_NONE, 291 ELM_GENLIST_ITEM_NONE,
306 _cb_op_font_sel, f); 292 _cb_op_font_sel, f);
307 if ((!config->font.bitmap) && (config->font.name) && 293 if ((!config->font.bitmap) && (config->font.name) &&