commit c0c4fcebb32193be96cc7e8f9d9ac0dcf323d233
parent 63001843fde06f544d01985268481bd83d7acd25
Author: pancake <pancake@nopcode.org>
Date: Thu, 29 Apr 2010 00:08:08 +0200
fix img_free
fix line width in swk_label
some changes in config.h
Diffstat:
6 files changed, 73 insertions(+), 9 deletions(-)
diff --git a/README b/README
@@ -0,0 +1,64 @@
+SWK - simple widget kit
+=======================
+
+ pacman -S sdl sdl_ttf sdl_image
+
+Usability guideline
+===================
+Default keybindings are defined in config.h
+
+TODO
+====
+* support for clipboard (implemented in gi_ backend)
+* simple way to define callback for buttons instead of reimplementing widget
+* scroll on focus
+* mouse bindings
+* allow widgets to define their boundaries to force size
+* add support to resize images
+* only focus buttons and entries
+* add function to click button 1, 2, 3, ...
+* allow to load images from memory instead of files
+* default image path
+
+Text format UI design
+=====================
+
+ \n -> newline
+ \t -> swk_filler
+ ".." -> swk_label
+ ---* -> swk_separator
+ ===* -> newline(-1)
+ [..] -> button
+ (..) -> option
+ <.*> -> image
+
+Example description:
+--------------------
+
+ {HelloWorld
+ "Press a button"
+ ----------------
+ (save password)
+ (store options)
+ [Ok] [Cancel]
+ ================
+ "This is new"
+ <image.png>
+ }
+
+Test program:
+-------------
+
+ void onclick() {
+ if(e->type != EClick || e->box->text==NULL)
+ return;
+ if(!strcmp(e->box->text, "Ok")) {
+ }
+ }
+ SwkWindow *w = swk_ui(
+ "{HelloWorld\n
+ "\"Press a button\"\n"
+ "--\n"
+ "[Ok] [Cancel]\n==\n");
+ w->cb = onclick;
+ swk_ui_free(w);
diff --git a/config.def.h b/config.def.h
@@ -4,7 +4,7 @@
#ifdef N900
#define FONTSIZE 32
#else
-#define FONTSIZE 14
+#define FONTSIZE 28
#endif
/* appearance */
@@ -17,8 +17,8 @@
//#define SWK_COLOR(r,g,b) r##g##b
#define HICOLOR SWK_COLOR(0,66,ff)
+#define BGCOLOR SWK_COLOR(20,20,20)
#define FGCOLOR SWK_COLOR(e0,e0,e0)
-#define BGCOLOR SWK_COLOR(00,00,00)
#define TFCOLOR SWK_COLOR(cc,cc,cc)
/* key bindings */
@@ -31,7 +31,7 @@ static SwkKeyBind keys[] = {
{ Ctrl, 10 , swk_focus_next },
{ Ctrl, 11 , swk_focus_prev },
{ Ctrl, 12 , swk_focus_activate },
- { 0, 225, swk_focus_activate }, // n900 enter
+ { 0, 225, swk_focus_activate }, // n900 enter
{ 0 , KUp, swk_focus_prev },
{ 0 , KDown, swk_focus_next },
{ 0 , 13 , swk_focus_activate },
diff --git a/gi_sdl.c b/gi_sdl.c
@@ -264,7 +264,6 @@ swk_gi_text(Rect r, const char *text) {
}
/* images */
-
void
swk_gi_img(Rect r, void *img) {
SDL_Surface *s = (SDL_Surface*)img;
@@ -277,9 +276,9 @@ swk_gi_img_load(const char *str) {
return IMG_Load(str);
}
-void*
-swk_gi_img_free(const char *str) {
- return IMG_Load(str);
+void
+swk_gi_img_free(void *s) {
+ SDL_FreeSurface(s);
}
void
diff --git a/swk.c b/swk.c
@@ -290,6 +290,7 @@ swk_label(SwkEvent *e) {
r = e->box->r;
r.w+=6;
swk_gi_text(r, e->box->text);
+ r.w-=6;
if(e->win->box == e->box)
swk_gi_line(r.x, r.y+1, r.w, 0, ColorHI);
break;
diff --git a/swk.h b/swk.h
@@ -125,6 +125,6 @@ void swk_gi_text(Rect r, const char *text);
/* images */
void swk_gi_img(Rect r, void *img);
void* swk_gi_img_load(const char *str);
-void* swk_gi_img_free(const char *str);
+void swk_gi_img_free(void *s);
void swk_gi_img_set(void *img, int x, int y, int color);
int swk_gi_img_get(void *img, int x, int y);
diff --git a/test.c b/test.c
@@ -40,7 +40,7 @@ static void myprogressbutton(SwkEvent *e) {
}
static SwkBox about[] = {
- SWK_BOX_NEWLINE(-1),
+ SWK_BOX_NEWLINE(0),
{ .cb=swk_label, .text="About this program...", },
SWK_BOX_NEWLINE(1),
{ .cb=swk_separator },