swk

static widget kit
git clone git://git.suckless.org/swk
Log | Files | Refs | README | LICENSE

commit a79c2ddbe29de4c6cc666e99f16457f08a287ee3
parent 8c51acff73d4d739dada94a877f29ba0c623f8c1
Author: pancake <pancake@nopcode.org>
Date:   Wed, 28 Apr 2010 22:32:03 +0200

fix screen size on non-tiled window managers
fit initial resize on tiled window managers
lock surface on flipping
support more than one scrolling area
display scroll index on scrolling separators
Diffstat:
gi_sdl.c | 5+++++
swk.c | 25+++++++++++++++++++++----
test.c | 5+++--
3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/gi_sdl.c b/gi_sdl.c @@ -70,6 +70,9 @@ swk_gi_init(SwkWindow *w) { fprintf(stderr, "Cannot initialize TTF: %s\n", TTF_GetError()); return 0; } + SDL_VideoInit(NULL, 0); + SDL_SetVideoMode(w->r.w, w->r.h, BPP, SDLFLAGS); + // double init is necesary to get window size SDL_SetVideoMode(w->r.w, w->r.h, BPP, SDLFLAGS); SDL_WM_SetCaption(w->title, NULL); screen = SDL_GetVideoSurface(); @@ -200,7 +203,9 @@ swk_gi_clear() { void swk_gi_flip() { + SDL_LockSurface(screen); SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); + SDL_UnlockSurface(screen); } /* -- drawing primitives -- */ diff --git a/swk.c b/swk.c @@ -23,7 +23,9 @@ swk_init(SwkWindow *w) { void swk_update(SwkWindow *w) { + char text[8]; int roy, oy; + int scroll = 0; w->_e.type = EExpose; if(swk_gi_update(w)) { SwkBox *b = w->boxes; @@ -34,8 +36,18 @@ swk_update(SwkWindow *w) { w->_e.box = b; if(b->r.w==-1 && b->r.h==-1 && ((int)(size_t)b->data)<0) roy = oy+1; - if(roy && b->r.y < roy) - swk_gi_line(0, roy, w->r.w, 0, ColorHI); + if (b->scroll) + scroll = b->scroll; + if(roy && b->r.y < roy) { + sprintf(text, "(%d)", scroll); + Rect r = w->r; + r.x = r.w-1; + r.y = roy; + r.w = 3; + swk_gi_text(r, text); + r.x--; + swk_gi_line(r.x, roy, r.w, 0, ColorHI); + } else b->cb(&w->_e); oy = b->r.y; } @@ -72,10 +84,14 @@ swk_fontsize_decrease(SwkWindow *w) { static SwkBox * getscrollbox(SwkWindow *w) { + SwkBox *r = NULL; SwkBox *b = w->boxes; - for(; b->cb; b++) + for(; b->cb; b++) { if(b->r.w==-1 && b->r.h==-1 && ((int)(size_t)b->data)<0) - return b; + r = b; + if(w->box==b) + return r?r:w->boxes; + } return w->boxes; } @@ -272,6 +288,7 @@ swk_label(SwkEvent *e) { switch(e->type) { case EExpose: r = e->box->r; + r.w+=6; swk_gi_text(r, e->box->text); if(e->win->box == e->box) swk_gi_line(r.x, r.y+1, r.w, 0, ColorHI); diff --git a/test.c b/test.c @@ -27,19 +27,20 @@ static void mybutton(SwkEvent *e) { static void myprogressbutton(SwkEvent *e) { if(e->type == EClick) { - pccount+=15; + pccount+=6; if(pccount > 100) { pccount = 0; e->win->boxes = helloworld; swk_update(e->win); } sprintf(pctext, "%d%%", pccount); - about[10].text = pctext; + about[11].text = pctext; } swk_button(e); } static SwkBox about[] = { + SWK_BOX_NEWLINE(-1), { .cb=swk_label, .text="About this program...", }, SWK_BOX_NEWLINE(1), { .cb=swk_separator },