From 593d8e238692f27adeafbe6e73f7abd29d36f00b Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Tue, 8 Sep 2009 11:18:02 +0000 Subject: [PATCH] more index work SVN revision: 42347 --- data/themes/default.edc | 68 ++++++++++++++++++++++++++++++++++++++ src/bin/test_index.c | 2 +- src/lib/Elementary.h.in | 19 ++++++++++- src/lib/elm_index.c | 86 +++++++++++++++++++++++++++++++++++++++++-------- src/lib/els_box.h | 2 -- 5 files changed, 160 insertions(+), 17 deletions(-) diff --git a/data/themes/default.edc b/data/themes/default.edc index 5034ccb..8c10373 100644 --- a/data/themes/default.edc +++ b/data/themes/default.edc @@ -13223,4 +13223,72 @@ collections { } } } + + group { name: "elm/index/item/vertical/default"; + images { + } + parts { + part { name: "0"; + type: RECT; + mouse_events: 0; + description { state: "default" 0.0; + color: 100 100 0 50; + } + } + part { name: "elm.text"; + type: TEXT; + mouse_events: 0; + scale: 1; + description { state: "default" 0.0; + rel1 { + offset: 1 1; + } + rel2 { + offset: -2 -2; + } + color: 0 0 0 255; + text { + font: "Sans,Edje-Vera"; + size: 10; + min: 1 1; + align: 1.0 0.5; + } + } + } + } + } + + group { name: "elm/index/item_odd/vertical/default"; + images { + } + parts { + part { name: "0"; + type: RECT; + mouse_events: 0; + description { state: "default" 0.0; + color: 100 50 0 50; + } + } + part { name: "elm.text"; + type: TEXT; + mouse_events: 0; + scale: 1; + description { state: "default" 0.0; + rel1 { + offset: 1 1; + } + rel2 { + offset: -2 -2; + } + color: 0 0 0 255; + text { + font: "Sans,Edje-Vera"; + size: 10; + min: 1 1; + align: 1.0 0.5; + } + } + } + } + } } diff --git a/src/bin/test_index.c b/src/bin/test_index.c index c77d302..8fe91dc 100644 --- a/src/bin/test_index.c +++ b/src/bin/test_index.c @@ -53,7 +53,7 @@ test_index(void *data, Evas_Object *obj, void *event_info) { char buf[32]; - snprintf(buf, sizeof(buf), "%i\n", i / 10); + snprintf(buf, sizeof(buf), "%i", i / 10); elm_index_item_append(id, buf, it); } } diff --git a/src/lib/Elementary.h.in b/src/lib/Elementary.h.in index 9cbbdeb..c5f5c9a 100644 --- a/src/lib/Elementary.h.in +++ b/src/lib/Elementary.h.in @@ -785,10 +785,14 @@ extern "C" { EAPI void elm_progressbar_unit_format_set(Evas_Object *obj, const char *format); EAPI void elm_progressbar_value_set(Evas_Object *obj, double val); EAPI double elm_progressbar_value_get(const Evas_Object *obj); + /* smart callbacks called: + */ EAPI Evas_Object *elm_separator_add(Evas_Object *parent); EAPI void elm_separator_horizontal_set(Evas_Object *obj, Eina_Bool horizontal); EAPI Eina_Bool elm_separator_horizontal_get(Evas_Object *obj); + /* smart callbacks called: + */ EAPI Evas_Object *elm_spinner_add(Evas_Object *parent); EAPI void elm_spinner_label_format_set(Evas_Object *obj, const char *fmt); @@ -802,6 +806,20 @@ extern "C" { * "changed" - when the spinner value changes * "delay,changed" - when the spinner value changed, but a small time after a change (use this if you only want to respond to a change once the spinner is held still for a short while). */ + + EAPI Evas_Object *elm_index_add(Evas_Object *parent); + EAPI void elm_index_active_set(Evas_Object *obj, Eina_Bool active); + EAPI void elm_index_item_level_set(Evas_Object *obj, int level); + EAPI int elm_index_item_level_get(Evas_Object *obj); + EAPI const void *elm_index_item_selected_get(Evas_Object *obj, int level); + EAPI void elm_index_item_append(Evas_Object *obj, const char *letter, const void *item); + EAPI void elm_index_item_prepend(Evas_Object *obj, const char *letter, const void *item); + EAPI void elm_index_item_append_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative); + EAPI void elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative); + EAPI void elm_index_item_del(Evas_Object *obj, const void *item); + /* smart callbacks called: + */ + #ifdef __cplusplus } #endif @@ -819,7 +837,6 @@ extern "C" { //// (incomplete - medium priority) // * need to add support for disabled in all widgets. Button, toolbar, hoversel, radio, check, spinner and entry are currently done. // * on the fly theme changes - test (should work) -// * need a hold-scroll counter in elm_widget // * hoversel only vertical right now - make horizontal // * when entries are in a scroller and change size, the scroller shows scrollbars. fix. same for selecting. for 1 line entries in a scroller should only have scroll arrow indicators. // diff --git a/src/lib/elm_index.c b/src/lib/elm_index.c index 249cf40..3d8a048 100644 --- a/src/lib/elm_index.c +++ b/src/lib/elm_index.c @@ -23,6 +23,7 @@ struct _Widget_Data Evas_Object *bx[2]; // 2 - for now all that's supported Eina_List *items; // 1 list. yes N levels, but only 2 for now and # of items will be small int level; + Evas_Coord dx, dy; Eina_Bool horizontal : 1; Eina_Bool active : 1; Eina_Bool down : 1; @@ -60,8 +61,8 @@ _theme_hook(Evas_Object *obj) else _elm_theme_set(wd->base, "index", "base/vertical", elm_widget_style_get(obj)); edje_object_part_swallow(wd->base, "elm.swallow.event", wd->event); - edje_object_part_swallow(wd->base, "elm.swallow.content", wd->bx[0]); - if (edje_object_part_exists(wd->base, "elm.swallow.content.sub")) + edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]); + if (edje_object_part_exists(wd->base, "elm.swallow.index.1")) { if (!wd->bx[1]) { @@ -70,7 +71,7 @@ _theme_hook(Evas_Object *obj) _els_smart_box_homogenous_set(wd->bx[1], 1); elm_widget_sub_object_add(obj, wd->bx[1]); } - edje_object_part_swallow(wd->base, "elm.swallow.content.sub", wd->bx[1]); + edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]); evas_object_show(wd->bx[1]); } else if (wd->bx[1]) @@ -134,10 +135,58 @@ _item_free(Item *it) free(it); } +// FIXME: always have index filled static void _index_eval(Evas_Object *obj) { Widget_Data *wd = elm_widget_data_get(obj); + if (wd->active) + { + Eina_List *l; + Item *it; + Evas_Coord mw, mh; + int i; + + i = 0; + EINA_LIST_FOREACH(wd->items, l, it) + { + Evas_Object *o; + + if (it->level != wd->level) break; + o = edje_object_add(evas_object_evas_get(obj)); + if (i & 0x1) + _elm_theme_set(o, "index", "item_odd/vertical", "default"); + else + _elm_theme_set(o, "index", "item/vertical", "default"); + edje_object_part_text_set(o, "elm.text", it->letter); + edje_object_size_min_restricted_calc(o, &mw, &mh, 0, 0); + evas_object_size_hint_min_set(o, mw, mh); + evas_object_size_hint_weight_set(o, 1.0, 1.0); + evas_object_size_hint_align_set(o, -1.0, -1.0); + elm_widget_sub_object_add(obj, o); + _els_smart_box_pack_end(wd->bx[0], o); + evas_object_show(o); + it->base = o; + i++; + } + edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]); + } + else + { + Eina_List *l; + Item *it; + Evas_Coord mw, mh; + int i; + + i = 0; + EINA_LIST_FOREACH(wd->items, l, it) + { + if (!it->base) continue; + evas_object_del(it->base); + it->base = 0; + } + edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]); + } } static void @@ -153,10 +202,14 @@ _mouse_down(void *data, Evas *e, Evas_Object *o, void *event_info) { Widget_Data *wd = elm_widget_data_get(data); Evas_Event_Mouse_Down *ev = event_info; - Evas_Object *obj = o; + Evas_Coord x, y; if (ev->button != 1) return; wd->down = 1; printf("down!\n"); + evas_object_geometry_get(o, &x, &y, NULL, NULL); + wd->dx = ev->canvas.x - x; + wd->dy = ev->canvas.y - y; + elm_index_active_set(data, 1); } static void @@ -164,10 +217,10 @@ _mouse_up(void *data, Evas *e, Evas_Object *o, void *event_info) { Widget_Data *wd = elm_widget_data_get(data); Evas_Event_Mouse_Up *ev = event_info; - Evas_Object *obj = o; if (ev->button != 1) return; wd->down = 0; printf("up!\n"); + elm_index_active_set(data, 0); } static void @@ -175,19 +228,26 @@ _mouse_move(void *data, Evas *e, Evas_Object *o, void *event_info) { Widget_Data *wd = elm_widget_data_get(data); Evas_Event_Mouse_Move *ev = event_info; - Evas_Object *obj = o; - Evas_Coord x, y, w, h; + Evas_Coord minw = 0, minh = 0, x, y, dx, dy, adx, ady; if (!wd->down) return; - evas_object_geometry_get(o, &x, &y, &w, &h); + elm_coords_finger_size_adjust(1, &minw, 1, &minh); + evas_object_geometry_get(o, &x, &y, NULL, NULL); + x = ev->cur.canvas.x - x; + y = ev->cur.canvas.y - y; + dx = x - wd->dx; + adx = dx; + if (adx < 0) adx = -dx; + dy = y - wd->dy; + ady = dy; + if (ady < 0) ady = -dy; if (wd->horizontal) { } else { - if (ev->cur.canvas.x < x) + if (adx > minw) { - printf("%i\n", wd->level); if (wd->level == 0) { printf("level up\n"); @@ -255,16 +315,16 @@ elm_index_add(Evas_Object *parent) _els_smart_box_orientation_set(wd->bx[0], 0); _els_smart_box_homogenous_set(wd->bx[0], 1); elm_widget_sub_object_add(obj, wd->bx[0]); - edje_object_part_swallow(wd->base, "elm.swallow.content", wd->bx[0]); + edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]); evas_object_show(wd->bx[0]); - if (edje_object_part_exists(wd->base, "elm.swallow.content.sub")) + if (edje_object_part_exists(wd->base, "elm.swallow.index.1")) { wd->bx[1] = _els_smart_box_add(e); _els_smart_box_orientation_set(wd->bx[1], 0); _els_smart_box_homogenous_set(wd->bx[1], 1); elm_widget_sub_object_add(obj, wd->bx[1]); - edje_object_part_swallow(wd->base, "elm.swallow.content.sub", wd->bx[1]); + edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]); evas_object_show(wd->bx[1]); } diff --git a/src/lib/els_box.h b/src/lib/els_box.h index 626a3fd..1fde225 100644 --- a/src/lib/els_box.h +++ b/src/lib/els_box.h @@ -7,5 +7,3 @@ int _els_smart_box_pack_end (Evas_Object *obj, Evas_Object *ch int _els_smart_box_pack_before (Evas_Object *obj, Evas_Object *child, Evas_Object *before); int _els_smart_box_pack_after (Evas_Object *obj, Evas_Object *child, Evas_Object *after); void _els_smart_box_unpack (Evas_Object *obj); -void _els_smart_box_min_size_get (Evas_Object *obj, Evas_Coord *minw, Evas_Coord *minh); -void _els_smart_box_max_size_get (Evas_Object *obj, Evas_Coord *maxw, Evas_Coord *maxh); -- 2.7.4