edje: Split off calc APIs to an interface (EO)

Those APIs can then be used by Elm.Layout, hopefully
simplifying the API.

I wonder if the APIs should be prefixed "calc_" (as is)
or "layout_calc_". The extra "layout_" prefix would make
it common with other layout APIs (eg. signals, data,
size min/max, ...).

Ref T5315
This commit is contained in:
Jean-Philippe Andre 2017-08-01 18:15:34 +09:00
parent 796d4b138b
commit 6df17b2ed0
11 changed files with 356 additions and 141 deletions

View File

@ -2,6 +2,7 @@
### Library
edje_eolian_files = \
lib/edje/efl_canvas_layout_calc.eo \
lib/edje/edje_object.eo \
lib/edje/efl_canvas_layout_internal.eo \
lib/edje/efl_canvas_layout_internal_box.eo \

View File

@ -1,5 +1,6 @@
#include <Efl.h>
#include "efl_canvas_layout_calc.eo.h"
#include "edje_object.eo.h"
#include "edje_edit.eo.h"

View File

@ -213,6 +213,155 @@ EAPI const char *edje_object_part_state_get(const Edje_Object *obj, const char *
*/
EAPI const Efl_Canvas_Object *edje_object_part_object_get(const Edje_Object *obj, const char * part);
/**
* @brief Whether this object updates its size hints automatically.
*
* By default edje doesn't set size hints on itself. If this property is set to
* @c true, size hints will be updated after recalculation. Be careful, as
* recalculation may happen often, enabling this property may have a
* considerable performance impact as other widgets will be notified of the
* size hints changes.
*
* A layout recalculation can be triggered by @ref edje_object_size_min_calc(),
* @ref edje_object_size_min_restricted_calc(),
* @ref edje_object_parts_extends_calc() or even any other internal event.
*
* Enable or disable auto-update of size hints.
*
* @param[in] update Whether or not update the size hints.
*
* @ingroup Edje_Object
*/
EAPI void edje_object_update_hints_set(Edje_Object *obj, Eina_Bool update);
/**
* @brief Whether this object updates its size hints automatically.
*
* By default edje doesn't set size hints on itself. If this property is set to
* @c true, size hints will be updated after recalculation. Be careful, as
* recalculation may happen often, enabling this property may have a
* considerable performance impact as other widgets will be notified of the
* size hints changes.
*
* A layout recalculation can be triggered by @ref edje_object_size_min_calc(),
* @ref edje_object_size_min_restricted_calc(),
* @ref edje_object_parts_extends_calc() or even any other internal event.
*
* Whether this object updates its size hints automatically.
*
* @return Whether or not update the size hints.
*
* @ingroup Edje_Object
*/
EAPI Eina_Bool edje_object_update_hints_get(const Edje_Object *obj);
/**
* @brief Calculates the minimum required size for a given Edje object.
*
* This call works exactly as edje_object_size_min_restricted_calc(), with the
* last two arguments set to 0. Please refer to its documentation, then.
*
* @param[out] minw The minimum required width (return value)
* @param[out] minh The minimum required height (return value)
*
* @ingroup Edje_Object
*/
EAPI void edje_object_size_min_calc(Edje_Object *obj, int *minw, int *minh);
/**
* @brief Calculates the minimum required size for a given Edje object.
*
* This call will trigger an internal recalculation of all parts of the object,
* in order to return its minimum required dimensions for width and height. The
* user might choose to impose those minimum sizes, making the resulting
* calculation to get to values equal or larger than @c restrictedw and
* @c restrictedh, for width and height, respectively.
*
* @note At the end of this call, the object won't be automatically resized to
* the new dimensions, but just return the calculated sizes. The caller is the
* one up to change its geometry or not.
*
* @warning Be advised that invisible parts in the object will be taken into
* account in this calculation.
*
* @param[out] minw The minimum required width (return value)
* @param[out] minh The minimum required height (return value)
* @param[in] restrictedw The minimum width constraint as input, @c minw can
* not be lower than this
* @param[in] restrictedh The minimum height constraint as input, @c minh can
* not be lower than this
*
* @ingroup Edje_Object
*/
EAPI void edje_object_size_min_restricted_calc(Edje_Object *obj, int *minw, int *minh, int restrictedw, int restrictedh);
/**
* @brief Calculates the geometry of the region, relative to a given Edje
* object's area, occupied by all parts in the object.
*
* This function gets the geometry of the rectangle equal to the area required
* to group all parts in obj's group/collection. The x and y coordinates are
* relative to the top left corner of the whole obj object's area. Parts placed
* out of the group's boundaries will also be taken in account, so that x and y
* may be negative.
*
* @note On failure, this function will make all non-$null geometry pointers'
* pointed variables be set to zero.
*
* @param[out] x The parts region's X coordinate
* @param[out] y The parts region's Y coordinate
* @param[out] w The parts region's width
* @param[out] h The parts region's height
*
* @return @c true on success, @c false otherwise
*
* @ingroup Edje_Object
*/
EAPI Eina_Bool edje_object_parts_extends_calc(Edje_Object *obj, int *x, int *y, int *w, int *h);
/**
* @brief Forces a Size/Geometry calculation.
*
* Forces the object to recalculate its layout regardless of freeze/thaw.
*
* See also @ref edje_object_freeze and @ref edje_object_thaw.
*
* @ingroup Edje_Object
*/
EAPI void edje_object_calc_force(Edje_Object *obj);
/**
* @brief Freezes the Edje object.
*
* This function puts all changes on hold. Successive freezes will nest,
* requiring an equal number of thaws.
*
* See also @ref edje_object_thaw()
*
* @return The frozen state or 0 on error
*
* @ingroup Edje_Object
*/
EAPI int edje_object_freeze(Edje_Object *obj);
/**
* @brief Thaws the Edje object.
*
* This function thaws the given Edje object.
*
* @note If sucessive freezes were done, an equal number of thaws will be
* required.
*
* See also @ref edje_object_freeze()
*
* @return The frozen state or 0 if the object is not frozen or on error.
*
* @ingroup Edje_Object
*/
EAPI int edje_object_thaw(Edje_Object *obj);
/**
* @ingroup Edje_Object_Communication_Interface_Message
*

View File

@ -1009,3 +1009,53 @@ edje_object_part_text_insert(Eo *obj, const char *part, const char *text)
if (ed->text_change.func)
ed->text_change.func(ed->text_change.data, obj, part);
}
/* Calc interface APIs */
EAPI void
edje_object_update_hints_set(Edje_Object *obj, Eina_Bool update)
{
efl_canvas_layout_calc_auto_update_hints_set(obj, update);
}
EAPI Eina_Bool
edje_object_update_hints_get(const Edje_Object *obj)
{
return efl_canvas_layout_calc_auto_update_hints_get(obj);
}
EAPI void
edje_object_size_min_calc(Edje_Object *obj, int *minw, int *minh)
{
efl_canvas_layout_calc_size_min(obj, minw, minh);
}
EAPI void
edje_object_size_min_restricted_calc(Edje_Object *obj, int *minw, int *minh, int restrictedw, int restrictedh)
{
efl_canvas_layout_calc_size_min_restricted(obj, minw, minh, restrictedw, restrictedh);
}
EAPI Eina_Bool
edje_object_parts_extends_calc(Edje_Object *obj, int *x, int *y, int *w, int *h)
{
return efl_canvas_layout_calc_parts_extends(obj, x, y, w, h);
}
EAPI int
edje_object_freeze(Edje_Object *obj)
{
return efl_canvas_layout_calc_freeze(obj);
}
EAPI int
edje_object_thaw(Edje_Object *obj)
{
return efl_canvas_layout_calc_thaw(obj);
}
EAPI void
edje_object_calc_force(Edje_Object *obj)
{
efl_canvas_layout_calc_force(obj);
}

View File

@ -3,7 +3,7 @@ import edje_types;
// FIXME: This EO doc needs a direct link to the "edcref" doc
class Edje.Object (Efl.Canvas.Group.Clipped, Efl.File, Efl.Container, Efl.Part,
Efl.Observer, Efl.Ui.Base)
Efl.Observer, Efl.Ui.Base, Efl.Canvas.Layout_Calc)
{
[[Edje object class]]
legacy_prefix: edje_object;
@ -140,133 +140,6 @@ class Edje.Object (Efl.Canvas.Group.Clipped, Efl.File, Efl.Container, Efl.Part,
}
}
/* EDJE CALC APIS BEGIN ---------------------------------------------- */
@property calc_update_hints {
[[Whether this object updates its size hints automatically.
By default edje doesn't set size hints on itself. If this property
is set to $true, size hints will be updated after recalculation.
Be careful, as recalculation may happen often, enabling this
property may have a considerable performance impact as other widgets
will be notified of the size hints changes.
A layout recalculation can be triggered by @.size_min_calc(),
@.size_min_restricted_calc(), @.parts_extends_calc() or even any
other internal event.
]]
set {
[[Enable or disable auto-update of size hints.]]
legacy: edje_object_update_hints_set;
}
get {
[[Whether this object updates its size hints automatically.]]
legacy: edje_object_update_hints_get;
}
values {
update: bool(false); [[Whether or not update the size hints.]]
}
}
// FIXME: Prefix with calc_ ?
size_min_calc {
[[Calculates the minimum required size for a given Edje object.
This call works exactly as edje_object_size_min_restricted_calc(),
with the last two arguments set to 0. Please refer to its
documentation, then.
]]
// FIXME: Return a 2D size type (no @out values)
params {
@out minw: int; [[The minimum required width (return value)]]
@out minh: int; [[The minimum required height (return value)]]
}
}
// FIXME: Prefix with calc_ ?
size_min_restricted_calc {
[[Calculates the minimum required size for a given Edje object.
This call will trigger an internal recalculation of all parts of
the object, in order to return its minimum required dimensions for
width and height. The user might choose to impose those minimum
sizes, making the resulting calculation to get to values equal or
larger than $restrictedw and $restrictedh, for width and height,
respectively.
Note: At the end of this call, the object won't be automatically
resized to the new dimensions, but just return the calculated sizes.
The caller is the one up to change its geometry or not.
Warning: Be advised that invisible parts in the object will be taken
into account in this calculation.
]]
// FIXME: Return a 2D size type (no @out values)
params {
@out minw: int; [[The minimum required width (return value)]]
@out minh: int; [[The minimum required height (return value)]]
@in restrictedw: int; [[The minimum width constraint as input,
$minw can not be lower than this]]
@in restrictedh: int; [[The minimum height constraint as input,
$minh can not be lower than this]]
}
}
// FIXME: Prefix with calc_ ?
parts_extends_calc {
[[Calculates the geometry of the region, relative to a given Edje
object's area, occupied by all parts in the object.
This function gets the geometry of the rectangle equal to the area
required to group all parts in obj's group/collection. The x
and y coordinates are relative to the top left corner of the
whole obj object's area. Parts placed out of the group's
boundaries will also be taken in account, so that x and y
may be negative.
Note: On failure, this function will make all non-$null geometry
pointers' pointed variables be set to zero.
]]
return: bool; [[$true on success, $false otherwise]]
/* FIXME: Return a 2D size type (no @out values) */
params {
@out x: int; [[The parts region's X coordinate]]
@out y: int; [[The parts region's Y coordinate]]
@out w: int; [[The parts region's width]]
@out h: int; [[The parts region's height]]
}
}
calc_force {
[[Forces a Size/Geometry calculation.
Forces the object to recalculate its layout regardless of
freeze/thaw.
See also @.calc_freeze and @.calc_thaw.
]]
}
calc_freeze {
[[Freezes the Edje object.
This function puts all changes on hold. Successive freezes will
nest, requiring an equal number of thaws.
See also @.calc_thaw()
]]
return: int; [[The frozen state or 0 on error]]
legacy: edje_object_freeze;
}
calc_thaw {
[[Thaws the Edje object.
This function thaws the given Edje object.
Note: If sucessive freezes were done, an equal number of thaws will
be required.
See also @.calc_freeze()
]]
return: int; [[The frozen state or 0 if the object is not frozen or on error.]]
legacy: edje_object_thaw;
}
/* EDJE CALC APIS END ------------------------------------------------ */
/* EDJE GROUP DATA APIS BEGIN ---------------------------------------- */
@property group_size_min {
get {
@ -1180,6 +1053,13 @@ class Edje.Object (Efl.Canvas.Group.Clipped, Efl.File, Efl.Container, Efl.Part,
Efl.Canvas.Object.no_render { set; }
Efl.Canvas.Object.paragraph_direction { set; }
Efl.Canvas.Group.group_calculate;
Efl.Canvas.Layout_Calc.calc_auto_update_hints { get; set; }
Efl.Canvas.Layout_Calc.calc_size_min;
Efl.Canvas.Layout_Calc.calc_size_min_restricted;
Efl.Canvas.Layout_Calc.calc_parts_extends;
Efl.Canvas.Layout_Calc.calc_freeze;
Efl.Canvas.Layout_Calc.calc_thaw;
Efl.Canvas.Layout_Calc.calc_force;
Efl.Ui.Base.mirrored { set; get; }
Efl.Ui.Base.language { set; get; }
Efl.Ui.Base.scale { set; get; }

View File

@ -40,6 +40,7 @@
#endif
#define EFL_CANVAS_OBJECT_PROTECTED
#define EFL_CANVAS_LAYOUT_CALC_PROTECTED
#include <Eina.h>
#include <Eet.h>

View File

@ -561,3 +561,4 @@ _edje_object_efl_observer_update(Eo *obj EINA_UNUSED, Edje *ed, Efl_Object *obs,
EFL_OBJECT_OP_FUNC(efl_dbg_info_get, _edje_object_efl_object_dbg_info_get)
#include "edje_object.eo.c"
#include "efl_canvas_layout_calc.eo.c"

View File

@ -463,7 +463,7 @@ _edje_object_group_data_get(Eo *obj EINA_UNUSED, Edje *ed, const char *key)
}
EOLIAN int
_edje_object_calc_freeze(Eo *obj EINA_UNUSED, Edje *ed)
_edje_object_efl_canvas_layout_calc_calc_freeze(Eo *obj EINA_UNUSED, Edje *ed)
{
unsigned short i;
@ -481,7 +481,7 @@ _edje_object_calc_freeze(Eo *obj EINA_UNUSED, Edje *ed)
}
EOLIAN int
_edje_object_calc_thaw(Eo *obj EINA_UNUSED, Edje *ed)
_edje_object_efl_canvas_layout_calc_calc_thaw(Eo *obj EINA_UNUSED, Edje *ed)
{
unsigned short i;
@ -3143,7 +3143,7 @@ _edje_object_group_size_max_get(Eo *obj EINA_UNUSED, Edje *ed EINA_UNUSED, Evas_
}
EOLIAN void
_edje_object_calc_force(Eo *obj EINA_UNUSED, Edje *ed)
_edje_object_efl_canvas_layout_calc_calc_force(Eo *obj EINA_UNUSED, Edje *ed)
{
int pf, pf2;
@ -3166,13 +3166,13 @@ _edje_object_calc_force(Eo *obj EINA_UNUSED, Edje *ed)
}
EOLIAN void
_edje_object_size_min_calc(Eo *obj, Edje *_pd EINA_UNUSED, Evas_Coord *minw, Evas_Coord *minh)
_edje_object_efl_canvas_layout_calc_calc_size_min(Eo *obj, Edje *_pd EINA_UNUSED, Evas_Coord *minw, Evas_Coord *minh)
{
edje_object_size_min_restricted_calc(obj, minw, minh, 0, 0);
}
EOLIAN Eina_Bool
_edje_object_parts_extends_calc(Eo *obj EINA_UNUSED, Edje *ed, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
_edje_object_efl_canvas_layout_calc_calc_parts_extends(Eo *obj EINA_UNUSED, Edje *ed, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
{
Evas_Coord xx1 = INT_MAX, yy1 = INT_MAX;
Evas_Coord xx2 = 0, yy2 = 0;
@ -3223,7 +3223,7 @@ _edje_object_parts_extends_calc(Eo *obj EINA_UNUSED, Edje *ed, Evas_Coord *x, Ev
}
EOLIAN void
_edje_object_size_min_restricted_calc(Eo *obj EINA_UNUSED, Edje *ed, Evas_Coord *minw, Evas_Coord *minh, Evas_Coord restrictedw, Evas_Coord restrictedh)
_edje_object_efl_canvas_layout_calc_calc_size_min_restricted(Eo *obj EINA_UNUSED, Edje *ed, Evas_Coord *minw, Evas_Coord *minh, Evas_Coord restrictedw, Evas_Coord restrictedh)
{
const int CALC_COUNT_LIMIT = 255;
@ -4854,7 +4854,7 @@ _edje_object_preload(Eo *obj, Edje *ed, Eina_Bool cancel)
}
EOLIAN void
_edje_object_calc_update_hints_set(Eo *obj EINA_UNUSED, Edje *ed, Eina_Bool update)
_edje_object_efl_canvas_layout_calc_calc_auto_update_hints_set(Eo *obj EINA_UNUSED, Edje *ed, Eina_Bool update)
{
if (!ed) return;
if (ed->update_hints == !!update) return;
@ -4868,7 +4868,7 @@ _edje_object_calc_update_hints_set(Eo *obj EINA_UNUSED, Edje *ed, Eina_Bool upda
}
EOLIAN Eina_Bool
_edje_object_calc_update_hints_get(Eo *obj EINA_UNUSED, Edje *ed)
_edje_object_efl_canvas_layout_calc_calc_auto_update_hints_get(Eo *obj EINA_UNUSED, Edje *ed)
{
return ed->update_hints;
}

View File

@ -0,0 +1,131 @@
interface Efl.Canvas.Layout_Calc
{
[[This interface defines a common set of APIs used to trigger calculations
with layout objects.
This defines all the APIs supported by legacy "Edje" object, known in EO
API as Efl.Canvas.Layout.
@since 1.21
]]
methods {
@property calc_auto_update_hints {
[[Whether this object updates its size hints automatically.
By default edje doesn't set size hints on itself. If this property
is set to $true, size hints will be updated after recalculation.
Be careful, as recalculation may happen often, enabling this
property may have a considerable performance impact as other widgets
will be notified of the size hints changes.
A layout recalculation can be triggered by @.calc_size_min(),
@.calc_size_min_restricted(), @.calc_parts_extends() or even any
other internal event.
]]
set {
[[Enable or disable auto-update of size hints.]]
}
get {
[[Whether this object updates its size hints automatically.]]
}
values {
update: bool(false); [[Whether or not update the size hints.]]
}
}
calc_size_min {
[[Calculates the minimum required size for a given Edje object.
This call works exactly as edje_object_size_min_restricted_calc(),
with the last two arguments set to 0. Please refer to its
documentation, then.
]]
// FIXME: Return a 2D size type (no @out values)
params {
@out minw: int; [[The minimum required width (return value)]]
@out minh: int; [[The minimum required height (return value)]]
}
}
calc_size_min_restricted {
[[Calculates the minimum required size for a given layout object.
This call will trigger an internal recalculation of all parts of
the object, in order to return its minimum required dimensions for
width and height. The user might choose to impose those minimum
sizes, making the resulting calculation to get to values equal or
larger than $restrictedw and $restrictedh, for width and height,
respectively.
Note: At the end of this call, the object won't be automatically
resized to the new dimensions, but just return the calculated sizes.
The caller is the one up to change its geometry or not.
Warning: Be advised that invisible parts in the object will be taken
into account in this calculation.
]]
// FIXME: Return a 2D size type (no @out values)
params {
@out minw: int; [[The minimum required width (return value)]]
@out minh: int; [[The minimum required height (return value)]]
@in restrictedw: int @optional; [[The minimum width constraint as
input, $minw can not be lower than this]]
@in restrictedh: int @optional; [[The minimum height constraint as
input, $minh can not be lower than this]]
}
}
calc_parts_extends {
[[Calculates the geometry of the region, relative to a given layout
object's area, occupied by all parts in the object.
This function gets the geometry of the rectangle equal to the area
required to group all parts in obj's group/collection. The x
and y coordinates are relative to the top left corner of the
whole obj object's area. Parts placed out of the group's
boundaries will also be taken in account, so that x and y
may be negative.
Note: On failure, this function will make all non-$null geometry
pointers' pointed variables be set to zero.
]]
return: bool; [[$true on success, $false otherwise]]
/* FIXME: Return a 2D size type (no @out values) */
params {
@out x: int; [[The parts region's X coordinate]]
@out y: int; [[The parts region's Y coordinate]]
@out w: int; [[The parts region's width]]
@out h: int; [[The parts region's height]]
}
}
calc_freeze {
[[Freezes the layout object.
This function puts all changes on hold. Successive freezes will
nest, requiring an equal number of thaws.
See also @.calc_thaw.
]]
return: int; [[The frozen state or 0 on error]]
}
calc_thaw {
[[Thaws the layout object.
This function thaws (in other words "unfreezes") the given layout
object.
Note: If sucessive freezes were done, an equal number of thaws will
be required.
See also @.calc_freeze.
]]
return: int; [[The frozen state or 0 if the object is not frozen or on error.]]
}
calc_force @protected {
[[Forces a Size/Geometry calculation.
Forces the object to recalculate its layout regardless of
freeze/thaw. This API should be used carefully.
See also @.calc_freeze and @.calc_thaw.
]]
}
}
}

View File

@ -5,6 +5,7 @@
#define ELM_INTERFACE_ATSPI_IMAGE_PROTECTED
#define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED
#define ELM_INTERFACE_ATSPI_WIDGET_ACTION_PROTECTED
#define EFL_CANVAS_LAYOUT_CALC_PROTECTED
#include <Elementary.h>
@ -1192,14 +1193,14 @@ _efl_ui_image_edje_object_group_size_max_get(Eo *obj EINA_UNUSED, Efl_Ui_Image_D
}
EOLIAN static void
_efl_ui_image_edje_object_calc_force(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
_efl_ui_image_efl_canvas_layout_calc_calc_force(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
{
if (sd->edje)
edje_object_calc_force(sd->img);
}
EOLIAN static void
_efl_ui_image_edje_object_size_min_calc(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd, int *w, int *h)
_efl_ui_image_efl_canvas_layout_calc_calc_size_min(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd, int *w, int *h)
{
if (sd->edje)
edje_object_size_min_calc(sd->img, w, h);

View File

@ -46,7 +46,7 @@ class Efl.Ui.Image (Elm.Widget, Efl.Ui.Clickable, Efl.Ui.Draggable,
Efl.File, Efl.Image, Efl.Image.Load, Efl.Player, Efl.Gfx.View,
Elm.Interface.Atspi_Image, Elm.Interface.Atspi_Widget_Action,
Edje.Object, Efl.Orientation, Efl.Flipable,
Efl.Ui.View, Efl.Ui.Model.Connect)
Efl.Ui.View, Efl.Ui.Model.Connect, Efl.Canvas.Layout_Calc)
{
[[ Efl UI image class]]
event_prefix: efl_ui_image;
@ -138,8 +138,8 @@ class Efl.Ui.Image (Elm.Widget, Efl.Ui.Clickable, Efl.Ui.Draggable,
Edje.Object.signal_emit;
Edje.Object.group_size_min { get; }
Edje.Object.group_size_max { get; }
Edje.Object.size_min_calc;
Edje.Object.calc_force;
Efl.Canvas.Layout_Calc.calc_size_min;
Efl.Canvas.Layout_Calc.calc_force;
Efl.Canvas.Object.clip { set; }
Efl.Canvas.Group.group_member_add;
Efl.Ui.Draggable.drag_target { get; set; }