swk

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

commit d85fee7cf0f1899b192d4b79b3774567ed6f42b6
parent 4f51b8003075b192d1e5237cce4b5ce4a9109420
Author: pancake <pancake@nopcode.org>
Date:   Tue, 27 Apr 2010 02:09:26 +0200

do not overlap widgets when vertical fill used
add second screen in test program
Diffstat:
gi_sdl.c | 4++--
swk.c | 10++++------
test.c | 31+++++++++++++++++++++++++++++++
3 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/gi_sdl.c b/gi_sdl.c @@ -79,8 +79,8 @@ swk_gi_update(SwkWindow *w) { screen = SDL_GetVideoSurface(); if (screen == NULL) return 0; - w->r.w = screen->w / FS; - w->r.h = screen->h / FS; + w->r.w = (screen->w / FS)-1; + w->r.h = (screen->h / FS)-1; return 1; } diff --git a/swk.c b/swk.c @@ -81,7 +81,7 @@ countrows(SwkBox *b) { void swk_fit(SwkWindow *w) { - int x, y = 0; + int x, yi, y = 0; SwkBox *b, *b2; for(b=b2=w->boxes; b->cb; b++) { if(b->r.w==-1 && b->r.h==-1) { @@ -93,11 +93,9 @@ swk_fit(SwkWindow *w) { } else { swk_fit_row(w, b2, b, y); b2 = b+1; - y += 1+(w->r.h-countrows(b2)); - if (y<0) { - fprintf(stderr, "overflow: must scroll\n"); - y=0; - } + yi = (w->r.h-countrows(b2)); + if (yi<2) y += 2; + else y += yi; } } } diff --git a/test.c b/test.c @@ -5,6 +5,9 @@ static int count = 3; static char text[64]; static SwkBox helloworld[]; static SwkBox *opt = NULL; +static void mybutton(SwkEvent *e); +static void mybutton_about(SwkEvent *e); +static void mybutton_about_ok(SwkEvent *e); static void mybutton(SwkEvent *e) { if (e->type == EClick) { @@ -19,6 +22,33 @@ static void mybutton(SwkEvent *e) { swk_button(e); } +static SwkBox about[] = { + { .cb=swk_label, .text="About this program...", }, + SWK_BOX_NEWLINE(1), + { .cb=swk_separator }, + { .cb=swk_label, .text="This program aims to be\nfor hackers\nand developers\n" }, + SWK_BOX_NEWLINE(-1), + { .cb=swk_filler }, + { .cb=mybutton_about_ok, .text="Ok" }, + { .cb=NULL } +}; + +static void mybutton_about_ok(SwkEvent *e) { + if (e->type == EClick) { + e->win->boxes = helloworld; + swk_update(e->win); + } + swk_button(e); +} + +static void mybutton_about(SwkEvent *e) { + if (e->type == EClick) { + e->win->boxes = about; + swk_update(e->win); + } + swk_button(e); +} + static SwkBox helloworld[] = { { .cb=swk_label, .text="Press a button", }, SWK_BOX_NEWLINE(1), @@ -42,6 +72,7 @@ static SwkBox helloworld[] = { { .cb=swk_option, .text="pasta barata", .data=&opt }, SWK_BOX_NEWLINE(5), { .cb=swk_label, .text="--swktest", }, + { .cb=mybutton_about, .text="about" }, { .cb=NULL } };