efl: Use Eina.Size2D for size hint aspect

This commit is contained in:
Jean-Philippe Andre 2017-09-18 16:44:42 +09:00
parent 6b5d155918
commit d8eea084fb
6 changed files with 49 additions and 42 deletions

View File

@ -504,7 +504,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, "Min size");
efl_gfx_size_hint_align_set(o, 0.5, 1.0);
efl_gfx_size_hint_aspect_set(o, EFL_GFX_SIZE_HINT_ASPECT_BOTH, 1, 1);
efl_gfx_size_hint_aspect_set(o, EFL_GFX_SIZE_HINT_ASPECT_BOTH, EINA_SIZE2D(1, 1));
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
@ -530,7 +530,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, "BtnA");
efl_gfx_size_hint_aspect_set(o, EFL_GFX_SIZE_HINT_ASPECT_BOTH, 1, 2);
efl_gfx_size_hint_aspect_set(o, EFL_GFX_SIZE_HINT_ASPECT_BOTH, EINA_SIZE2D(1, 2));
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);

View File

@ -59,8 +59,7 @@ interface Efl.Gfx.Size.Hint
*/
values {
mode: Efl.Gfx.Size.Hint.Aspect; [[Mode of interpretation.]]
w: int; [[Width]]
h: int; [[Height]]
sz: Eina.Size2D; [[Base size to use for aspecting.]]
/* FIXME: do we want min/max like Edje instead??
min: double; [[Default: 0.0 (no preference).]]

View File

@ -12,10 +12,9 @@ struct _Item_Calc
Evas_Object *obj;
double weight[2];
double align[2];
Eina_Size2D max, want;
Eina_Size2D max, want, aspect;
int pad[4];
Efl_Gfx_Size_Hint_Aspect aspect_type;
int aspect[2];
int id;
};
@ -79,13 +78,13 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
efl_gfx_size_hint_margin_get(o, &item->pad[0], &item->pad[1], &item->pad[2], &item->pad[3]);
item->max = efl_gfx_size_hint_max_get(o);
item->want = efl_gfx_size_hint_combined_min_get(o);
efl_gfx_size_hint_aspect_get(o, &item->aspect_type, &item->aspect[0], &item->aspect[1]);
efl_gfx_size_hint_aspect_get(o, &item->aspect_type, &item->aspect);
if (item->aspect[0] <= 0 || item->aspect[1] <= 0)
if (item->aspect.w <= 0 || item->aspect.h <= 0)
{
if (item->aspect_type >= EFL_GFX_SIZE_HINT_ASPECT_HORIZONTAL)
ERR("Invalid aspect parameter for obj: %p", item->obj);
item->aspect[0] = item->aspect[1] = 0;
item->aspect.w = item->aspect.h = 0;
item->aspect_type = EFL_GFX_SIZE_HINT_ASPECT_NONE;
}
@ -94,11 +93,11 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
double w, h;
w = item->want.w;
h = w * item->aspect[1] / item->aspect[0];
h = w * item->aspect.h / item->aspect.w;
if (h < item->want.h)
{
h = item->want.h;
w = h * item->aspect[0] / item->aspect[1];
w = h * item->aspect.w / item->aspect.h;
}
if (horiz)
@ -108,7 +107,7 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
double w1, h1;
h1 = item->max.h > 0 ? MIN(boxh, item->max.h) : boxh;
h1 = MAX(h, h1);
w1 = h1 * item->aspect[0] / item->aspect[1];
w1 = h1 * item->aspect.w / item->aspect.h;
w = item->max.w > 0 ? MIN(w1, item->max.w) : w1;
}
}
@ -119,7 +118,7 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
double w1, h1;
w1 = item->max.w > 0 ? MIN(boxw, item->max.w) : boxw;
w1 = MAX(w, w1);
h1 = w1 * item->aspect[1] / item->aspect[0];
h1 = w1 * item->aspect.h / item->aspect.w;
h = item->max.h > 0 ? MIN(h1, item->max.h) : h1;
}
}
@ -254,7 +253,7 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
h = item->want.h;
if (weight[0] > 0)
w = item->want.w + extra * item->weight[0] / weight[0];
h = w * item->aspect[1] / item->aspect[0];
h = w * item->aspect.h / item->aspect.w;
if (item->aspect_type == EFL_GFX_SIZE_HINT_ASPECT_BOTH ||
item->aspect_type == EFL_GFX_SIZE_HINT_ASPECT_VERTICAL)
@ -262,7 +261,7 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
if (h > boxh)
{
h = boxh;
w = h * item->aspect[0] / item->aspect[1];
w = h * item->aspect.w / item->aspect.h;
}
}
}
@ -272,7 +271,7 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
h = item->want.h;
if (weight[1] > 0)
h = item->want.h + extra * item->weight[1] / weight[1];
w = h * item->aspect[0] / item->aspect[1];
w = h * item->aspect.w / item->aspect.h;
if (item->aspect_type == EFL_GFX_SIZE_HINT_ASPECT_BOTH ||
item->aspect_type == EFL_GFX_SIZE_HINT_ASPECT_HORIZONTAL)
@ -280,7 +279,7 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
if (w > boxw)
{
w = boxw;
h = w * item->aspect[1] / item->aspect[0];
h = w * item->aspect.h / item->aspect.w;
}
}
}
@ -289,13 +288,13 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
{
double mar, ar;
mar = item->max.w / (double)item->max.h;
ar = item->aspect[0] / (double)item->aspect[1];
ar = item->aspect.w / (double)item->aspect.h;
if (ar < mar)
{
if (h > item->max.h)
{
h = item->max.h;
w = h * item->aspect[0] / item->aspect[1];
w = h * item->aspect.w / item->aspect.h;
}
}
else
@ -303,19 +302,19 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
if (w > item->max.w)
{
w = item->max.w;
h = w * item->aspect[1] / item->aspect[0];
h = w * item->aspect.h / item->aspect.w;
}
}
}
else if (item->max.w != INT_MAX)
{
w = MIN(w, MAX(item->want.w, item->max.w));
h = w * item->aspect[1] / item->aspect[0];
h = w * item->aspect.h / item->aspect.w;
}
else
{
h = MIN(h, MAX(item->want.h, item->max.h));
w = h * item->aspect[0] / item->aspect[1];
w = h * item->aspect.w / item->aspect.h;
}
w = w - item->pad[0] - item->pad[1];
h = h - item->pad[2] - item->pad[3];

View File

@ -5951,14 +5951,14 @@ _win_aspect_get(Efl_Ui_Win_Data *sd)
EOLIAN static void
_efl_ui_win_efl_gfx_size_hint_hint_aspect_set(Eo *obj EINA_UNUSED, Efl_Ui_Win_Data *pd,
Efl_Gfx_Size_Hint_Aspect mode, int w, int h)
Efl_Gfx_Size_Hint_Aspect mode, Eina_Size2D sz)
{
if (h) _win_aspect_set(pd, (double) w / (double) h);
if (sz.h) _win_aspect_set(pd, (double) sz.w / (double) sz.h);
else _win_aspect_set(pd, 0.0);
efl_gfx_size_hint_aspect_set(efl_super(obj, MY_CLASS), mode, w, h);
efl_gfx_size_hint_aspect_set(efl_super(obj, MY_CLASS), mode, sz);
#ifdef HAVE_ELEMENTARY_WL2
if (pd->wl.win)
ecore_wl2_window_aspect_set(pd->wl.win, w, h, mode);
ecore_wl2_window_aspect_set(pd->wl.win, sz.w, sz.h, mode);
#endif
}
@ -7957,10 +7957,12 @@ end:
EAPI void
elm_win_aspect_set(Eo *obj, double aspect)
{
Eina_Size2D sz = { 0, 0 };
if (aspect > DBL_EPSILON)
efl_gfx_size_hint_aspect_set(obj, EFL_GFX_SIZE_HINT_ASPECT_NONE, 1000 * aspect, 1000);
else
efl_gfx_size_hint_aspect_set(obj, EFL_GFX_SIZE_HINT_ASPECT_NONE, 0, 0);
sz = EINA_SIZE2D(1000 * aspect, 1000);
efl_gfx_size_hint_aspect_set(obj, EFL_GFX_SIZE_HINT_ASPECT_NONE, sz);
}
EAPI double

View File

@ -1527,35 +1527,39 @@ _efl_canvas_object_efl_gfx_size_hint_hint_min_set(Eo *eo_obj, Evas_Object_Protec
}
EOLIAN static void
_efl_canvas_object_efl_gfx_size_hint_hint_aspect_get(Eo *eo_obj EINA_UNUSED, Evas_Object_Protected_Data *obj, Efl_Gfx_Size_Hint_Aspect *aspect, Evas_Coord *w, Evas_Coord *h)
_efl_canvas_object_efl_gfx_size_hint_hint_aspect_get(Eo *eo_obj EINA_UNUSED, Evas_Object_Protected_Data *obj, Efl_Gfx_Size_Hint_Aspect *aspect, Eina_Size2D *sz)
{
if ((!obj->size_hints) || obj->delete_me)
{
if (aspect) *aspect = EVAS_ASPECT_CONTROL_NONE;
if (w) *w = 0;
if (h) *h = 0;
if (sz) *sz = EINA_SIZE2D(0, 0);
return;
}
if (aspect) *aspect = obj->size_hints->aspect.mode;
if (w) *w = obj->size_hints->aspect.size.w;
if (h) *h = obj->size_hints->aspect.size.h;
if (sz)
{
sz->w = obj->size_hints->aspect.size.w;
sz->h = obj->size_hints->aspect.size.h;
}
}
EOLIAN static void
_efl_canvas_object_efl_gfx_size_hint_hint_aspect_set(Eo *eo_obj, Evas_Object_Protected_Data *obj, Efl_Gfx_Size_Hint_Aspect aspect, Evas_Coord w, Evas_Coord h)
_efl_canvas_object_efl_gfx_size_hint_hint_aspect_set(Eo *eo_obj, Evas_Object_Protected_Data *obj, Efl_Gfx_Size_Hint_Aspect aspect, Eina_Size2D sz)
{
if (obj->delete_me)
return;
evas_object_async_block(obj);
if (EINA_UNLIKELY(!obj->size_hints))
{
if (!w && !h) return;
if (!sz.w && !sz.h) return;
_evas_object_size_hint_alloc(eo_obj, obj);
}
if ((obj->size_hints->aspect.mode == aspect) && (obj->size_hints->aspect.size.w == w) && (obj->size_hints->aspect.size.h == h)) return;
if ((obj->size_hints->aspect.mode == aspect) &&
(obj->size_hints->aspect.size.w == sz.w) &&
(obj->size_hints->aspect.size.h == sz.h)) return;
obj->size_hints->aspect.mode = aspect;
obj->size_hints->aspect.size.w = w;
obj->size_hints->aspect.size.h = h;
obj->size_hints->aspect.size = sz;
evas_object_inform_call_changed_size_hints(eo_obj);
}
@ -2544,13 +2548,16 @@ evas_object_static_clip_get(const Evas_Object *eo_obj)
EAPI void
evas_object_size_hint_aspect_set(Evas_Object *obj, Evas_Aspect_Control aspect, Evas_Coord w, Evas_Coord h)
{
efl_gfx_size_hint_aspect_set(obj, aspect, w, h);
efl_gfx_size_hint_aspect_set(obj, aspect, EINA_SIZE2D(w, h));
}
EAPI void
evas_object_size_hint_aspect_get(const Evas_Object *obj, Evas_Aspect_Control *aspect, Evas_Coord *w, Evas_Coord *h)
{
efl_gfx_size_hint_aspect_get(obj, aspect, w, h);
Eina_Size2D sz = { 0, 0 };
efl_gfx_size_hint_aspect_get(obj, aspect, &sz);
if (w) *w = sz.w;
if (h) *h = sz.h;
}
EAPI void

View File

@ -1004,7 +1004,7 @@ struct _Evas_Size
struct _Evas_Aspect
{
Evas_Aspect_Control mode;
Evas_Size size;
Eina_Size2D size;
};
struct _Evas_Border