7 typedef struct Slider Slider;
9 int dir; /* HORIZ or VERT */
10 int val; /* setting, in screen coordinates */
12 void (*hit)(Panel *, int, int, int); /* call back to user when slider changes */
15 void pl_drawslider(Panel *p){
19 r=pl_box(p->b, p->r, UP);
21 case HORIZ: pl_sliderupd(p->b, r, sp->dir, 0, sp->val); break;
22 case VERT: pl_sliderupd(p->b, r, sp->dir, r.max.y-sp->val, r.max.y); break;
25 int pl_hitslider(Panel *p, Mouse *m){
26 int oldstate, oldval, len;
31 size=subpt(p->r.max, p->r.min);
32 pl_interior(p->state, &ul, &size);
38 else if(m->buttons&7){
40 sp->buttons=m->buttons;
46 sp->val=ul.y+size.y-m->xy.y;
49 if(sp->val<0) sp->val=0;
50 else if(sp->val>len) sp->val=len;
52 else /* mouse inside, but no buttons down */
54 if(oldval!=sp->val || oldstate!=p->state) pldraw(p, p->b);
55 if(oldval!=sp->val && sp->hit) sp->hit(p, sp->buttons, sp->val, len);
58 void pl_typeslider(Panel *p, Rune c){
61 Point pl_getsizeslider(Panel *p, Point children){
63 return pl_boxsize(((Slider *)p->data)->minsize, p->state);
65 void pl_childspaceslider(Panel *g, Point *ul, Point *size){
68 void plinitslider(Panel *v, int flags, Point size, void (*hit)(Panel *, int, int, int)){
71 v->r=Rect(0,0,size.x,size.y);
74 v->draw=pl_drawslider;
76 v->type=pl_typeslider;
77 v->getsize=pl_getsizeslider;
78 v->childspace=pl_childspaceslider;
80 sp->dir=size.x>size.y?HORIZ:VERT;
84 Panel *plslider(Panel *parent, int flags, Point size, void (*hit)(Panel *, int, int, int)){
86 p=pl_newpanel(parent, sizeof(Slider));
87 plinitslider(p, flags, size, hit);
90 void plsetslider(Panel *p, int value, int range){
94 else if(value>range) value=range;
95 if(sp->dir==HORIZ) sp->val=value*(p->r.max.x-p->r.min.x)/range;
96 else sp->val=value*(p->r.max.y-p->r.min.y)/range;