efl: Use Eina.Size2D for size hint max

This commit is contained in:
Jean-Philippe Andre 2017-09-18 14:07:56 +09:00
parent 994d32f2a8
commit d24dcb3c24
9 changed files with 76 additions and 71 deletions

View File

@ -909,7 +909,7 @@ test_box_stack(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
/* rectangle with a max size */
o = efl_add(EFL_CANVAS_RECTANGLE_CLASS, win,
efl_gfx_color_set(efl_added, 64, 128, 64, 255),
efl_gfx_size_hint_max_set(efl_added, 128, 20));
efl_gfx_size_hint_max_set(efl_added, EINA_SIZE2D(128, 20)));
efl_pack(bx, o);
/* image with a forced min size */

View File

@ -383,6 +383,7 @@ test_gfx_filters(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *eve
for (size_t k = 0; k < EINA_C_ARRAY_LENGTH(images); k++)
{
Eina_Size2D size = { ELM_SCALE_SIZE(48), ELM_SCALE_SIZE(48) };
char buf[PATH_MAX];
if (!images[k].path) break;
@ -390,7 +391,7 @@ test_gfx_filters(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *eve
o = efl_add(EFL_UI_IMAGE_CLASS, win,
efl_gfx_size_hint_weight_set(efl_added, 0.0, 0.0),
efl_gfx_size_hint_align_set(efl_added, 0.5, 0.5),
efl_gfx_size_hint_max_set(efl_added, ELM_SCALE_SIZE(48), ELM_SCALE_SIZE(48)),
efl_gfx_size_hint_max_set(efl_added, size),
efl_gfx_size_hint_min_set(efl_added, ELM_SCALE_SIZE(48), ELM_SCALE_SIZE(48)),
efl_file_set(efl_added, buf, NULL),
efl_name_set(efl_added, images[k].src_name),
@ -401,6 +402,7 @@ test_gfx_filters(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *eve
efl_pack(box2, o);
}
Eina_Size2D maxsz = { -1, ELM_SCALE_SIZE(48 * 2) };
const struct { int r, g, b, a; } colors[] = {
{ 255, 255, 255, 255 },
{ 0, 0, 0, 255 },
@ -420,7 +422,7 @@ test_gfx_filters(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *eve
efl_gfx_size_hint_weight_set(efl_added, 1.0, 0),
efl_gfx_size_hint_align_set(efl_added, -1.0, 0),
elm_colorselector_mode_set(efl_added, ELM_COLORSELECTOR_PALETTE),
efl_gfx_size_hint_max_set(efl_added, -1, ELM_SCALE_SIZE(48 * 2)),
efl_gfx_size_hint_max_set(efl_added, maxsz),
efl_name_set(efl_added, "myColor"),
elm_object_tooltip_text_set(efl_added, "Pick a color to use as variable 'myColor'"),
efl_event_callback_add(efl_added, ELM_COLORSELECTOR_EVENT_CHANGED, _colsel_cb, win));

View File

@ -527,7 +527,7 @@ test_ui_box(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in
objects[i++] = o = elm_button_add(win);
elm_object_text_set(o, "Button with a quite long text.");
efl_gfx_size_hint_align_set(o, -1, -1);
efl_gfx_size_hint_max_set(o, 200, 100);
efl_gfx_size_hint_max_set(o, EINA_SIZE2D(200, 100));
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);

View File

@ -26,6 +26,7 @@ static void
_bt2_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Efl_Canvas_Object *dia, *lb, *parent = data;
Eina_Size2D size = { 300, 150 };
dia = efl_add(EFL_UI_WIN_CLASS, parent,
efl_ui_win_type_set(efl_added, EFL_UI_WIN_DIALOG_BASIC),
@ -41,7 +42,7 @@ _bt2_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_
lb = efl_add(EFL_UI_TEXT_CLASS, dia,
efl_text_set(efl_added, "This is a non-resizable dialog."),
efl_gfx_size_hint_min_set(efl_added, 300, 150),
efl_gfx_size_hint_max_set(efl_added, 300, 150),
efl_gfx_size_hint_max_set(efl_added, size),
efl_gfx_size_hint_weight_set(efl_added, 0, 0));
// Swallow in the label as the default content, this will make it visible.
@ -51,21 +52,21 @@ _bt2_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_
static void
_size_update(void *data, const Efl_Event *ev)
{
int w, h, W, H, wc, hc;
Eina_Size2D sz;
int w, h, wc, hc;
Eina_Size2D sz, max;
char buf[2048];
Eo *dia = ev->object;
Eo *lbl = data;
efl_gfx_size_hint_combined_min_get(dia, &wc, &hc);
efl_gfx_size_hint_min_get(dia, &w, &h);
efl_gfx_size_hint_max_get(dia, &W, &H);
max = efl_gfx_size_hint_max_get(dia);
sz = efl_gfx_size_get(dia);
sprintf(buf, "This is a dialog with min/max size<br>"
"Min size: %dx%d (requested) %dx%d (effective)<br>"
"Max size: %dx%d<br>"
"Current size: %dx%d", w, h, wc, hc, W, H, sz.w, sz.h);
"Current size: %dx%d", w, h, wc, hc, max.w, max.h, sz.w, sz.h);
//efl_text_set(lbl, buf);
elm_object_text_set(lbl, buf);
}
@ -93,7 +94,7 @@ _bt3_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_
// Set min & max size (app-side)
efl_gfx_size_hint_min_set(dia, ELM_SCALE_SIZE(0), ELM_SCALE_SIZE(100));
efl_gfx_size_hint_max_set(dia, ELM_SCALE_SIZE(800), ELM_SCALE_SIZE(600));
efl_gfx_size_hint_max_set(dia, EINA_SIZE2D(ELM_SCALE_SIZE(800), ELM_SCALE_SIZE(600)));
}
static void
@ -120,7 +121,7 @@ _bt4_clicked_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *even
// Set min & max size (app-side)
efl_gfx_size_hint_min_set(dia, ELM_SCALE_SIZE(0), ELM_SCALE_SIZE(100));
efl_gfx_size_hint_max_set(dia, ELM_SCALE_SIZE(800), ELM_SCALE_SIZE(600));
efl_gfx_size_hint_max_set(dia, EINA_SIZE2D(ELM_SCALE_SIZE(800), ELM_SCALE_SIZE(600)));
efl_ui_win_center(dia, EINA_TRUE, EINA_TRUE);
}

View File

@ -87,8 +87,8 @@ interface Efl.Gfx.Size.Hint
the size of smart objects.
]]
values {
w: int; [[Integer to use as the maximum width hint.]]
h: int; [[Integer to use as the maximum height hint.]]
sz: Eina.Size2D; [[Maximum size (hint) in pixels, (-1, -1) by
default for canvas objects).]]
}
}
@property hint_min {

View File

@ -12,7 +12,7 @@ struct _Item_Calc
Evas_Object *obj;
double weight[2];
double align[2];
int max[2];
Eina_Size2D max;
int pad[4];
int want[2];
Efl_Gfx_Size_Hint_Aspect aspect_type;
@ -78,7 +78,7 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
efl_gfx_size_hint_weight_get(o, &item->weight[0], &item->weight[1]);
efl_gfx_size_hint_align_get(o, &item->align[0], &item->align[1]);
efl_gfx_size_hint_margin_get(o, &item->pad[0], &item->pad[1], &item->pad[2], &item->pad[3]);
efl_gfx_size_hint_max_get(o, &item->max[0], &item->max[1]);
item->max = efl_gfx_size_hint_max_get(o);
efl_gfx_size_hint_combined_min_get(o, &item->want[0], &item->want[1]);
efl_gfx_size_hint_aspect_get(o, &item->aspect_type, &item->aspect[0], &item->aspect[1]);
@ -107,10 +107,10 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
if ((item->align[1] < 0) && (h < boxh))
{
double w1, h1;
h1 = item->max[1] > 0 ? MIN(boxh, item->max[1]) : boxh;
h1 = item->max.h > 0 ? MIN(boxh, item->max.h) : boxh;
h1 = MAX(h, h1);
w1 = h1 * item->aspect[0] / item->aspect[1];
w = item->max[0] > 0 ? MIN(w1, item->max[0]) : w1;
w = item->max.w > 0 ? MIN(w1, item->max.w) : w1;
}
}
else
@ -118,10 +118,10 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
if ((item->align[0] < 0) && (w < boxw))
{
double w1, h1;
w1 = item->max[0] > 0 ? MIN(boxw, item->max[0]) : boxw;
w1 = item->max.w > 0 ? MIN(boxw, item->max.w) : boxw;
w1 = MAX(w, w1);
h1 = w1 * item->aspect[1] / item->aspect[0];
h = item->max[1] > 0 ? MIN(h1, item->max[1]) : h1;
h = item->max.h > 0 ? MIN(h1, item->max.h) : h1;
}
}
item->want[0] = w;
@ -139,10 +139,10 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
if (item->want[0] < 0) item->want[0] = 0;
if (item->want[1] < 0) item->want[1] = 0;
if (item->max[0] < 0) item->max[0] = INT_MAX;
if (item->max[1] < 0) item->max[1] = INT_MAX;
if (item->max[0] < item->want[0]) item->max[0] = item->want[0];
if (item->max[1] < item->want[1]) item->max[1] = item->want[1];
if (item->max.w < 0) item->max.w = INT_MAX;
if (item->max.h < 0) item->max.h = INT_MAX;
if (item->max.w < item->want[0]) item->max.w = item->want[0];
if (item->max.h < item->want[1]) item->max.h = item->want[1];
item->want[0] += item->pad[0] + item->pad[1];
item->want[1] += item->pad[2] + item->pad[3];
@ -286,36 +286,36 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
}
}
if ((item->max[0] != INT_MAX) && (item->max[1] != INT_MAX))
if ((item->max.w != INT_MAX) && (item->max.h != INT_MAX))
{
double mar, ar;
mar = item->max[0] / (double)item->max[1];
mar = item->max.w / (double)item->max.h;
ar = item->aspect[0] / (double)item->aspect[1];
if (ar < mar)
{
if (h > item->max[1])
if (h > item->max.h)
{
h = item->max[1];
h = item->max.h;
w = h * item->aspect[0] / item->aspect[1];
}
}
else
{
if (w > item->max[0])
if (w > item->max.w)
{
w = item->max[0];
w = item->max.w;
h = w * item->aspect[1] / item->aspect[0];
}
}
}
else if (item->max[0] != INT_MAX)
else if (item->max.w != INT_MAX)
{
w = MIN(w, MAX(item->want[0], item->max[0]));
w = MIN(w, MAX(item->want[0], item->max.w));
h = w * item->aspect[1] / item->aspect[0];
}
else
{
h = MIN(h, MAX(item->want[1], item->max[1]));
h = MIN(h, MAX(item->want[1], item->max.h));
w = h * item->aspect[0] / item->aspect[1];
}
w = w - item->pad[0] - item->pad[1];
@ -334,9 +334,9 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
else
{
// horizontally
if (item->max[0] < INT_MAX)
if (item->max.w < INT_MAX)
{
w = MIN(MAX(item->want[0] - item->pad[0] - item->pad[1], item->max[0]), cw);
w = MIN(MAX(item->want[0] - item->pad[0] - item->pad[1], item->max.w), cw);
if (item->align[0] < 0)
{
// bad case: fill+max are not good together
@ -361,9 +361,9 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
}
// vertically
if (item->max[1] < INT_MAX)
if (item->max.h < INT_MAX)
{
h = MIN(MAX(item->want[1] - item->pad[2] - item->pad[3], item->max[1]), ch);
h = MIN(MAX(item->want[1] - item->pad[2] - item->pad[3], item->max.h), ch);
if (item->align[1] < 0)
{
// bad case: fill+max are not good together

View File

@ -852,15 +852,16 @@ _elm_win_obj_intercept_layer_set(void *data, Evas_Object *obj EINA_UNUSED, int l
static void
_elm_win_size_hints_update(Efl_Ui_Win *win, Efl_Ui_Win_Data *sd)
{
Evas_Coord minw, minh, maxw, maxh;
Evas_Coord minw, minh;
Eina_Size2D max;
efl_gfx_size_hint_combined_min_get(win, &minw, &minh);
efl_gfx_size_hint_max_get(win, &maxw, &maxh);
if (maxw < 1) maxw = -1;
if (maxh < 1) maxh = -1;
max = efl_gfx_size_hint_max_get(win);
if (max.w < 1) max.w = -1;
if (max.h < 1) max.h = -1;
TRAP(sd, size_min_set, minw, minh);
TRAP(sd, size_max_set, maxw, maxh);
TRAP(sd, size_max_set, max.w, max.h);
}
static void
@ -1614,7 +1615,7 @@ _elm_win_state_change(Ecore_Evas *ee)
if (ch_wm_rotation)
{
efl_gfx_size_hint_restricted_min_set(obj, -1, -1);
efl_gfx_size_hint_max_set(obj, -1, -1);
efl_gfx_size_hint_max_set(obj, EINA_SIZE2D(-1, -1));
#ifdef HAVE_ELEMENTARY_X
ELM_WIN_DATA_ALIVE_CHECK(obj, sd);
_elm_win_xwin_update(sd);
@ -3495,7 +3496,7 @@ _elm_win_resize_objects_eval(Evas_Object *obj, Eina_Bool force_resize)
sd->tmp_updating_hints = 1;
efl_gfx_size_hint_restricted_min_set(obj, minw, minh);
efl_gfx_size_hint_max_set(obj, maxw, maxh);
efl_gfx_size_hint_max_set(obj, EINA_SIZE2D(maxw, maxh));
sd->tmp_updating_hints = 0;
_elm_win_size_hints_update(obj, sd);
@ -5992,18 +5993,18 @@ _efl_ui_win_efl_gfx_size_hint_hint_step_set(Eo *obj EINA_UNUSED, Efl_Ui_Win_Data
}
EOLIAN static void
_efl_ui_win_efl_gfx_size_hint_hint_max_set(Eo *obj, Efl_Ui_Win_Data *sd, int w, int h)
_efl_ui_win_efl_gfx_size_hint_hint_max_set(Eo *obj, Efl_Ui_Win_Data *sd, Eina_Size2D sz)
{
if (sd->tmp_updating_hints)
{
efl_gfx_size_hint_max_set(efl_super(obj, MY_CLASS), w, h);
efl_gfx_size_hint_max_set(efl_super(obj, MY_CLASS), sz);
}
else
{
if (w < 1) w = -1;
if (h < 1) h = -1;
sd->max_w = w;
sd->max_h = h;
if (sz.w < 1) sz.w = -1;
if (sz.h < 1) sz.h = -1;
sd->max_w = sz.w;
sd->max_h = sz.h;
_elm_win_resize_objects_eval(obj, EINA_FALSE);
}
}
@ -6079,7 +6080,7 @@ _win_rotate(Evas_Object *obj, Efl_Ui_Win_Data *sd, int rotation, Eina_Bool resiz
if (resize) TRAP(sd, rotation_with_resize_set, rotation);
else TRAP(sd, rotation_set, rotation);
efl_gfx_size_hint_restricted_min_set(obj, -1, -1);
efl_gfx_size_hint_max_set(obj, -1, -1);
efl_gfx_size_hint_max_set(obj, EINA_SIZE2D(-1, -1));
_elm_win_resize_objects_eval(obj, EINA_FALSE);
#ifdef HAVE_ELEMENTARY_X
_elm_win_xwin_update(sd);

View File

@ -1441,33 +1441,30 @@ _efl_canvas_object_efl_gfx_size_hint_hint_combined_min_get(Eo *eo_obj EINA_UNUSE
if (h) *h = MAX(obj->size_hints->min.h, obj->size_hints->user_min.h);
}
EOLIAN static void
_efl_canvas_object_efl_gfx_size_hint_hint_max_get(Eo *eo_obj EINA_UNUSED, Evas_Object_Protected_Data *obj, Evas_Coord *w, Evas_Coord *h)
EOLIAN static Eina_Size2D
_efl_canvas_object_efl_gfx_size_hint_hint_max_get(Eo *eo_obj EINA_UNUSED, Evas_Object_Protected_Data *obj)
{
if ((!obj->size_hints) || obj->delete_me)
{
if (w) *w = -1;
if (h) *h = -1;
return;
}
if (w) *w = obj->size_hints->max.w;
if (h) *h = obj->size_hints->max.h;
return EINA_SIZE2D(-1, -1);
return obj->size_hints->max;
}
EOLIAN static void
_efl_canvas_object_efl_gfx_size_hint_hint_max_set(Eo *eo_obj, Evas_Object_Protected_Data *obj, Evas_Coord w, Evas_Coord h)
_efl_canvas_object_efl_gfx_size_hint_hint_max_set(Eo *eo_obj, Evas_Object_Protected_Data *obj, Eina_Size2D sz)
{
if (obj->delete_me)
return;
evas_object_async_block(obj);
if (EINA_UNLIKELY(!obj->size_hints))
{
if ((w == -1) && (h == -1)) return;
if ((sz.w == -1) && (sz.h == -1)) return;
_evas_object_size_hint_alloc(eo_obj, obj);
}
if ((obj->size_hints->max.w == w) && (obj->size_hints->max.h == h)) return;
obj->size_hints->max.w = w;
obj->size_hints->max.h = h;
if ((obj->size_hints->max.w == sz.w) && (obj->size_hints->max.h == sz.h)) return;
obj->size_hints->max.w = sz.w;
obj->size_hints->max.h = sz.h;
evas_object_inform_call_changed_size_hints(eo_obj);
}
@ -2051,8 +2048,8 @@ _efl_canvas_object_efl_object_dbg_info_get(Eo *eo_obj, Evas_Object_Protected_Dat
int r, g, b, a;
//int requestw, requesth;
int minw, minh;
int maxw, maxh;
Eina_Rect geom;
Eina_Size2D max;
short layer;
Eina_Bool focus;
Eina_Bool visible;
@ -2067,7 +2064,7 @@ _efl_canvas_object_efl_object_dbg_info_get(Eo *eo_obj, Evas_Object_Protected_Dat
geom = efl_gfx_geometry_get(eo_obj);
scale = efl_canvas_object_scale_get(eo_obj);
efl_gfx_size_hint_restricted_min_get(eo_obj, &minw, &minh);
efl_gfx_size_hint_max_get(eo_obj, &maxw, &maxh);
max = efl_gfx_size_hint_max_get(eo_obj);
//efl_gfx_size_hint_request_get(eo_obj, &requestw, &requesth);
efl_gfx_size_hint_align_get(eo_obj, &dblx, &dbly);
efl_gfx_size_hint_weight_get(eo_obj, &dblw, &dblh);
@ -2101,8 +2098,8 @@ _efl_canvas_object_efl_object_dbg_info_get(Eo *eo_obj, Evas_Object_Protected_Dat
EFL_DBG_INFO_APPEND(node, "h", EINA_VALUE_TYPE_INT, minh);
node = EFL_DBG_INFO_LIST_APPEND(group, "Max size");
EFL_DBG_INFO_APPEND(node, "w", EINA_VALUE_TYPE_INT, maxw);
EFL_DBG_INFO_APPEND(node, "h", EINA_VALUE_TYPE_INT, maxh);
EFL_DBG_INFO_APPEND(node, "w", EINA_VALUE_TYPE_INT, max.w);
EFL_DBG_INFO_APPEND(node, "h", EINA_VALUE_TYPE_INT, max.h);
//node = EFL_DBG_INFO_LIST_APPEND(group, "Request size");
//EFL_DBG_INFO_APPEND(node, "w", EINA_VALUE_TYPE_INT, requestw);
@ -2569,13 +2566,16 @@ evas_object_size_hint_aspect_get(const Evas_Object *obj, Evas_Aspect_Control *as
EAPI void
evas_object_size_hint_max_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
{
efl_gfx_size_hint_max_set(obj, w, h);
efl_gfx_size_hint_max_set(obj, EINA_SIZE2D(w, h));
}
EAPI void
evas_object_size_hint_max_get(const Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
{
efl_gfx_size_hint_max_get(obj, w, h);
Eina_Size2D sz;
sz = efl_gfx_size_hint_max_get(obj);
if (w) *w = sz.w;
if (h) *h = sz.h;
}
EAPI void

View File

@ -1019,7 +1019,8 @@ struct _Evas_Double_Pair
struct _Evas_Size_Hints
{
Evas_Size min, max, user_min, request;
Evas_Size min, user_min, request;
Eina_Size2D max;
Evas_Aspect aspect;
Evas_Double_Pair align, weight;
Evas_Border padding;