On Mon, Oct 27, 2008 at 12:22 AM, Enlightenment SVN
<[EMAIL PROTECTED]> wrote:
> Log:
>  add evas_object_box.
>
>  Box is a smart object to help with the common task of laying out lots
>  of objects. It's very flexibile and one can customize the layout
>  function on a per-object basis dynamically, just set a new layout
>  function (the most common are provided). By default layouts use size
>  hints from children to do their work, but one can also add new
>  properties, just subclass with evas_object_smart_smart_set() and then
>  define your own option_* callbacks.
>
>  This code was ported from Guarana (widgets/sequence_box.c) with
>  permission of ProFUSION embedded systems so it can be relicensed from
>  LGPL to Evas license.
>
>  Original author: Gustavo Lima Chaves <[EMAIL PROTECTED]>
>  Port: Gustavo Sverzut Barbieri <[EMAIL PROTECTED]>

This code is part of our effort to unify common code into base libs,
where its worth to avoid duplicating code over and over again.

With that in Evas, we can now expose it in Edje and use it in Guarana
and Elementary and possible any other toolkit. It uses Evas_Object's
size hints infrastructure, but can be extended to have its own
properties if one wish.

Attached is a test case and example. You can try to hack your own
fancy layout function, it's it's generic and useful to others, add it
to evas as well (Like layout using a Bezier or any other path).

People implementing Ecore Evas can now use layout "stack" and
ecore_evas_object_associate() to provide the "main window" concept,
just add your background and then your object to the evas_object_box
and associate this box to the window. If you want your background to
scale in both directions, just set it's aligns to -1.0 and -1.0.

TODO: rewrite most operations to use fixed point math, saving embedded
systems of doing slow soft-float.

-- 
Gustavo Sverzut Barbieri
http://profusion.mobi embedded systems
--------------------------------------
MSN: [EMAIL PROTECTED]
Skype: gsbarbieri
Mobile: +55 (19) 9225-2202
#include <Ecore.h>
#include <Evas.h>
#include <Ecore_Evas.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

struct test_data {
    Ecore_Evas *ee;
    Evas *evas;
    Evas_Object *bg;
    Evas_Object *box;
    float align_h;
    float align_v;
    int padding_h;
    int padding_v;
};

static struct test_data d;

static void
on_keydown(void *data, Evas *evas, Evas_Object *o, void *einfo)
{
    struct test_data *test = data;
    Evas_Event_Key_Down *ev = einfo;

    if (strcmp(ev->keyname, "Escape") == 0)
        ecore_main_loop_quit();

    if (strcmp(ev->keyname, "1") == 0)
        evas_object_box_layout_set(
            test->box, evas_object_box_layout_horizontal);

    if (strcmp(ev->keyname, "2") == 0)
        evas_object_box_layout_set(
            test->box, evas_object_box_layout_vertical);

    if (strcmp(ev->keyname, "3") == 0)
        evas_object_box_layout_set(
            test->box, evas_object_box_layout_homogeneous_horizontal);

    if (strcmp(ev->keyname, "4") == 0)
        evas_object_box_layout_set(
            test->box, evas_object_box_layout_homogeneous_vertical);

    if (strcmp(ev->keyname, "5") == 0)
        evas_object_box_layout_set(
            test->box,
            evas_object_box_layout_homogeneous_max_size_horizontal);

    if (strcmp(ev->keyname, "6") == 0)
        evas_object_box_layout_set(
            test->box,
            evas_object_box_layout_homogeneous_max_size_vertical);

    if (strcmp(ev->keyname, "7") == 0)
        evas_object_box_layout_set(
            test->box, evas_object_box_layout_flow_horizontal);

    if (strcmp(ev->keyname, "8") == 0)
        evas_object_box_layout_set(
            test->box, evas_object_box_layout_flow_vertical);

    if (strcmp(ev->keyname, "9") == 0)
        evas_object_box_layout_set(
            test->box, evas_object_box_layout_stack);
}

