swk

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

commit 428895db9fe578899db0efdc588a01b54224c4fb
parent c935901161f07237869b4af43f090dcc53800053
Author: pancake <pancake@nopcode.org>
Date:   Tue, 24 Aug 2010 22:06:11 +0200

fix cursor in swk_entry with some ugly hacks
use USE_X11 and USE_SDL defines
fix error message when cannot open images
add 'close' button in scrollwin screen of test.c
Diffstat:
Makefile | 2++
gi_sdl.c | 9+++++++--
gi_x11.c | 8+++++++-
swk.c | 18+++++++++++++-----
t/test.c | 9+++++++++
5 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile @@ -7,9 +7,11 @@ VERSION=0.1 GI?=sdl ifeq (${GI},sdl) GI_LIBS=-lSDL -lSDL_ttf -lSDL_image +CFLAGS+=-DUSE_SDL else ifeq (${GI},x11) GI_LIBS=-lX11 -ldraw +CFLAGS+=-DUSE_X11 endif endif diff --git a/gi_sdl.c b/gi_sdl.c @@ -13,7 +13,7 @@ #define SDLFLAGS SDL_DOUBLEBUF|SDL_RESIZABLE static int first = 1; -static int fs = FONTSIZE; // TODO: we need fsW and fsH +static int fs = FONTSIZE; static Uint32 pal[ColorLast]; static SDL_Color fontcolor = { TFCOLOR }; static SDL_Color bgcolor = { BGCOLOR }; @@ -245,12 +245,17 @@ swk_gi_line(int x1, int y1, int x2, int y2, int color) { void swk_gi_fill(Rect r, int color, int lil) { SDL_Rect area = { r.x*fs, r.y*fs, r.w*fs, r.h*fs }; - if(lil) { + if(lil==1) { const int s = fs/4; area.x += s; area.y += s; area.w -= (s*2); area.h -= (s*2); + } else if (lil==2) { + area.x/=4; + area.y+=4; + area.w/=4; + area.h-=4; } if(!area.w) area.w = 1; if(!area.h) area.h = 1; diff --git a/gi_x11.c b/gi_x11.c @@ -211,12 +211,18 @@ swk_gi_line(int x1, int y1, int x2, int y2, int color) { void swk_gi_fill(Rect r, int color, int lil) { XRectangle area = { r.x*fs, r.y*fs, r.w*fs, r.h*fs }; - if(lil) { + if(lil==1) { int s = fs/4; area.x += s; area.y += s; area.width -= (s*2); area.height -= (s*2); + } else + if(lil==2) { + area.x/=3; + area.width/=4; + area.y+=4; + area.height-=4; } if(area.width<1) area.width = 1; if(area.height<1) area.height = 1; diff --git a/swk.c b/swk.c @@ -394,10 +394,18 @@ swk_entry(SwkEvent *e) { break; case EExpose: // XXX: add support for cursor (handle arrow keys) - len = strlen(e->box->text); - len += e->box->r.x; + #ifdef USE_SDL + len = 4*e->box->r.x; + len += 2*strlen(e->box->text)+1; + #else + len = 3*e->box->r.x; + len += strlen(e->box->text)+1; + #endif swk_label(e); - swk_gi_line(len, e->box->r.y, 0, 1, ColorFG); + { + Rect r = {len, e->box->r.y, 1, 1 }; + swk_gi_fill(r, ColorFG, 2); + } break; } } @@ -522,12 +530,12 @@ void swk_image(SwkEvent *e) { if(e->box->data == NULL) { e->box->data = swk_gi_img_load(e->box->text); - if(e->box->data) + if(!e->box->data) fprintf(stderr, "Cannot find image %s\n", e->box->text); } switch(e->type) { case EExpose: - swk_gi_rect(e->box->r, BORDERCOLOR); + swk_gi_rect(e->box->r, ColorFG); if(e->win->box == e->box) { Rect r = e->box->r; swk_gi_line(r.x, r.y+1, r.w, 0, ColorHI); diff --git a/t/test.c b/t/test.c @@ -79,10 +79,19 @@ static void mybutton_about(SwkEvent *e) { swk_button(e); } +static void mybutton_close(SwkEvent *e) { + if(e->type == EClick) { + e->win->boxes[e->win->col] = helloworld; + swk_update(e->win); + } + swk_button(e); +} + static SwkBox scrollwin[] = { SWK_BOX_NEWLINE(0), { .cb=swk_label, .text="Scroll to change value", }, SWK_BOX_NEWLINE(1), + { .cb=mybutton_close, .text="Close" }, { .cb=swk_separator }, SWK_BOX_NEWLINE(1), { .cb=swk_label, .text=" /etc" },