Hi, folks.
I'm writing to gather, specially from Raster and the more ancient Evas
hackers, what to expect/document about Evas' size hints, WHEN
COMBINED.
We have some common sense ground here, obviously, like: min/max sizes
must always be respected.
But if we start to mix, for a given container object, member objects
having min, max, align, padding and weight hints, things start not to
be so straightforward WRT defining expected/suggested behavior for
people implementing objects taking hints for account.
Attached is a simple app. with a *horizontal* box (with geometry
marked in red) and a child blue rectangle. I've setuped its size hints
as [min=10,10, max=100,100, align=0.5, padding=30,0,0,0,
weight=0.0,0.0].
It has commands to set hardcoded sizes on the box ('1', '2' and '3'),
because it will resize itself after packing objects into it. There
also a command to toggle weight on/off on that rectangle.
For the 0-weight cases, it layouts as expected. With 1.0 weight, come
the doubts:
- shouldn't case '1' with weight 1.0 be equal to the case with weight
0.0?
- what to do on case '5', here (weight 1.0). Should the size enforced
on the child match its min. one, also letting it flow out of the
parent's bounds because of the padding?
Case '3' for 1.0 weight is OK, because the horizontal box won't
"listen" to y components of weights on children.
So, please, help me sort out what should be the behavior on those two
cases, so that I can document properly the issue on *combination of
one or more hints*.
--
Gustavo Lima Chaves
Computer Engineer @ ProFUSION Embedded Systems
/* gcc -o test evas-combined-hints.c `pkg-config --libs --cflags evas ecore
ecore-evas` */
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
#define PACKAGE_EXAMPLES_DIR "."
#define __UNUSED__
#endif
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define WIDTH 480
#define HEIGHT 480
static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
struct test_data
{
Ecore_Evas *ee;
Evas *canvas;
Evas_Object *bg, *box, *rect, *border;
};
static struct test_data d = {0};
/* here just to keep our example's window size and background image's
* size in synchrony */
static void
_canvas_resize_cb(Ecore_Evas *ee)
{
int w, h;
ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
evas_object_resize(d.bg, w, h);
}
static void
_on_box_resize(void *data __UNUSED__,
Evas *evas __UNUSED__,
Evas_Object *o,
void *einfo __UNUSED__)
{
Evas_Coord w, h;
evas_object_geometry_get(o, NULL, NULL, &w, &h);
fprintf(stdout, "Box got resized to (%d, %d)\n", w, h);
evas_object_resize(d.border, w + 2, h + 2);
}
/* use the following commands to interact with this example - 'h' is
* the key for help */
static void
_on_keydown(void *data __UNUSED__,
Evas *evas __UNUSED__,
Evas_Object *o __UNUSED__,
void *einfo)
{
Evas_Event_Key_Down *ev = einfo;
if (strcmp(ev->keyname, "h") == 0) /* print help */
{
fprintf(stdout,
"commands are:\n"
"\ti increase box size\n"
"\td decrease box size\n"
"\t1 hardcode box size to 10x10\n"
"\t5 hardcode box size to 50x50\n"
"\t3 hardcode box size to 300x300\n"
"\tw toggle rectangle's weight hints\n"
"\th - print help\n");
return;
}
/* increase box size */
if (strcmp(ev->keyname, "i") == 0)
{
Evas_Coord w, h;
evas_object_geometry_get(d.box, NULL, NULL, &w, &h);
w += 10;
h += 10;
evas_object_resize(d.box, w, h);
return;
}
/* decrease box size */
if (strcmp(ev->keyname, "d") == 0)
{
Evas_Coord w, h;
evas_object_geometry_get(d.box, NULL, NULL, &w, &h);
w -= 10;
h -= 10;
evas_object_resize(d.box, w, h);
return;
}
/* hardcode box size to 10x10 */
if (strcmp(ev->keyname, "1") == 0)
{
evas_object_resize(d.box, 10, 10);
return;
}
/* hardcode box size to 50x50 */
if (strcmp(ev->keyname, "5") == 0)
{
evas_object_resize(d.box, 50, 50);
return;
}
/* hardcode box size to 300x300 */
if (strcmp(ev->keyname, "3") == 0)
{
evas_object_resize(d.box, 300, 300);
return;
}
/* toggle rectangle's weight hints */
if (strcmp(ev->keyname, "w") == 0)
{
double x, y;
evas_object_size_hint_weight_get(d.rect, &x, &y);
x = !x;
y = !y;
evas_object_size_hint_weight_set(d.rect, x, y);
fprintf(stdout, "Weight hints go to %f, %f\n", x, y);
return;
}
}
static void
_on_destroy(Ecore_Evas *ee __UNUSED__)
{
ecore_main_loop_quit();
}
int
main(void)
{
if (!ecore_evas_init())
return EXIT_FAILURE;
/* this will give you a window with an Evas canvas under the first
* engine available */
d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
if (!d.ee)
goto error;
ecore_evas_callback_destroy_set(d.ee, _on_destroy);
ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
ecore_evas_show(d.ee);
/* the canvas pointer, de facto */
d.canvas = ecore_evas_get(d.ee);
d.bg = evas_object_rectangle_add(d.canvas);
evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
evas_object_move(d.bg, 0, 0); /* at canvas' origin */
evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
evas_object_show(d.bg);
evas_object_focus_set(d.bg, EINA_TRUE);
evas_object_event_callback_add(
d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
int bw, bh;
bw = bh = 10;
/* Evas box with horizontal layout */
d.box = evas_object_box_add(d.canvas);
evas_object_move(d.box, 30, 30);
evas_object_event_callback_add(
d.box, EVAS_CALLBACK_RESIZE, _on_box_resize, NULL);
evas_object_resize(d.box, bw, bh);
evas_object_show(d.box);
/* 1 px red border to highlight the box */
d.border = evas_object_image_filled_add(d.canvas);
evas_object_image_file_set(d.border, border_img_path, NULL);
evas_object_image_border_set(d.border, 1, 1, 1, 1);
evas_object_image_border_center_fill_set(d.border, EVAS_BORDER_FILL_NONE);
evas_object_move(d.border, 30 - 1, 30 - 1);
evas_object_resize(d.border, bw + 2, bh + 2);
evas_object_layer_set(d.border, EVAS_LAYER_MAX);
evas_object_show(d.border);
d.rect = evas_object_rectangle_add(d.canvas);
evas_object_color_set(d.rect, 0, 0, 255, 255);
/* min=10,10, max=100,100, align=0.5, padding=30,0,0,0, weight=0.0,0.0 */
evas_object_size_hint_min_set(d.rect, 50, 50);
evas_object_size_hint_max_set(d.rect, 100, 100);
evas_object_size_hint_align_set(d.rect, 0.5, 0.5);
evas_object_size_hint_padding_set(d.rect, 30, 0, 0, 0);
evas_object_show(d.rect);
evas_object_box_append(d.box, d.rect);
ecore_main_loop_begin();
ecore_evas_shutdown();
return 0;
error:
fprintf(stderr, "you got to have at least one evas engine built and linked"
" up to ecore-evas for this example to run properly.\n");
return -1;
}
------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric
Ries, the creator of the Lean Startup Methodology on "Lean Startup
Secrets Revealed." This video shows you how to validate your ideas,
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel