element.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. #include <lib9.h>
  2. #include <draw.h>
  3. #include <interp.h>
  4. #include <isa.h>
  5. #include "../libinterp/runt.h"
  6. #include <drawif.h>
  7. #include <prefab.h>
  8. void icondraw(Prefab_Element*, Image*, Rectangle, int, int);
  9. void textdraw(Prefab_Element*, Image*, Rectangle, int, int);
  10. void listdraw(Prefab_Element*, Image*, Rectangle, int, int);
  11. void outlinehighlight(Prefab_Element*, Image*, Prefab_Compound*, int);
  12. void texthighlight(Prefab_Element*, Image*, Prefab_Compound*, int);
  13. void simpleclip(Prefab_Element*, Rectangle);
  14. void horizontalclip(Prefab_Element*, Rectangle);
  15. void verticalclip(Prefab_Element*, Rectangle);
  16. void textscroll(Prefab_Element*, Point, int*);
  17. void horizontalscroll(Prefab_Element*, Point, int*);
  18. void verticalscroll(Prefab_Element*, Point, int*);
  19. void iconscroll(Prefab_Element*, Point, int*);
  20. struct
  21. {
  22. void (*draw)(Prefab_Element*, Image*, Rectangle, int, int);
  23. void (*highlight)(Prefab_Element*, Image*, Prefab_Compound*, int);
  24. void (*clip)(Prefab_Element*, Rectangle);
  25. void (*scroll)(Prefab_Element*, Point, int*);
  26. }elemfn[] = {
  27. /* EIcon */ { icondraw, outlinehighlight, simpleclip, iconscroll, },
  28. /* EText */ { textdraw, texthighlight, simpleclip, textscroll, },
  29. /* ETitle */ { textdraw, outlinehighlight, simpleclip, textscroll, },
  30. /* EHorizontal */ { listdraw, outlinehighlight, horizontalclip, horizontalscroll, },
  31. /* EVertical */ { listdraw, outlinehighlight, verticalclip, verticalscroll, },
  32. /* ESeparator */ { icondraw, outlinehighlight, simpleclip, iconscroll, },
  33. };
  34. Point
  35. iconsize(Image *image)
  36. {
  37. Point dd;
  38. if(image->repl){
  39. dd.x = Dx(image->clipr);
  40. dd.y = Dy(image->clipr);
  41. }else{
  42. dd.x = Dx(image->r);
  43. dd.y = Dy(image->r);
  44. }
  45. return dd;
  46. }
  47. void
  48. icondraw(Prefab_Element *elem, Image *i, Rectangle clipr, int clean, int highlight)
  49. {
  50. Prefab_Style *style;
  51. Rectangle r;
  52. Point p;
  53. PElement *pelem;
  54. Image *image, *c;
  55. Point size;
  56. USED(highlight);
  57. pelem = lookupelement(elem);
  58. if(pelem == H)
  59. return;
  60. if(!rectclip(&clipr, i->clipr))
  61. return;
  62. R2R(r, elem->r);
  63. if(!rectclip(&clipr, r))
  64. return;
  65. if(elem->image==H || elem->mask==H || badenviron(elem->environ, 0))
  66. return;
  67. style = elem->environ->style;
  68. if(!clean){
  69. c = lookupimage(style->elemcolor);
  70. if(c != nil)
  71. draw(i, clipr, c, nil, clipr.min);
  72. }
  73. r.min = pelem->drawpt;
  74. image = lookupimage(elem->image);
  75. if(image == nil)
  76. return;
  77. size = iconsize(image);
  78. r.max.x = r.min.x+size.x;
  79. r.max.y = r.min.y+size.y;
  80. if(rectclip(&r, clipr)){
  81. p = image->r.min;
  82. p.x += r.min.x-pelem->drawpt.x;
  83. p.y += r.min.y-pelem->drawpt.y;
  84. c = lookupimage(elem->mask);
  85. if(c != nil)
  86. draw(i, r, image, c, p);
  87. }
  88. }
  89. void
  90. textdraw(Prefab_Element *elem, Image *i, Rectangle clipr, int clean, int highlight)
  91. {
  92. Prefab_Style *style;
  93. Rectangle r;
  94. PElement *pelem;
  95. Image *color, *c;
  96. Font *font;
  97. USED(highlight);
  98. pelem = lookupelement(elem);
  99. if(pelem == H)
  100. return;
  101. if(!rectclip(&clipr, i->clipr))
  102. return;
  103. R2R(r, elem->r);
  104. if(!rectclip(&clipr, r))
  105. return;
  106. if(elem->str==H || badenviron(elem->environ, 0))
  107. return;
  108. style = elem->environ->style;
  109. font = lookupfont(elem->font);
  110. if(font == nil)
  111. return;
  112. if(highlight)
  113. color = lookupimage(style->highlightcolor);
  114. else
  115. color = lookupimage(elem->image);
  116. if(!clean){
  117. c = lookupimage(style->elemcolor);
  118. if(c != nil)
  119. draw(i, clipr, c, nil, clipr.min);
  120. }
  121. if(color != nil)
  122. _string(i, pelem->drawpt, color, pelem->drawpt, font, string2c(elem->str), nil, 1<<24, clipr, nil, pelem->drawpt, SoverD);
  123. }
  124. void
  125. listdraw(Prefab_Element *elem, Image *i, Rectangle clipr, int clean, int highlight)
  126. {
  127. Prefab_Style *style;
  128. Prefab_Element *e;
  129. List *l;
  130. Rectangle r;
  131. PElement *pelem;
  132. Image *c;
  133. pelem = lookupelement(elem);
  134. if(pelem == H)
  135. return;
  136. if(!rectclip(&clipr, i->clipr))
  137. return;
  138. R2R(r, elem->r);
  139. if(!rectclip(&clipr, r))
  140. return;
  141. if(elem->kids==H || badenviron(elem->environ, 0))
  142. return;
  143. if(pelem->first != elem->kids) /* error? */
  144. return;
  145. style = elem->environ->style;
  146. if(!clean){
  147. c = lookupimage(style->elemcolor);
  148. if(c != nil)
  149. draw(i, clipr, c, nil, clipr.min);
  150. }
  151. for(l=pelem->vfirst; l!=H; l=l->tail){
  152. e = *(Prefab_Element**)l->data;
  153. R2R(r, e->r);
  154. if(rectXrect(r, clipr))
  155. drawelement(e, i, clipr, elem->environ==e->environ, highlight);
  156. if(l == pelem->vlast)
  157. break;
  158. }
  159. }
  160. void
  161. drawelement(Prefab_Element *elem, Image *i, Rectangle clipr, int clean, int highlight)
  162. {
  163. PElement *pelem;
  164. if(elem != H){
  165. pelem = lookupelement(elem);
  166. if(pelem == H)
  167. return;
  168. (*elemfn[elem->kind].draw)(elem, i, clipr, clean, highlight);
  169. if(!highlight && pelem->highlight!=H)
  170. (*elemfn[elem->kind].highlight)(elem, i, pelem->highlight, 1);
  171. }
  172. }
  173. void
  174. translateelement(Prefab_Element *elem, Point delta)
  175. {
  176. PElement *pelem;
  177. List *l;
  178. if(elem == H)
  179. return;
  180. pelem = lookupelement(elem);
  181. if(pelem == H)
  182. return;
  183. elem->r.min.x += delta.x;
  184. elem->r.min.y += delta.y;
  185. elem->r.max.x += delta.x;
  186. elem->r.max.y += delta.y;
  187. pelem->drawpt.x += delta.x;
  188. pelem->drawpt.y += delta.y;
  189. switch(elem->kind){
  190. case EHorizontal:
  191. case EVertical:
  192. if(pelem->first != elem->kids)
  193. return;
  194. for(l=elem->kids; l!=H; l=l->tail)
  195. translateelement(*(Prefab_Element**)l->data, delta);
  196. break;
  197. }
  198. }
  199. int
  200. fitrect(Rectangle *r, Rectangle sr)
  201. {
  202. if(r->max.x > sr.max.x){
  203. r->min.x -= r->max.x-sr.max.x;
  204. r->max.x = sr.max.x;
  205. }
  206. if(r->max.y > sr.max.y){
  207. r->min.y -= r->max.y-sr.max.y;
  208. r->max.y = sr.max.y;
  209. }
  210. if(r->min.x < sr.min.x){
  211. r->max.x += sr.min.x-r->min.x;
  212. r->min.x = sr.min.x;
  213. }
  214. if(r->min.y < sr.min.y){
  215. r->max.y += sr.min.y-r->min.y;
  216. r->min.y = sr.min.y;
  217. }
  218. return rectinrect(*r, sr);
  219. }
  220. void
  221. adjusthorizontal(Prefab_Element *elem, int spacing, int position)
  222. {
  223. int edx, dx, i, x;
  224. int nlist; /* BUG: should precompute */
  225. List *l;
  226. PElement *pelem;
  227. Prefab_Element *e;
  228. Point p;
  229. pelem = lookupelement(elem);
  230. if(pelem == H)
  231. return;
  232. if(pelem->first != elem->kids)
  233. return;
  234. p.y = 0;
  235. switch(spacing){
  236. default: /* shouldn't happen; protected by adjustelement */
  237. case Adjpack:
  238. x = elem->r.min.x;
  239. for(l=elem->kids; l!=H; l=l->tail){
  240. e = *(Prefab_Element**)l->data;
  241. p.x = x - e->r.min.x;
  242. translateelement(e, p);
  243. x += Dx(e->r);
  244. }
  245. elem->r.max.x = x;
  246. return;
  247. case Adjequal:
  248. dx = 0;
  249. nlist = 0;
  250. for(l=elem->kids; l!=H; l=l->tail){
  251. e = *(Prefab_Element**)l->data;
  252. if(dx < Dx(e->r))
  253. dx = Dx(e->r);
  254. nlist++;
  255. }
  256. elem->r.max.x = elem->r.min.x+nlist*dx;
  257. break;
  258. case Adjfill:
  259. nlist = 0;
  260. for(l=elem->kids; l!=H; l=l->tail)
  261. nlist++;
  262. dx = Dx(elem->r)/nlist;
  263. break;
  264. }
  265. i = 0;
  266. for(l=elem->kids; l!=H; l=l->tail){
  267. e = *(Prefab_Element**)l->data;
  268. edx = Dx(e->r);
  269. if(position == Adjleft)
  270. edx = 0;
  271. else if(position == Adjcenter)
  272. edx = (dx-edx)/2;
  273. else /* right */
  274. edx = dx-edx;
  275. p.x = (elem->r.min.x+i*dx + edx) - e->r.min.x;
  276. translateelement(e, p);
  277. i++;
  278. }
  279. }
  280. void
  281. adjustvertical(Prefab_Element *elem, int spacing, int position)
  282. {
  283. int edy, dy, i, y;
  284. int nlist; /* BUG: should precompute */
  285. List *l;
  286. PElement *pelem;
  287. Prefab_Element *e;
  288. Point p;
  289. pelem = lookupelement(elem);
  290. if(pelem == H)
  291. return;
  292. if(pelem->first != elem->kids)
  293. return;
  294. p.x = 0;
  295. switch(spacing){
  296. default: /* shouldn't happen; protected by adjustelement */
  297. case Adjpack:
  298. y = elem->r.min.y;
  299. for(l=elem->kids; l!=H; l=l->tail){
  300. e = *(Prefab_Element**)l->data;
  301. p.y = y - e->r.min.y;
  302. translateelement(e, p);
  303. y += Dy(e->r);
  304. }
  305. elem->r.max.y = y;
  306. return;
  307. case Adjequal:
  308. dy = 0;
  309. nlist = 0;
  310. for(l=elem->kids; l!=H; l=l->tail){
  311. e = *(Prefab_Element**)l->data;
  312. if(dy < Dy(e->r))
  313. dy = Dy(e->r);
  314. nlist++;
  315. }
  316. elem->r.max.y = elem->r.min.y+nlist*dy;
  317. break;
  318. case Adjfill:
  319. nlist = 0;
  320. for(l=elem->kids; l!=H; l=l->tail)
  321. nlist++;
  322. dy = Dy(elem->r)/nlist;
  323. break;
  324. }
  325. i = 0;
  326. for(l=elem->kids; l!=H; l=l->tail){
  327. e = *(Prefab_Element**)l->data;
  328. edy = Dy(e->r);
  329. if(position == Adjup)
  330. edy = 0;
  331. else if(position == Adjcenter)
  332. edy = (dy-edy)/2;
  333. else /* down */
  334. edy = dy-edy;
  335. p.y = (elem->r.min.y+i*dy + edy) - e->r.min.y;
  336. translateelement(e, p);
  337. i++;
  338. }
  339. }
  340. void
  341. adjustelement(Prefab_Element *elem, int spacing, int position)
  342. {
  343. if(lookupelement(elem) == H)
  344. return;
  345. if(spacing<Adjpack || spacing>Adjfill || position<Adjleft || position>Adjdown)
  346. return;
  347. switch(elem->kind){
  348. case EVertical:
  349. adjustvertical(elem, spacing, position);
  350. break;
  351. case EHorizontal:
  352. adjusthorizontal(elem, spacing, position);
  353. break;
  354. }
  355. }
  356. void
  357. highlightelement(Prefab_Element *elem, Image *i, Prefab_Compound *comp, int on)
  358. {
  359. PElement *pelem;
  360. pelem = lookupelement(elem);
  361. if(pelem!=H && lookupcompound(comp)!=H){
  362. if(on)
  363. pelem->highlight = comp;
  364. else
  365. pelem->highlight = H;
  366. (*elemfn[elem->kind].highlight)(elem, i, comp, on);
  367. }
  368. }
  369. static
  370. int
  371. anytextelements(Prefab_Element *e)
  372. {
  373. Prefab_Element *t;
  374. List *l;
  375. for(l=e->kids; l!=H; l=l->tail){
  376. t = *(Prefab_Element**)l->data;
  377. if(t->kind == EText)
  378. return 1;
  379. }
  380. return 0;
  381. }
  382. void
  383. textlisthighlight(Prefab_Element *e, Image *i, Prefab_Compound *c, int on)
  384. {
  385. Prefab_Element *t;
  386. List *l;
  387. for(l=e->kids; l!=H; l=l->tail){
  388. t = *(Prefab_Element**)l->data;
  389. if(t->kind == EText)
  390. texthighlight(t, i, c, on);
  391. }
  392. }
  393. void
  394. outlinehighlight(Prefab_Element *e, Image *i, Prefab_Compound *c, int on)
  395. {
  396. List *l;
  397. Prefab_Element *t;
  398. Image *color;
  399. Rectangle r, r1, r2;
  400. Point dp;
  401. int done;
  402. /* see if we can do it by highlighting just a text element */
  403. if((e->kind==EVertical || e->kind==EHorizontal) && e->kids!=H){
  404. /* is any child a text element? */
  405. if(anytextelements(e)){
  406. textlisthighlight(e, i, c, on);
  407. return;
  408. }
  409. /* grandchild? */
  410. done = 0;
  411. for(l=e->kids; l!=H; l=l->tail){
  412. t = *(Prefab_Element**)l->data;
  413. if(t->kind==EVertical || t->kind==EHorizontal)
  414. if(anytextelements(t)){
  415. textlisthighlight(t, i, c, on);
  416. done = 1;
  417. }
  418. }
  419. if(done)
  420. return;
  421. }
  422. if(on){
  423. color = lookupimage(e->environ->style->highlightcolor);
  424. if(color == nil)
  425. return;
  426. R2R(r, e->r);
  427. /* avoid outlining empty space around images */
  428. dp = ((PElement*)e)->drawpt;
  429. if(e->kind==EIcon && e->image->repl==0 && ptinrect(dp, r)){
  430. R2R(r1, e->image->r);
  431. R2R(r2, e->image->clipr);
  432. if(rectclip(&r1, r2)){
  433. dp.x += Dx(r1);
  434. dp.y += Dy(r1);
  435. if(ptinrect(dp, r))
  436. r = Rpt(((PElement*)e)->drawpt, dp);
  437. }
  438. }
  439. draw(i, r, color, nil, r.min);
  440. drawelement(e, i, insetrect(r, 2), Dirty, 1);
  441. }else{
  442. drawelement(e, i, IRECT(e->r), Dirty, 0);
  443. edge(c->environ, i, c->r, e->r);
  444. }
  445. }
  446. void
  447. texthighlight(Prefab_Element *e, Image *i, Prefab_Compound *c, int on)
  448. {
  449. drawelement(e, i, IRECT(e->r), Clean, on);
  450. edge(c->environ, i, c->r, e->r);
  451. }
  452. void
  453. clipelement(Prefab_Element *elem, Rectangle r)
  454. {
  455. if(lookupelement(elem) != H)
  456. (*elemfn[elem->kind].clip)(elem, r);
  457. }
  458. void
  459. simpleclip(Prefab_Element *elem, Rectangle r)
  460. {
  461. R2R(elem->r, r);
  462. }
  463. void
  464. horizontalclip(Prefab_Element *elem, Rectangle r)
  465. {
  466. int x;
  467. List *l;
  468. Prefab_Element *e;
  469. PElement *pelem;
  470. x = r.min.x;
  471. pelem = lookupelement(elem);
  472. if(pelem == H)
  473. return;
  474. for(l=pelem->vfirst; l!=H && x<r.max.x; l=l->tail){
  475. e = *(Prefab_Element**)l->data;
  476. x += Dx(e->r);
  477. }
  478. pelem->vlast = l;
  479. R2R(elem->r, r);
  480. }
  481. void
  482. verticalclip(Prefab_Element *elem, Rectangle r)
  483. {
  484. int y;
  485. List *l;
  486. Prefab_Element *e;
  487. PElement *pelem;
  488. y = r.min.y;
  489. pelem = lookupelement(elem);
  490. if(pelem == H)
  491. return;
  492. for(l=pelem->vfirst; l!=H && y<r.max.y; l=l->tail){
  493. e = *(Prefab_Element**)l->data;
  494. y += Dy(e->r);
  495. }
  496. pelem->vlast = l;
  497. R2R(elem->r, r);
  498. }
  499. void
  500. scrollelement(Prefab_Element *elem, Point d, int *moved)
  501. {
  502. if(lookupelement(elem) != H)
  503. (*elemfn[elem->kind].scroll)(elem, d, moved);
  504. }
  505. void
  506. textscroll(Prefab_Element *elem, Point d, int *moved)
  507. {
  508. PElement *pelem;
  509. pelem = lookupelement(elem);
  510. if(pelem==H || (d.x==0 && d.y==0))
  511. return;
  512. pelem->drawpt = subpt(pelem->drawpt, d);
  513. *moved = 1;
  514. }
  515. void
  516. iconscroll(Prefab_Element *elem, Point d, int *moved)
  517. {
  518. Point p;
  519. Image *i;
  520. PElement *pelem;
  521. pelem = lookupelement(elem);
  522. if(pelem==H || elem->image==H || (d.x==0 && d.y==0))
  523. return;
  524. i = lookupimage(elem->image);
  525. if(i == nil)
  526. return;
  527. p = subpt(pelem->drawpt, d);
  528. if(i->repl == 0){
  529. if(p.x+Dx(i->clipr) < elem->r.max.x)
  530. p.x = elem->r.max.x - Dx(i->clipr);
  531. if(p.y+Dy(i->clipr) < elem->r.max.y)
  532. p.y = elem->r.max.y - Dy(i->clipr);
  533. if(p.x > elem->r.min.x)
  534. p.x = elem->r.min.x;
  535. if(p.y > elem->r.min.y)
  536. p.y = elem->r.min.y;
  537. }
  538. *moved = !eqpt(pelem->drawpt, p);
  539. pelem->drawpt = p;
  540. }
  541. void
  542. horizontalscroll(Prefab_Element *elem, Point d, int *moved)
  543. {
  544. List *l;
  545. Prefab_Element *e;
  546. PElement *pelem;
  547. pelem = lookupelement(elem);
  548. if(pelem==H || elem->kids==H || (d.x==0 && d.y==0))
  549. return;
  550. for(l=pelem->first; l!=H; l=l->tail){
  551. e = *(Prefab_Element**)l->data;
  552. translateelement(e, d);
  553. }
  554. for(l=pelem->first; l!=H; l=l->tail){
  555. e = *(Prefab_Element**)l->data;
  556. if(e->r.max.x > elem->r.min.x)
  557. break;
  558. }
  559. pelem->vfirst = l;
  560. pelem->vlast = l;
  561. for(; l!=H; l=l->tail){
  562. e = *(Prefab_Element**)l->data;
  563. pelem->vlast = l;
  564. if(e->r.min.x >= elem->r.max.x)
  565. break;
  566. }
  567. *moved = 1;
  568. }
  569. void
  570. verticalscroll(Prefab_Element *elem, Point d, int *moved)
  571. {
  572. List *l;
  573. Prefab_Element *e;
  574. PElement *pelem;
  575. pelem = lookupelement(elem);
  576. if(pelem==H || elem->kids==H || (d.x==0 && d.y==0))
  577. return;
  578. for(l=pelem->first; l!=H; l=l->tail){
  579. e = *(Prefab_Element**)l->data;
  580. translateelement(e, d);
  581. }
  582. for(l=pelem->first; l!=H; l=l->tail){
  583. e = *(Prefab_Element**)l->data;
  584. if(e->r.max.y > elem->r.min.y)
  585. break;
  586. }
  587. pelem->vfirst = l;
  588. pelem->vlast = l;
  589. for(; l!=H; l=l->tail){
  590. e = *(Prefab_Element**)l->data;
  591. pelem->vlast = l;
  592. if(e->r.min.y >= elem->r.max.y)
  593. break;
  594. }
  595. *moved = 1;
  596. }
  597. /*
  598. * Make e visible within list. Return value is whether any change was made;
  599. * if so, must redraw (BUG: should probably do this here)
  600. */
  601. int
  602. showelement(Prefab_Element *list, Prefab_Element *e)
  603. {
  604. Point p;
  605. Prefab_Element *h, *t;
  606. PElement *plist;
  607. int moved;
  608. p.x = p.y = 0;
  609. if(list->kids == H)
  610. return 0;
  611. plist = lookupelement(list);
  612. if(plist == H)
  613. return 0;
  614. h = *(Prefab_Element**)plist->first->data;
  615. t = *(Prefab_Element**)plist->last->data;
  616. if(list->kind == EHorizontal){
  617. p.x = (list->r.min.x+Dx(list->r)/2) - e->r.min.x;
  618. if(e->r.min.x < list->r.min.x){ /* scroll to right */
  619. if(e->r.max.x+p.x > list->r.max.x)
  620. p.x = list->r.min.x-e->r.min.x;
  621. if(h->r.min.x + p.x > list->r.min.x)
  622. p.x = list->r.min.x-h->r.min.x;
  623. }else if(e->r.max.x > list->r.max.x){ /* scroll to left */
  624. if(e->r.min.x+p.x < list->r.min.x)
  625. p.x = list->r.min.x-e->r.min.x;
  626. if(t->r.max.x + p.x < list->r.max.x)
  627. p.x = list->r.max.x-t->r.max.x;
  628. }else
  629. return 0;
  630. }else if(list->kind == EVertical){
  631. p.y = (list->r.min.y+Dy(list->r)/2) - e->r.min.y;
  632. if(e->r.min.y < list->r.min.y){ /* scroll towards bottom */
  633. if(e->r.max.y+p.y > list->r.max.y)
  634. p.y = list->r.min.y-e->r.min.y;
  635. if(h->r.min.y + p.y > list->r.min.y)
  636. p.y = list->r.min.y-h->r.min.y;
  637. }else if(e->r.max.y > list->r.max.y){ /* scroll towards top */
  638. if(e->r.min.y+p.y < list->r.min.y)
  639. p.y = list->r.min.y-e->r.min.y;
  640. if(t->r.max.y + p.y < list->r.max.y)
  641. p.y = list->r.max.y-t->r.max.y;
  642. }else
  643. return 0;
  644. }else
  645. return 0;
  646. if(p.x!=0 || p.y!=0){
  647. scrollelement(list, p, &moved);
  648. return 1;
  649. }
  650. return 0;
  651. }
  652. PElement*
  653. mkelement(Prefab_Environ *env, enum Elementtype t)
  654. {
  655. Heap *h;
  656. PElement *p;
  657. h = heapz(TElement);
  658. p = H2D(PElement*, h);
  659. p->highlight = H;
  660. p->first = H;
  661. p->last = H;
  662. p->vfirst = H;
  663. p->vlast = H;
  664. p->nkids = 1;
  665. p->pkind = t;
  666. p->e.kind = t;
  667. p->e.environ = env;
  668. D2H(env)->ref++;
  669. return p;
  670. }