add spacer gadgets for bryces

this is a rectangle which dynamically resizes based on the available space
in the bar. it can only be added when autosize is disabled, and setting
autosize will remove all spacers

fix T5914
This commit is contained in:
Mike Blumenkrantz 2017-08-25 14:47:05 -04:00
parent 2e0638e87a
commit 175c614838
2 changed files with 134 additions and 27 deletions

View File

@ -16,6 +16,7 @@ typedef struct Bryce
Evas_Object *scroller;
Evas_Object *autohide_event;
Eina_List *zone_obstacles;
Eina_List *spacers;
Evas_Object *parent; //comp_object is not an elm widget
Eina_Stringshare *style;
@ -47,6 +48,7 @@ typedef struct Bryce
Eina_Bool mouse_in : 1;
Eina_Bool noshadow : 1;
Eina_Bool size_changed : 1;
Eina_Bool editing : 1;
} Bryce;
typedef struct Bryces
@ -731,6 +733,7 @@ _bryce_gadgets_menu_close(void *data, Evas_Object *obj)
Bryce *b = data;
b->autohide_blocked--;
b->editing = 0;
evas_object_layer_set(b->bryce, b->layer);
evas_object_hide(obj);
evas_object_del(obj);
@ -745,6 +748,7 @@ _bryce_gadgets_menu(void *data, E_Menu *m EINA_UNUSED, E_Menu_Item *mi EINA_UNUS
Evas_Object *comp_object;
b->autohide_blocked++;
b->editing = 1;
comp_object = e_gadget_site_edit(b->site);
evas_object_layer_set(b->bryce, E_LAYER_POPUP);
e_comp_object_util_autoclose(comp_object, _bryce_gadgets_menu_close, e_comp_object_util_autoclose_on_escape, b);
@ -1132,7 +1136,11 @@ e_bryce_autosize_set(Evas_Object *bryce, Eina_Bool set)
if (b->autosize == set) return;
b->autosize = set;
if (set)
{
while (b->spacers)
e_gadget_del(eina_list_data_get(b->spacers));
}
e_config_save_queue();
_bryce_autosize(b);
}
@ -1287,6 +1295,46 @@ e_bryce_save(void)
e_config_domain_save("e_bryces", edd_bryces, bryces);
}
static void
bryce_spacer_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
Bryce *b = data;
b->spacers = eina_list_remove(b->spacers, obj);
}
static Evas_Object *
bryce_spacer_create(Evas_Object *parent, int *id, E_Gadget_Site_Orient orient)
{
Bryce *b;
Eina_List *l;
Evas_Object *r;
if (!orient) return NULL;
/* only allow on bryces */
EINA_LIST_FOREACH(bryces->bryces, l, b)
{
if (b->editing || (parent == b->site)) break;
}
if (!b) return NULL;
if (b->autosize) return NULL;
r = evas_object_rectangle_add(e_comp->evas);
evas_object_event_callback_add(r, EVAS_CALLBACK_DEL, bryce_spacer_del, b);
b->spacers = eina_list_append(b->spacers, r);
E_EXPAND(r);
E_FILL(r);
/* FIXME: this should be better for demo gadgets... */
if (*id < 0)
{
evas_object_size_hint_aspect_set(r, EVAS_ASPECT_CONTROL_BOTH, 1, 1);
evas_object_color_set(r, 255, 0, 0, 255);
}
else
evas_object_color_set(r, 0, 0, 0, 0);
return r;
}
EINTERN void
e_bryce_init(void)
{
@ -1346,6 +1394,7 @@ e_bryce_init(void)
evas_object_event_callback_add(e_comp->canvas->resize_object, EVAS_CALLBACK_RESIZE, _bryce_comp_resize, NULL);
E_LIST_HANDLER_APPEND(handlers, E_EVENT_ZONE_USEFUL_GEOMETRY_CHANGED, _bryce_zone_useful_geometry_changed, NULL);
e_gadget_type_add("Spacer Bar", bryce_spacer_create, NULL);
}
EINTERN void
@ -1388,4 +1437,5 @@ e_bryce_shutdown(void)
}
E_FREE_LIST(handlers, ecore_event_handler_del);
E_FREE(bryces);
e_gadget_type_del("Spacer Bar");
}

View File

@ -593,13 +593,15 @@ _site_gadget_aspect(E_Gadget_Config *zgc, Evas_Coord *ww, Evas_Coord *hh, int ax
}
}
static void
static Eina_Bool
_site_gadget_resize(Evas_Object *g, int w, int h, Evas_Coord *ww, Evas_Coord *hh, Evas_Coord *ow, Evas_Coord *oh)
{
Evas_Coord mnw, mnh, mxw, mxh;
E_Gadget_Config *zgc;
Evas_Aspect_Control aspect;
int ax, ay;
double ex, ey;
Eina_Bool ret = EINA_FALSE;
zgc = evas_object_data_get(g, "__e_gadget");
w -= zgc->style.minw;
@ -608,16 +610,19 @@ _site_gadget_resize(Evas_Object *g, int w, int h, Evas_Coord *ww, Evas_Coord *hh
evas_object_size_hint_min_get(g, &mnw, &mnh);
evas_object_size_hint_max_get(g, &mxw, &mxh);
evas_object_size_hint_aspect_get(g, &aspect, &ax, &ay);
evas_object_size_hint_weight_get(g, &ex, &ey);
if (IS_HORIZ(zgc->site->orient))
{
*ww = mnw, *hh = h;
if (!(*ww)) *ww = *hh;
if (dblequal(ex, EVAS_HINT_EXPAND) && (!aspect)) ret = EINA_TRUE;
}
else if (IS_VERT(zgc->site->orient))
{
*hh = mnh, *ww = w;
if (!(*hh)) *hh = *ww;
if (dblequal(ey, EVAS_HINT_EXPAND) && (!aspect)) ret = EINA_TRUE;
}
else
{
@ -646,6 +651,7 @@ _site_gadget_resize(Evas_Object *g, int w, int h, Evas_Coord *ww, Evas_Coord *hh
}
//fprintf(stderr, "%s: %dx%d\n", zgc->type, *ow, *oh);
evas_object_resize(zgc->display, *ow, *oh);
return ret;
}
static void
@ -668,10 +674,21 @@ _site_layout_orient(Evas_Object *o, E_Gadget_Site *zgs)
Eina_List *l;
double ax, ay;
E_Gadget_Config *zgc;
int mw, mh, sw, sh;
int mw, mh, sw, sh, rw, rh, bw, bh;
int expand_count;
struct Size
{
Evas_Coord_Size size;
Evas_Coord_Size clipped;
Eina_Bool expand;
Evas_Object *obj;
} *size;
Eina_List *expand = NULL, *gadgets = NULL;
evas_object_geometry_get(o, &x, &y, &w, &h);
if ((!w) && (!h)) return;
evas_object_geometry_get(elm_object_parent_widget_get(zgs->layout), NULL, NULL, &bw, &bh);
rw = bw, rh = bh;
evas_object_size_hint_min_get(o, &mw, &mh);
evas_object_size_hint_min_get(zgs->layout, &sw, &sh);
evas_object_geometry_set(zgs->events, x, y, w, h);
@ -681,27 +698,70 @@ _site_layout_orient(Evas_Object *o, E_Gadget_Site *zgs)
xx = x;
yy = y;
EINA_LIST_FOREACH(zgs->gadgets, l, zgc)
{
int ww, hh, ow, oh;
Eina_Bool ex;
if (!zgc->display) continue;
ex = _site_gadget_resize(zgc->gadget, w, h, &ww, &hh, &ow, &oh);
size = E_NEW(struct Size, 1);
size->size.w = ww;
size->size.h = hh;
size->clipped.w = ow;
size->clipped.h = oh;
size->expand = ex;
size->obj = zgc->display;
gadgets = eina_list_append(gadgets, size);
if (ex)
{
expand = eina_list_append(expand, size);
continue;
}
if (IS_HORIZ(zgs->orient))
rw = MAX(rw - ow, 0);
else if (IS_VERT(zgs->orient))
rh = MAX(rh - oh, 0);
}
expand_count = eina_list_count(expand);
EINA_LIST_FREE(expand, size)
{
if (IS_HORIZ(zgs->orient))
{
if (rw)
size->size.w = size->clipped.w = rw / expand_count;
else
size->size.w = size->clipped.w = 0;
}
else if (IS_VERT(zgs->orient))
{
if (rh)
size->size.h = size->clipped.h = rh / expand_count;
else
size->size.h = size->clipped.h = 0;
}
evas_object_resize(size->obj, size->clipped.w, size->clipped.h);
}
if (zgs->gravity % 2)//left/top
{
EINA_LIST_FOREACH(zgs->gadgets, l, zgc)
EINA_LIST_FREE(gadgets, size)
{
Evas_Coord gx = xx, gy = yy;
int ww, hh, ow, oh;
if (!zgc->display) continue;
_site_gadget_resize(zgc->gadget, w, h, &ww, &hh, &ow, &oh);
if (IS_HORIZ(zgs->orient))
gx += (Evas_Coord)(((double)(ww - ow)) * 0.5),
gy += (h / 2) - (oh / 2);
gx += (Evas_Coord)(((double)(size->size.w - size->clipped.w)) * 0.5),
gy += (h / 2) - (size->clipped.h / 2);
else if (IS_VERT(zgs->orient))
gy += (Evas_Coord)(((double)(hh - oh)) * 0.5),
gx += (w / 2) - (ow / 2);
evas_object_move(zgc->display, gx, gy);
gy += (Evas_Coord)(((double)(size->size.h - size->clipped.h)) * 0.5),
gx += (w / 2) - (size->clipped.w / 2);
evas_object_move(size->obj, gx, gy);
if (IS_HORIZ(zgs->orient))
xx += ow;
xx += size->clipped.w;
else
yy += oh;
yy += size->clipped.h;
free(size);
}
}
else if (zgs->gravity)
@ -711,25 +771,22 @@ _site_layout_orient(Evas_Object *o, E_Gadget_Site *zgs)
else
yy += h;
EINA_LIST_REVERSE_FOREACH(zgs->gadgets, l, zgc)
E_LIST_REVERSE_FREE(gadgets, size)
{
Evas_Coord gx = xx, gy = yy;
int ww, hh, ow, oh;
if (!zgc->display) continue;
_site_gadget_resize(zgc->gadget, w, h, &ww, &hh, &ow, &oh);
if (IS_HORIZ(zgs->orient))
gx -= (Evas_Coord)(((double)(ww - ow)) * 0.5) + ow,
gy += (h / 2) - (oh / 2);
gx -= (Evas_Coord)(((double)(size->size.w - size->clipped.w)) * 0.5) + size->clipped.w,
gy += (h / 2) - (size->clipped.h / 2);
else
gy -= (Evas_Coord)(((double)(hh - oh)) * 0.5) + oh,
gx += (w / 2) - (ow / 2);
evas_object_move(zgc->display, gx, gy);
gy -= (Evas_Coord)(((double)(size->size.h - size->clipped.h)) * 0.5) + size->clipped.h,
gx += (w / 2) - (size->clipped.w / 2);
evas_object_move(size->obj, gx, gy);
if (IS_HORIZ(zgs->orient))
xx -= ow;
xx -= size->clipped.w;
else
yy -= oh;
yy -= size->clipped.h;
free(size);
}
}