diff --git a/legacy/edje/data/src/test.edc b/legacy/edje/data/src/test.edc index 46bb0d329a..0a2e1be9c5 100644 --- a/legacy/edje/data/src/test.edc +++ b/legacy/edje/data/src/test.edc @@ -90,6 +90,9 @@ collections // max: 0 0; // step: 1 1; // aspect: 0.0 999999.0; +// can be NONE VERTICAL and HORIZONTAL - depending which axis (if any) is used +// as a master control on aspect calculations +// aspect_preference: NONE; rel1 { relative: 0.0 0.0; diff --git a/legacy/edje/src/bin/edje_cc_handlers.c b/legacy/edje/src/bin/edje_cc_handlers.c index 2e2fad54f1..08ccf6b721 100644 --- a/legacy/edje/src/bin/edje_cc_handlers.c +++ b/legacy/edje/src/bin/edje_cc_handlers.c @@ -38,6 +38,7 @@ static void st_collections_group_parts_part_description_min(void); static void st_collections_group_parts_part_description_max(void); static void st_collections_group_parts_part_description_step(void); static void st_collections_group_parts_part_description_aspect(void); +static void st_collections_group_parts_part_description_aspect_preference(void); static void st_collections_group_parts_part_description_rel1_relative(void); static void st_collections_group_parts_part_description_rel1_offset(void); static void st_collections_group_parts_part_description_rel1_to(void); @@ -109,6 +110,7 @@ New_Statement_Handler statement_handlers[] = {"collections.group.parts.part.description.max", st_collections_group_parts_part_description_max}, {"collections.group.parts.part.description.step", st_collections_group_parts_part_description_step}, {"collections.group.parts.part.description.aspect", st_collections_group_parts_part_description_aspect}, + {"collections.group.parts.part.description.aspect_preference", st_collections_group_parts_part_description_aspect_preference}, {"collections.group.parts.part.description.rel1.relative", st_collections_group_parts_part_description_rel1_relative}, {"collections.group.parts.part.description.rel1.offset", st_collections_group_parts_part_description_rel1_offset}, {"collections.group.parts.part.description.rel1.to", st_collections_group_parts_part_description_rel1_to}, @@ -184,6 +186,7 @@ New_Object_Handler object_handlers[] = {"collections.group.parts.part.description.max", NULL}, {"collections.group.parts.part.description.step", NULL}, {"collections.group.parts.part.description.aspect", NULL}, + {"collections.group.parts.part.description.aspect_preference", NULL}, {"collections.group.parts.part.description.rel1", NULL}, {"collections.group.parts.part.description.rel1.relative", NULL}, {"collections.group.parts.part.description.rel1.offset", NULL}, @@ -715,6 +718,24 @@ st_collections_group_parts_part_description_aspect(void) ed->aspect.max = parse_float_range(1, 0.0, 999999999.0); } +static void +st_collections_group_parts_part_description_aspect_preference(void) +{ + Edje_Part_Collection *pc; + Edje_Part *ep; + Edje_Part_Description *ed; + + pc = evas_list_data(evas_list_last(edje_collections)); + ep = evas_list_data(evas_list_last(pc->parts)); + ed = ep->default_desc; + if (ep->other_desc) ed = evas_list_data(evas_list_last(ep->other_desc)); + ed->aspect.prefer = parse_enum(0, + "NONE", EDJE_ASPECT_PREFER_NONE, + "VERTICAL", EDJE_ASPECT_PREFER_VERTICAL, + "HORIZONTAL", EDJE_ASPECT_PREFER_HORIZONTAL, + NULL); +} + static void st_collections_group_parts_part_description_rel1_relative(void) { diff --git a/legacy/edje/src/lib/Edje_Edit.h b/legacy/edje/src/lib/Edje_Edit.h index 3f51916f57..75da7d6c31 100644 --- a/legacy/edje/src/lib/Edje_Edit.h +++ b/legacy/edje/src/lib/Edje_Edit.h @@ -128,6 +128,10 @@ Edje_Edit_Image *edje_edit_iamge_get_by_id(int id); #define EDJE_VAR_FLOAT 2 #define EDJE_VAR_STRING 3 +#define EDJE_ASPECT_PREFER_NONE 0 +#define EDJE_ASPECT_PREFER_VERTICAL 1 +#define EDJE_ASPECT_PREFER_HORIZONTAL 2 + #define EDJE_VAR_MAGIC_BASE 0x12fe84ba /*----------*/ @@ -304,6 +308,7 @@ struct _Edje_Part_Description struct { double min, max; /* aspect = w/h */ + unsigned char prefer; /* NEITHER = 0, VERTICAL = 1, HORIZONTAL = 2 */ } aspect; struct { diff --git a/legacy/edje/src/lib/edje_calc.c b/legacy/edje/src/lib/edje_calc.c index b299323ea1..794f692890 100644 --- a/legacy/edje/src/lib/edje_calc.c +++ b/legacy/edje/src/lib/edje_calc.c @@ -316,6 +316,7 @@ _edje_part_recalc_single(Edje *ed, params->y + 1; /* aspect */ +#if 0 if (params->h > 0) { double aspect; @@ -368,7 +369,122 @@ _edje_part_recalc_single(Edje *ed, } } } - +#else + if (params->h > 0) + { + double aspect; + double new_w, new_h; + + new_h = params->h; + new_w = params->w; + aspect = (double)params->w / (double)params->h; + if (desc->aspect.prefer == EDJE_ASPECT_PREFER_NONE) /* keep both dimensions in check */ + { + /* adjust for max aspect (width / height) */ + if ((desc->aspect.max > 0.0) && (aspect > desc->aspect.max)) + { + new_h = (params->w / desc->aspect.max); + new_w = (params->h * desc->aspect.max); + } + printf("[a] %s [%3.3f -> %3.3f] (%ix%i) -> (%3.3fx%3.3f)\n", + ep->part->name, + desc->aspect.min, desc->aspect.max, + params->w, params->h, + new_w, new_h); + /* adjust for min aspect (width / height) */ + if ((desc->aspect.min > 0.0) && (aspect < desc->aspect.min)) + { + new_h = (params->w / desc->aspect.min); + new_w = (params->h * desc->aspect.min); + } + printf(" [b] %s [%3.3f -> %3.3f] (%ix%i) -> (%3.3fx%3.3f)\n", + ep->part->name, + desc->aspect.min, desc->aspect.max, + params->w, params->h, + new_w, new_h); + } /* prefer vertical size as determiner */ + else if (desc->aspect.prefer == EDJE_ASPECT_PREFER_VERTICAL) /* keep both dimensions in check */ + { + /* adjust for max aspect (width / height) */ + if ((desc->aspect.max > 0.0) && (aspect > desc->aspect.max)) + { + new_w = (params->h * desc->aspect.max); + } + printf("[a] %s [%3.3f -> %3.3f] (%ix%i) -> (%3.3fx%3.3f)\n", + ep->part->name, + desc->aspect.min, desc->aspect.max, + params->w, params->h, + new_w, new_h); + /* adjust for min aspect (width / height) */ + if ((desc->aspect.min > 0.0) && (aspect < desc->aspect.min)) + { + new_w = (params->h * desc->aspect.min); + } + printf(" [b] %s [%3.3f -> %3.3f] (%ix%i) -> (%3.3fx%3.3f)\n", + ep->part->name, + desc->aspect.min, desc->aspect.max, + params->w, params->h, + new_w, new_h); + } /* prefer horizontal size as determiner */ + else if (desc->aspect.prefer == EDJE_ASPECT_PREFER_HORIZONTAL) /* keep both dimensions in check */ + { + /* adjust for max aspect (width / height) */ + if ((desc->aspect.max > 0.0) && (aspect > desc->aspect.max)) + { + new_h = (params->w / desc->aspect.max); + } + printf("[a] %s [%3.3f -> %3.3f] (%ix%i) -> (%3.3fx%3.3f)\n", + ep->part->name, + desc->aspect.min, desc->aspect.max, + params->w, params->h, + new_w, new_h); + /* adjust for min aspect (width / height) */ + if ((desc->aspect.min > 0.0) && (aspect < desc->aspect.min)) + { + new_h = (params->w / desc->aspect.min); + } + printf(" [b] %s [%3.3f -> %3.3f] (%ix%i) -> (%3.3fx%3.3f)\n", + ep->part->name, + desc->aspect.min, desc->aspect.max, + params->w, params->h, + new_w, new_h); + } + /* do real adjustment */ + if ((params->h - new_h) > (params->w - new_w)) + { + if (params->h < new_h) + { + params->y = params->y + + ((params->h - new_h) * (1.0 - desc->align.y)); + params->h = new_h; + } + else if (params->h > new_h) + { + params->y = params->y + + ((params->h - new_h) * desc->align.y); + params->h = new_h; + } + params->w = new_w; + } + else + { + if (params->w < new_w) + { + params->x = params->x + + ((params->w - new_w) * (1.0 - desc->align.x)); + params->w = new_w; + } + else if (params->w > new_w) + { + params->x = params->x + + ((params->w - new_w) * desc->align.x); + params->w = new_w; + } + params->h = new_h; + } + } +#endif + /* size step */ if (desc->step.x > 0) { diff --git a/legacy/edje/src/lib/edje_data.c b/legacy/edje/src/lib/edje_data.c index 8898255806..ee192e11a8 100644 --- a/legacy/edje/src/lib/edje_data.c +++ b/legacy/edje/src/lib/edje_data.c @@ -146,6 +146,7 @@ _edje_edd_setup(void) EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "step.y", step.y, EET_T_INT); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "aspect.min", aspect.min, EET_T_DOUBLE); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "aspect.max", aspect.max, EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "aspect.prefer", aspect.prefer, EET_T_CHAR); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "rel1.relative_x", rel1.relative_x, EET_T_DOUBLE); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "rel1.relative_y", rel1.relative_y, EET_T_DOUBLE); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "rel1.offset_x", rel1.offset_x, EET_T_INT);