handle label resizes and wraps properly - add test for it!
SVN revision: 44964
This commit is contained in:
parent
fb2b5b1c5c
commit
61c86da960
|
@ -556,7 +556,7 @@ collections {
|
|||
description { state: "default" 0.0;
|
||||
text {
|
||||
style: "textblock_style";
|
||||
min: 0 0;
|
||||
min: 0 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,8 @@ test_menu.c \
|
|||
test_panel.c \
|
||||
test_map.c \
|
||||
test_weather.c \
|
||||
test_flip.c
|
||||
test_flip.c \
|
||||
test_label.c
|
||||
|
||||
elementary_test_LDADD = $(top_builddir)/src/lib/libelementary.la @ELEMENTARY_EWEATHER_LIBS@
|
||||
elementary_test_LDFLAGS =
|
||||
|
|
|
@ -56,6 +56,7 @@ void test_panel(void *data, Evas_Object *obj, void *event_info);
|
|||
void test_map(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_weather(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_flip(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_label(void *data, Evas_Object *obj, void *event_info);
|
||||
|
||||
static void
|
||||
my_win_del(void *data, Evas_Object *obj, void *event_info)
|
||||
|
@ -194,6 +195,7 @@ my_win_main(void)
|
|||
elm_list_item_append(li, "Map", NULL, NULL, test_map, NULL);
|
||||
elm_list_item_append(li, "Weather", NULL, NULL, test_weather, NULL);
|
||||
elm_list_item_append(li, "Flip", NULL, NULL, test_flip, NULL);
|
||||
elm_list_item_append(li, "Label", NULL, NULL, test_label, NULL);
|
||||
|
||||
elm_list_go(li);
|
||||
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
#include <Elementary.h>
|
||||
#ifndef ELM_LIB_QUICKLAUNCH
|
||||
|
||||
void
|
||||
test_label(void *data, Evas_Object *obj, void *event_info)
|
||||
{
|
||||
Evas_Object *win, *bg, *bx, *lb;
|
||||
|
||||
win = elm_win_add(NULL, "label", ELM_WIN_BASIC);
|
||||
elm_win_title_set(win, "Label");
|
||||
elm_win_autodel_set(win, 1);
|
||||
|
||||
bg = elm_bg_add(win);
|
||||
elm_win_resize_object_add(win, bg);
|
||||
evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_show(bg);
|
||||
|
||||
bx = elm_box_add(win);
|
||||
evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
|
||||
lb = elm_label_add(win);
|
||||
elm_label_label_set(lb,
|
||||
"<b>This is a small label</b>"
|
||||
);
|
||||
evas_object_size_hint_weight_set(lb, 0.0, 0.0);
|
||||
evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_box_pack_end(bx, lb);
|
||||
evas_object_show(lb);
|
||||
|
||||
lb = elm_label_add(win);
|
||||
elm_label_label_set(lb,
|
||||
"This is a larger label with newlines<br>"
|
||||
"to make it bigger, bit it won't expand or wrap<br>"
|
||||
"just be a block of text that can't change its<br>"
|
||||
"formatting as it's fixed based on text<br>"
|
||||
);
|
||||
evas_object_size_hint_weight_set(lb, 0.0, 0.0);
|
||||
evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_box_pack_end(bx, lb);
|
||||
evas_object_show(lb);
|
||||
|
||||
lb = elm_label_add(win);
|
||||
elm_label_line_wrap_set(lb, 1);
|
||||
elm_label_label_set(lb,
|
||||
"<b>"
|
||||
"This is more text designed to line-wrap here as "
|
||||
"This object is resized horizontally. As it is "
|
||||
"resized vertically though, nothing should change. "
|
||||
"The amount of space allocated vertically should "
|
||||
"change as horizontal size changes."
|
||||
"</b>"
|
||||
);
|
||||
evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
|
||||
evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_box_pack_end(bx, lb);
|
||||
evas_object_show(lb);
|
||||
|
||||
lb = elm_label_add(win);
|
||||
elm_label_label_set(lb,
|
||||
"This small label set to wrap"
|
||||
);
|
||||
evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
|
||||
evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_box_pack_end(bx, lb);
|
||||
evas_object_show(lb);
|
||||
|
||||
elm_win_resize_object_add(win, bx);
|
||||
evas_object_show(bx);
|
||||
|
||||
evas_object_resize(win, 320, 300);
|
||||
|
||||
evas_object_show(win);
|
||||
}
|
||||
#endif
|
|
@ -14,18 +14,41 @@ struct _Widget_Data
|
|||
{
|
||||
Evas_Object *lbl;
|
||||
const char *label;
|
||||
Evas_Coord lastw;
|
||||
Ecore_Job *deferred_recalc_job;
|
||||
Eina_Bool linewrap : 1;
|
||||
Eina_Bool changed : 1;
|
||||
};
|
||||
|
||||
static void _del_hook(Evas_Object *obj);
|
||||
static void _theme_hook(Evas_Object *obj);
|
||||
static void _sizing_eval(Evas_Object *obj);
|
||||
|
||||
static void
|
||||
_elm_win_recalc_job(void *data)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(data);
|
||||
Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
|
||||
Evas_Coord resw, resh, minminw;
|
||||
|
||||
wd->deferred_recalc_job = NULL;
|
||||
evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
|
||||
resh = 0;
|
||||
minminw = 0;
|
||||
edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, 0, 0);
|
||||
minminw = minw;
|
||||
edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, resw, 0);
|
||||
evas_object_size_hint_min_set(data, minminw, minh);
|
||||
maxh = minh;
|
||||
evas_object_size_hint_max_set(data, -1, maxh);
|
||||
}
|
||||
|
||||
static void
|
||||
_del_hook(Evas_Object *obj)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
|
||||
if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
|
||||
if (wd->label) eina_stringshare_del(wd->label);
|
||||
free(wd);
|
||||
}
|
||||
|
@ -50,12 +73,37 @@ _sizing_eval(Evas_Object *obj)
|
|||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
|
||||
Evas_Coord resw, resh, minminw;
|
||||
|
||||
edje_object_size_min_calc(wd->lbl, &minw, &minh);
|
||||
evas_object_size_hint_min_set(obj, minw, minh);
|
||||
evas_object_size_hint_max_set(obj, maxw, maxh);
|
||||
if (wd->linewrap)
|
||||
{
|
||||
evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
|
||||
if ((resw == wd->lastw) && (!wd->changed)) return;
|
||||
wd->changed = EINA_FALSE;
|
||||
wd->lastw = resw;
|
||||
if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
|
||||
wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
|
||||
edje_object_size_min_calc(wd->lbl, &minw, &minh);
|
||||
evas_object_size_hint_min_set(obj, minw, minh);
|
||||
maxh = minh;
|
||||
evas_object_size_hint_max_set(obj, maxw, maxh);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(data);
|
||||
|
||||
if (wd->linewrap)
|
||||
{
|
||||
_sizing_eval(data);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Add a new label to the parent
|
||||
*
|
||||
|
@ -88,6 +136,10 @@ elm_label_add(Evas_Object *parent)
|
|||
wd->label = eina_stringshare_add("<br>");
|
||||
edje_object_part_text_set(wd->lbl, "elm.text", "<br>");
|
||||
elm_widget_resize_object_set(obj, wd->lbl);
|
||||
|
||||
evas_object_event_callback_add(wd->lbl, EVAS_CALLBACK_RESIZE, _resize, obj);
|
||||
|
||||
wd->changed = 1;
|
||||
_sizing_eval(obj);
|
||||
return obj;
|
||||
}
|
||||
|
@ -109,6 +161,7 @@ elm_label_label_set(Evas_Object *obj, const char *label)
|
|||
if (wd->label) eina_stringshare_del(wd->label);
|
||||
wd->label = eina_stringshare_add(label);
|
||||
edje_object_part_text_set(wd->lbl, "elm.text", label);
|
||||
wd->changed = 1;
|
||||
_sizing_eval(obj);
|
||||
}
|
||||
|
||||
|
@ -142,5 +195,6 @@ elm_label_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
|
|||
_elm_theme_set(wd->lbl, "label", "base", elm_widget_style_get(obj));
|
||||
elm_label_label_set(obj, t);
|
||||
eina_stringshare_del(t);
|
||||
wd->changed = 1;
|
||||
_sizing_eval(obj);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue