mothra: plpack in any case, even if labels dont fit

front
cinap_lenrek 2012-04-14 14:54:45 +02:00
parent 34918e7081
commit 9509b5850b
3 changed files with 15 additions and 28 deletions

View File

@ -66,24 +66,18 @@ Point pl_getshare(Panel *p){
} }
/* /*
* Set the sizes and rectangles of p and its descendants, given their requested sizes. * Set the sizes and rectangles of p and its descendants, given their requested sizes.
* Returns 1 if everything fit, 0 otherwise.
* For now we punt in the case that the children don't all fit.
* Possibly we should shrink all the children's sizereqs to fit,
* by the same means used to do EXPAND, except clamping at some minimum size,
* but that smacks of AI.
*/ */
Panel *pl_toosmall; void pl_setrect(Panel *p, Point ul, Point avail){
int pl_setrect(Panel *p, Point ul, Point avail){
Point space, newul, newspace, slack, share; Point space, newul, newspace, slack, share;
int l; int l;
Panel *c; Panel *c;
p->size=subpt(p->sizereq, p->pad); p->size=subpt(p->sizereq, p->pad);
ul=addpt(ul, divpt(p->pad, 2)); ul=addpt(ul, divpt(p->pad, 2));
avail=subpt(avail, p->pad); avail=subpt(avail, p->pad);
if(p->size.x>avail.x || p->size.y>avail.y){ if(p->size.x>avail.x)
pl_toosmall=p; p->size.x = avail.x;
return 0; /* not enough space! */ if(p->size.y>avail.y)
} p->size.y = avail.y;
if(p->flags&(FILLX|EXPAND)) p->size.x=avail.x; if(p->flags&(FILLX|EXPAND)) p->size.x=avail.x;
if(p->flags&(FILLY|EXPAND)) p->size.y=avail.y; if(p->flags&(FILLY|EXPAND)) p->size.y=avail.y;
switch(p->flags&PLACE){ switch(p->flags&PLACE){
@ -127,34 +121,33 @@ int pl_setrect(Panel *p, Point ul, Point avail){
case PACKN: case PACKN:
newul=Pt(ul.x, ul.y+c->sizereq.y); newul=Pt(ul.x, ul.y+c->sizereq.y);
newspace=Pt(space.x, space.y-c->sizereq.y); newspace=Pt(space.x, space.y-c->sizereq.y);
if(!pl_setrect(c, ul, Pt(space.x, c->sizereq.y))) return 0; pl_setrect(c, ul, Pt(space.x, c->sizereq.y));
break; break;
case PACKW: case PACKW:
newul=Pt(ul.x+c->sizereq.x, ul.y); newul=Pt(ul.x+c->sizereq.x, ul.y);
newspace=Pt(space.x-c->sizereq.x, space.y); newspace=Pt(space.x-c->sizereq.x, space.y);
if(!pl_setrect(c, ul, Pt(c->sizereq.x, space.y))) return 0; pl_setrect(c, ul, Pt(c->sizereq.x, space.y));
break; break;
case PACKS: case PACKS:
newul=ul; newul=ul;
newspace=Pt(space.x, space.y-c->sizereq.y); newspace=Pt(space.x, space.y-c->sizereq.y);
if(!pl_setrect(c, Pt(ul.x, ul.y+space.y-c->sizereq.y), pl_setrect(c, Pt(ul.x, ul.y+space.y-c->sizereq.y),
Pt(space.x, c->sizereq.y))) return 0; Pt(space.x, c->sizereq.y));
break; break;
case PACKE: case PACKE:
newul=ul; newul=ul;
newspace=Pt(space.x-c->sizereq.x, space.y); newspace=Pt(space.x-c->sizereq.x, space.y);
if(!pl_setrect(c, Pt(ul.x+space.x-c->sizereq.x, ul.y), pl_setrect(c, Pt(ul.x+space.x-c->sizereq.x, ul.y),
Pt(c->sizereq.x, space.y))) return 0; Pt(c->sizereq.x, space.y));
break; break;
} }
ul=newul; ul=newul;
space=newspace; space=newspace;
} }
return 1;
} }
int plpack(Panel *p, Rectangle where){ void plpack(Panel *p, Rectangle where){
pl_sizereq(p); pl_sizereq(p);
return pl_setrect(p, where.min, subpt(where.max, where.min)); pl_setrect(p, where.min, subpt(where.max, where.min));
} }
/* /*
* move an already-packed panel so that p->r=raddp(p->r, d) * move an already-packed panel so that p->r=raddp(p->r, d)

View File

@ -98,7 +98,7 @@ struct Panel{
#define PRI_POPUP 1 /* popup menus */ #define PRI_POPUP 1 /* popup menus */
#define PRI_SCROLLBAR 2 /* scroll bars */ #define PRI_SCROLLBAR 2 /* scroll bars */
int plinit(int); /* initialization */ int plinit(int); /* initialization */
int plpack(Panel *, Rectangle); /* figure out where to put the Panel & children */ void plpack(Panel *, Rectangle); /* figure out where to put the Panel & children */
void plmove(Panel *, Point); /* move an already-packed panel to a new location */ void plmove(Panel *, Point); /* move an already-packed panel to a new location */
void pldraw(Panel *, Image *); /* display the panel on the bitmap */ void pldraw(Panel *, Image *); /* display the panel on the bitmap */
void plfree(Panel *); /* give back space */ void plfree(Panel *); /* give back space */

View File

@ -174,7 +174,7 @@ void mkpanels(void){
plscroll(list, 0, bar); plscroll(list, 0, bar);
p=plgroup(root, PACKN|FILLX); p=plgroup(root, PACKN|FILLX);
pllabel(p, PACKW, "Title:"); pllabel(p, PACKW, "Title:");
curttl=pllabel(p, PACKE|EXPAND, "Initializing"); curttl=pllabel(p, PACKE|EXPAND, "---");
plplacelabel(curttl, PLACEW); plplacelabel(curttl, PLACEW);
p=plgroup(root, PACKN|FILLX); p=plgroup(root, PACKN|FILLX);
pllabel(p, PACKW, "Url:"); pllabel(p, PACKW, "Url:");
@ -445,14 +445,8 @@ void eresized(int new){
exits("getwindow"); exits("getwindow");
} }
r=screen->r; r=screen->r;
plinitlabel(curttl, PACKE|EXPAND, "---");
plinitlabel(cururl, PACKE|EXPAND, "---");
plpack(root, r); plpack(root, r);
plpack(alt, r); plpack(alt, r);
if(current){
plinitlabel(curttl, PACKE|EXPAND, current->title);
plinitlabel(cururl, PACKE|EXPAND, current->url->fullname);
}
draw(screen, r, display->white, 0, ZP); draw(screen, r, display->white, 0, ZP);
pldraw(root, screen); pldraw(root, screen);
unlockdisplay(display); unlockdisplay(display);