static Evas_Object *
box_new(Evas *evas, const char *name, int x, int y, int w, int h)
{
    Evas_Object *o;

    o = evas_object_box_add(evas);
    evas_object_move(o, x, y);
    evas_object_resize(o, w, h);
    evas_object_show(o);

    evas_object_name_set(o, name);

    return o;
}

static void
on_resize(Ecore_Evas *ee)
{
    int w, h;

    evas_output_viewport_get(d.evas, NULL, NULL, &w, &h);
    evas_object_resize(d.bg, w, h);
    evas_object_resize(d.box, w, h);
}

static void
on_destroy(Ecore_Evas *ee)
{
    ecore_main_loop_quit();
}

int
main(int argc, char *argv[])
{
    Ecore_Evas *ee;
    Evas_Object_Box_Option *opt;
    int w, h, i;
    Evas_Object *last;
    Evas_Object *o;

    evas_init();
    ecore_init();
    ecore_evas_init();

    ee = ecore_evas_new(NULL, 0, 0, 640, 480, NULL);
    ecore_evas_show(ee);

    d.ee = ee;
    d.evas = ecore_evas_get(ee);
    d.align_h = 0.0;
    d.align_v = -1.0;
    d.padding_h = 0;
    d.padding_v = 0;

    ecore_evas_callback_resize_set(ee, on_resize);
    ecore_evas_callback_destroy_set(ee, on_destroy);

    evas_output_viewport_get(d.evas, NULL, NULL, &w, &h);

    d.bg = evas_object_rectangle_add(d.evas);
    evas_object_resize(d.bg, w, h);
    evas_object_show(d.bg);
    evas_object_focus_set(d.bg, 1);
    evas_object_event_callback_add(
        d.bg, EVAS_CALLBACK_KEY_DOWN, on_keydown, &d);

    d.box = box_new(d.evas, "box", 0, 0, w, h);

    evas_object_box_align_h_set(d.box, d.align_h);
    evas_object_box_align_v_set(d.box, d.align_v);
    evas_object_box_padding_h_set(d.box, d.padding_h);
    evas_object_box_padding_v_set(d.box, d.padding_v);

    for (i = 1; i <= 5; i++) {
        o = last = evas_object_rectangle_add(d.evas);
        evas_object_resize(o, 50, 50);
        evas_object_color_set(o, 128, 0, 0, 128);
        evas_object_show(o);

        opt = evas_object_box_append(d.box, o);
        if (!opt)
            return 1;

        evas_object_size_hint_align_set(opt->obj, 0.0, 0.0);
        evas_object_size_hint_padding_set(opt->obj, 0, 0, 0, 0);
        evas_object_size_hint_weight_set(opt->obj, 0.0, 0.0);

        /* evas_object_size_hint_min_set(opt->obj, i * 2, i * 2); */
        /* evas_object_size_hint_max_set(opt->obj, 15 + i, 15 + i); */
    }

    o = evas_object_rectangle_add(d.evas);
    evas_object_resize(o, 10, 10);
    evas_object_color_set(o, 255, 0, 255, 255);
    evas_object_show(o);
    printf("inserting magenta before last\n");
    opt = evas_object_box_insert_before(d.box, o, last);

    evas_object_size_hint_align_set(opt->obj, 0.0, 0.0);
    evas_object_size_hint_padding_set(opt->obj, 0, 0, 0, 0);
    evas_object_size_hint_weight_set(opt->obj, 0.0, 0.0);

    o = evas_object_rectangle_add(d.evas);
    evas_object_resize(o, 10, 10);
    evas_object_color_set(o, 0, 255, 0, 255);
    evas_object_show(o);
    printf("inserting green at 3\n");
    opt = evas_object_box_insert_at(d.box, o, 3);

    evas_object_size_hint_align_set(opt->obj, 0.0, 0.0);
    evas_object_size_hint_padding_set(opt->obj, 0, 0, 0, 0);
    evas_object_size_hint_weight_set(opt->obj, 0.0, 0.0);

    ecore_main_loop_begin();

    ecore_evas_shutdown();
    ecore_shutdown();
    evas_shutdown();


    return 0;
}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to