[hackers] [swk] initial stuff || arg

From: <hg_AT_suckless.org>
Date: Sat, 27 Mar 2010 22:10:34 +0000 (UTC)

changeset: 0:1adc0fd39299
tag: tip
user: arg_AT_localhost.localdomain
date: Sat Mar 27 22:10:33 2010 +0000
files: Makefile README swk.c swk.h test.c
description:
initial stuff

diff -r 000000000000 -r 1adc0fd39299 Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile Sat Mar 27 22:10:33 2010 +0000
@@ -0,0 +1,24 @@
+CC?=gcc
+DESTDIR?=
+PREFIX?=${DESTDIR}/usr/local
+LIBDIR?=${PREFIX}/lib
+
+all: static test
+
+test.o:
+ ${CC} -I. test.c -c -o test.o
+
+test: test.o
+ ${CC} test.o -o test libswk.a
+
+clean:
+ rm -f libswk.a test.o swk.o test
+
+install:
+ cp ${DESTDIR}/${LIBDIR}
+
+static: libswk.a
+
+libswk.a: swk.o
+ rm -f libswk.a
+ ar qcvf libswk.a swk.o
diff -r 000000000000 -r 1adc0fd39299 README
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/README Sat Mar 27 22:10:33 2010 +0000
@@ -0,0 +1,90 @@
+swk - the static widget toolkit
+================================
+swk is a dynamic widget toolkit that provides the ability to create
+keyboard-driven textual UIs very quickly on top of supported(*) window systems
+
+Historically the swk domain is covered by (n)curses based applications that run
+completely in text mode. But this approach has numerous disadvatages, such as
+archaic cursor handling, slow screen redraws, limitations through the use of
+just text and characters, different behaviour in different terminal modes, and
+so on.
+
+On the other hand full-featured UI toolkits like GTK or Qt are far too complex
+and bloated to be anywhere close for rapid and effecient development, or to be
+actually portable onto devices with limited memory and processing power.
+
+Design
+------
+We believe lesser choice is better.
+
+swk has a very basic set of widgets, particularly only widgets with few
+properties and function pointers to extend and override the behaviour and
+appearance of such widgets. The overall widget structure is a tree of widgets,
+where the root of the tree represents the lower-most widget which
+contains all other widgets; and where all leafs represent the
+top-most widgets.
+
+Each widget is parent relative and swk scales child widgets by maximising them
+into the available space of the surrounding parent widget, unless a child
+widget has no width or height factor specified.
+
+The layout algorithm fills child widgets horizontally until a break is inserted
+that creates a new row. The swk layout algorithm does *not* support the use of
+absolute x/y offsets or fixed width/height in order to guarantuee seamless
+scaling, this is an advantage and increases the usability and look'n'feel of
+swk user interfaces.
+
+The width/height of a widget is defined as float factor in between 0.0 and 1.0
+that is used for scaling it in a parent relative way. The sum of all widgets
+in a row until a break should not exceed 1.0, the sum of the widget with the
+greatest height in each row should not exceed 1.0 either in order that the
+layout algorithm creates useful results. If the sum is greater than 1.0 or
+negative swk will ignore all width/height factors until the developer has fixed
+his mistake.
+
+typedef void * SwkBitmap;
+typedef SwkWidget * SwkBreak;
+typedef unsigned long SwkColor;
+typedef char * SwkText;
+
+typedef struct {
+ SwkText *name;
+} SwkFont;
+
+typedef struct {
+ SwkColor bg;
+ SwkColor text;
+ SwkColor border;
+ SwkFont *font;
+} SwkGC;
+
+typedef struct _SwkWidget SwkWidget;
+struct _SwkWidget {
+ float w_factor;
+ float h_factor;
+ SwkGC gc
+ SwkText *text
+ SwkWidget *parent
+ SwkWidget **childs
+ SwkBitmap *(*draw)(Widget *w, void *userdata, SwkBitmap *current, unsigned int current_w, unsigned int current_h);
+ void (*click)(Widget *w, void *userdata, unsigned int current_w, unsigned int current_h, int x, int y);
+ void (*keypress)(Widget *w, void *userdata, int keycode);
+ void (*focusin)(Widget *w, void *userdata);
+ void (*focusout)(Widget *w, void *userdata);
+};
+
+The content of each widget is a Bitmap, which is a platform dependent
+representation of the actual content of the widget using in its current size.
+
+If you overload the draw function of a widget, it is expected that you return a
+Bitmap covering the current actual size of the widget.
+
+There are also a bunch of swk manipulation functions that help you implementing
+custom draw functions:
+
+void swk_copy_bitmap(Bitmap *target, Bitmap *source, int target_x, int target_y, int source_x, int source_y, uint source_w, uint source_h);
+void swk_draw_text(Bitmap *target, int offset_x, int offset_y, Text *text);
+
+Remarks
+-------
+(*) Currently we the X Window System is the only supported environment.
diff -r 000000000000 -r 1adc0fd39299 swk.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/swk.c Sat Mar 27 22:10:33 2010 +0000
@@ -0,0 +1,64 @@
+/* Copyleft 2010 -- pancake <nopcode.org> */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "swk.h"
+
+int swkret = 0;
+SwkScene swkscene;
+
+int swk_init () {
+ swkscene.window = NULL;
+ swkscene.windows = NULL;
+}
+
+SwkWindow *swk_widget () {
+}
+
+SwkWindow *swk_box () {
+}
+
+SwkWindow *swk_box_add (SwkBox *box) {
+}
+
+// TODO: rename to box_layout ??
+int swk_window_layout_flow (SwkWindow *window) {
+ return 0;
+}
+
+int swk_box_layout_flow (SwkBox *box) {
+ return 0;
+}
+
+SwkWindow *swk_window () {
+ SwkWindow *w = (SwkWindow *) malloc (sizeof (SwkWindow));
+ w->next = NULL;
+ if (swkscene.window) swkscene.window->next = w;
+ else swkscene.windows = w;
+ swkscene.window = w;
+ return w;
+}
+
+int swk_window_add (SwkWindow *w) {
+}
+
+SwkWidget* swk_label () {
+ /* .. */
+}
+
+int swk_window_delete (SwkWindow *w) {
+ SwkWindow *iter = swkscene.window;
+ // XXX
+ while (iter) {
+ if (iter == w)
+ return 1;
+ iter = iter->next;
+ }
+ return 0;
+}
+
+int swk_event () {
+}
+
+int swk_redraw () {
+}
diff -r 000000000000 -r 1adc0fd39299 swk.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/swk.h Sat Mar 27 22:10:33 2010 +0000
@@ -0,0 +1,51 @@
+#define TRUE 1
+#define FALSE 0
+typedef int bool_t;
+
+typedef struct swk_widget_t {
+ int (*render) (struct swk_widget_t *widget, int w, int h);
+ int (*activate) (struct swk_widget_t *widget, int type);
+ void *user;
+} SwkWidget;
+
+typedef struct container_t {
+ char *title; // nullable
+ int show; // boolean
+ struct SwkWidget *widget;
+ struct SwkBox *next;
+} SwkBox;
+
+typedef struct swk_window_t {
+ char *title;
+ SwkWidget *selected;
+ SwkBox *box;
+ SwkBox *boxes;
+ int (*box_align) (struct swk_window_t *window);
+ struct swk_window_t *next;
+} SwkWindow;
+
+typedef struct scene_t {
+ SwkWindow *windows;
+ SwkWindow *window;
+} SwkScene;
+
+typedef enum {
+ CLICK,
+ RELEASE,
+ MOUSE_OVER,
+ MOUSE_OUT,
+} SwkEvent;
+
+int swk_widget_set_event_mask (SwkWidget *w, int evmask);
+
+int swk_scene_next (SwkScene *s, int dir);
+int swk_event ();
+
+void flow_layout_align (SwkScene *scene);
+
+extern SwkScene swkscene;
+extern int swkret;
+
+// uhm? not here maybe
+extern int swk_window_layout_flow (SwkWindow *window);
+extern int swk_box_layout_flow (SwkBox* box);
diff -r 000000000000 -r 1adc0fd39299 test.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test.c Sat Mar 27 22:10:33 2010 +0000
@@ -0,0 +1,17 @@
+#include <swk.h>
+
+int main () {
+ SwkWindow *w;
+ SwkBox *c;
+
+ swk_init ();
+
+ w = swk_window (swk_window_layout_flow);
+ c = swk_box (swk_box_layout_flow);
+ swk_box_add (c, swk_label ("Hello World"));
+ //swk_add_box (c);
+
+ // TODO: not working with glib
+ while (swk_event ());
+ return swkret;
+}
Received on Sat Mar 27 2010 - 22:10:34 UTC

This archive was generated by hypermail 2.2.0 : Sat Mar 27 2010 - 22:12:06 UTC