chickadee » kiwi

Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

kiwi

TOC »

Introduction

This egg provides a fairly complete set of low-level bindings and a high-level SXML widget interface to the KiWi library. It is intended to be used in combination with the sdl2 egg to create simple user interfaces for games and GUI applications.

Author

Vasilij Schneidermann

Repository

https://github.com/wasamasa/kiwi

Requirements

Both KiWi and SDL2 must be available on your machine. An Arch Linux PKGBUILD is available here. The bindings are based on everything up to commit de9c5d, so they might break on API-incompatible changes introduced after 2016-06-04. Please contact me on the #chicken channel or open a GitHub issue if this happens to you.

The installation script tries autodetecting their location with cmake and sdl2-config. This can be overridden by using the KIWI_FLAGS and SDL2_FLAGS environment variables. The bindings themselves require the clojurian and matchable eggs.

API

Setup and teardown

create-sdl2-driver
create-sdl2-driver RENDERER WINDOWprocedure

Creates and returns a SDL2-backed driver. RENDERER and WINDOW must be raw pointers to a SDL2 renderer and window and can be obtained by using the unwrap-renderer and unwrap-window procedures from the sdl2-internals module of the sdl2 egg.

driver?
driver? ARGprocedure

Returns #t if ARG is an driver, otherwise #f.

driver-sdl2-renderer
driver-sdl2-renderer DRIVERprocedure

Returns the raw SDL2 renderer pointer associated with DRIVER.

driver-sdl2-window
driver-sdl2-window DRIVERprocedure

Returns the raw SDL2 window pointer associated with DRIVER.

release-driver!
release-driver! DRIVERprocedure

Frees the resources of DRIVER. This is called implicitly as finalizer for driver records.

load-surface
load-surface DRIVER FILENAMEprocedure

Creates and returns a surface based on an image found at FILENAME. Supported image formats are the same as for the sdl2-image egg. If the image could not be loaded, an exception of the type (exn sdl2) is thrown.

surface?
surface? ARGprocedure

Returns #t if ARG is an surface, otherwise #f.

release-surface!
release-surface! DRIVER SURFACEprocedure

Frees the resources of SURFACE. This is called implicitly as finalizer for surface records.

load-font
load-font DRIVER FONTNAME SIZEprocedure

Creates and returns a font based on the TTF font found at FILENAME with the font size SIZE. If the font could not be loaded, an exception of the type (exn sdl2) is thrown.

font?
font? ARGprocedure

Returns #t if ARG is an font, otherwise #f.

release-font!
release-font! DRIVER FONTprocedure

Frees the resources of FONT. This is called implicitly as finalizer for font records.

init!
init! DRIVER TILESET-SURFACEprocedure

Initializes and returns a GUI. TILESET-SURFACE must be a surface to be used as tileset.

process-events!
process-events! GUIprocedure

Process events for GUI and trigger all event handlers involved.

paint!
paint! GUIprocedure

Repaint all widgets associated with GUI.

quit!
quit! GUIprocedure

Terminates GUI and frees the resources of all associated widgets. This procedure must be called explicitly at the end of the program before terminating SDL2 and is therefore a candidate for an on-exit handler.

gui-driver / gui-driver-set!
gui-driver GUIprocedure
gui-driver-set! GUI DRIVERprocedure
set! (gui-driver GUI) DRIVERsetter

Retrieves or sets the driver of GUI.

gui-font / gui-font-set!
gui-font GUIprocedure
gui-font-set! GUI FONTprocedure
set! (gui-font GUI) FONTsetter

Retrieves or sets the font of GUI. Note that this is optional as KiWi comes baked in with Source Sans Pro as default font.

gui-text-color / gui-text-color-set!
gui-text-color GUIprocedure
gui-text-color-set! GUI TEXT-COLORprocedure
set! (gui-text-color GUI) TEXT-COLORsetter

Retrieves or sets the text color of GUI.

gui-tileset-surface / gui-tileset-surface-set!
gui-tileset-surface GUIprocedure
gui-tileset-surface-set! GUI TILESET-SURFACEprocedure
set! (gui-tileset-surface GUI) TILESET-SURFACEsetter

Retrieves or sets the tileset surface of GUI.

Rects

rect
rect X Y W Hprocedure

Creates and returns a rectangle at the coordinates X and Y with the dimensions W and H.

rect?
rect? ARGprocedure

Returns #t if ARG is an rect, otherwise #f.

rect-x / rect-x-set!
rect-x RECTprocedure
rect-x-set! RECT Xprocedure
set! (rect-x RECT) Xsetter

Retrieves or sets the x coordinate of RECT.

rect-y / rect-y-set!
rect-y RECTprocedure
rect-y-set! RECT Yprocedure
set! (rect-y RECT) Ysetter

Retrieves or sets the y coordinate of RECT.

rect-w / rect-w-set!
rect-w RECTprocedure
rect-w-set! RECT Wprocedure
set! (rect-w RECT) Wsetter

Retrieves or sets the width of RECT.

rect-h / rect-h-set!
rect-h RECTprocedure
rect-h-set! RECT Hprocedure
set! (rect-h RECT) Hsetter

Retrieves or sets the height of RECT.

Rect helpers

rect-empty?
rect-empty? RECTprocedure

Returns #t if RECT is empty, otherwise #f.

enclosing-rect
enclosing-rect RECTSprocedure

Returns a rectangle enclosing all RECTS.

rect-center-in-parent!
rect-center-in-parent! PARENT INNERprocedure

Centers INNER in PARENT vertically and horizontally by mutating the coordinates of INNER.

rect-center-in-parent-vertically!
rect-center-in-parent-vertically! PARENT INNERprocedure

Centers INNER in PARENT vertically by mutating the coordinates of INNER.

rect-center-in-parent-horizontally!
rect-center-in-parent-horizontally! PARENT INNERprocedure

Centers INNER in PARENT horizontally by mutating the coordinates of INNER.

rect-layout-vertically!
rect-layout-vertically! RECTS PADDING #!optional HALIGNprocedure

Layouts RECTS to be aligned as a vertical list with PADDING pixels between them by mutating their coordinates. HALIGN must be one of (left center right) if specified, otherwise the horizontal alignment of RECTS will not be changed.

rect-layout-horizontally!
rect-layout-horizontally! RECTS PADDING #!optional VALIGNprocedure

Layouts RECTS to be aligned as a horizontal list with PADDING pixels between them by mutating their coordinates. VALIGN must be one of (top middle bottom) if specified, otherwise the vertical alignment of RECTS will not be changed.

rect-fill-parent-vertically!
rect-fill-parent-vertically! PARENT RECTS WEIGHTS PADDINGprocedure

Layouts and resizes RECTS to fit PARENT by changing their coordinates and height. WEIGHTS is a list of fixnums mapped to RECTS. The higher the weight, the more space a rectangle will occupy. PADDING specifies the space in pixels between the rectangles. Note that this procedure does no rectangle aligning.

rect-fill-parent-horizontally!
rect-fill-parent-horizontally! PARENT RECTS WEIGHTS PADDING VALIGNprocedure

Layouts and resizes RECTS to fit PARENT by changing their coordinates and width. WEIGHTS is a list of fixnums mapped to RECTS. The higher the weight, the more space a rectangle will occupy. PADDING specifies the space in pixels between the rectangles. VALIGN must be one of (top middle bottom).

rect-margin!
rect-margin! PARENT INNER MARGINprocedure

Resizes and repositions INNER to be centered inside PARENT with MARGIN pixels of margin.

Colors

color
color R G B Aprocedure

Creates and returns a color with the components R, G, B and A.

color?
color? ARGprocedure

Returns #t if ARG is an color, otherwise #f.

color-r / color-r-set!
color-r COLORprocedure
color-r-set! COLOR Rprocedure
set! (color-r COLOR) Rsetter

Retrieves or sets the red component of COLOR. R must be a fixnum between 0 and 255 (inclusive).

color-g / color-g-set!
color-g COLORprocedure
color-g-set! COLOR Gprocedure
set! (color-g COLOR) Gsetter

Retrieves or sets the green component of COLOR. G must be a fixnum between 0 and 255 (inclusive).

color-b / color-b-set!
color-b COLORprocedure
color-b-set! COLOR Bprocedure
set! (color-b COLOR) Bsetter

Retrieves or sets the blue component of COLOR. B must be a fixnum between 0 and 255 (inclusive).

color-a / color-a-set!
color-a COLORprocedure
color-a-set! COLOR Aprocedure
set! (color-a COLOR) Asetter

Retrieves or sets the alpha component of COLOR. A must be a fixnum between 0 and 255 (inclusive).

Frame widget

frame
frame GUI PARENT GEOMETRYprocedure

Creates and returns a frame widget. PARENT must either be a widget or #f to create a top-level widget. GEOMETRY is a rectangle describing the position and dimensions of the widget.

frame?
frame? ARGprocedure

Returns #t if ARG is an frame widget, otherwise #f.

Scrollbox widget

scrollbox
scrollbox GUI PARENT GEOMETRYprocedure

Creates and returns a scrollbox widget. PARENT must either be a widget or #f to create a top-level widget. GEOMETRY is a rectangle describing the position and dimensions of the widget.

scrollbox?
scrollbox? ARGprocedure

Returns #t if ARG is an scrollbox widget, otherwise #f.

scrollbox-vertical-scroll!
scrollbox-vertical-scroll! SCROLLBOX AMOUNTprocedure

Scroll SCROLLBOX vertically by AMOUNT pixels.

scrollbox-horizontal-scroll!
scrollbox-horizontal-scroll! SCROLLBOX AMOUNTprocedure

Scroll SCROLLBOX horizontally by AMOUNT pixels.

Label widget

label
label GUI PARENT TEXT GEOMETRYprocedure

Creates and returns a label widget. PARENT must either be a widget or #f to create a top-level widget. TEXT is a string to be used as the label's text. GEOMETRY is a rectangle describing the position and dimensions of the widget.

label?
label? ARGprocedure

Returns #t if ARG is an label widget, otherwise #f.

label-text-set!
label-text-set! LABEL TEXTprocedure

Sets the text of LABEL to TEXT.

label-icon-set!
label-icon-set! LABEL CLIPprocedure

Sets an icon for LABEL. CLIP is a rectangle that will be clipped out of the currently active tileset for the icon.

label-alignment-set!
label-alignment-set! LABEL HALIGN HOFFSET VALIGN VOFFSETprocedure

Sets the alignment of LABEL. HALIGN must be one of (left center right) and VALIGN one of (top middle bottom). HOFFSET and VOFFSET specify the horizontal and vertical offset in pixels.

label-style-set!
label-style-set! LABEL STYLEprocedure

Sets the text style of LABEL. STYLE must be one of (normal bold italic underline strikethrough).

label-font / label-font-set!
label-font LABELprocedure
label-font-set! LABEL FONTprocedure
set! (label-font LABEL) FONTsetter

Retrieves or sets the font of LABEL.

label-text-color / label-text-color-set!
label-text-color LABELprocedure
label-text-color-set! LABEL TEXT-COLORprocedure
set! (label-text-color LABEL) TEXT-COLORsetter

Retrieves or sets the text color of LABEL. Note that this will default to black.

label-text-color-set?
label-text-color-set? LABELprocedure

Returns #t if the text color of LABEL has been set by the user.

Button widget

button
button GUI PARENT TEXT GEOMETRYprocedure

Creates and returns a button widget. PARENT must either be a widget or #f to create a top-level widget. TEXT is a string to be used for creating the button's label. GEOMETRY is a rectangle describing the position and dimensions of the widget.

button*
button* GUI PARENT LABEL GEOMETRYprocedure

Creates and returns a button widget. PARENT must either be a widget or #f to create a top-level widget. LABEL is a label to be associated with the button and can be #f to have none. GEOMETRY is a rectangle describing the position and dimensions of the widget.

button?
button? ARGprocedure

Returns #t if ARG is an button widget, otherwise #f.

button-label / button-label-set!
button-label BUTTONprocedure
button-label-set! BUTTON LABELprocedure
set! (button-label BUTTON) LABELsetter

Retrieves or sets the label of BUTTON. The latter returns the old label.

Editbox widget

editbox
editbox GUI PARENT TEXT GEOMETRYprocedure

Creates and returns a editbox widget. PARENT must either be a widget or #f to create a top-level widget. TEXT is a string to be used as the button's text. GEOMETRY is a rectangle describing the position and dimensions of the widget.

editbox?
editbox? ARGprocedure

Returns #t if ARG is an editbox widget, otherwise #f.

editbox-text / editbox-text-set!
editbox-text EDITBOXprocedure
editbox-text-set! EDITBOX TEXTprocedure
set! (editbox-text EDITBOX) TEXTsetter

Retrieves or sets the text of EDITBOX.

editbox-cursor-position / editbox-cursor-position-set!
editbox-cursor-position EDITBOXprocedure
editbox-cursor-position-set! EDITBOX POSprocedure
set! (editbox-cursor-position EDITBOX) POSsetter

Retrieves or sets the cursor position of EDITBOX. POS must be a fixnum specifying a valid index into the existing editbox text.

editbox-font / editbox-font-set!
editbox-font EDITBOXprocedure
editbox-font-set! EDITBOX FONTprocedure
set! (editbox-font EDITBOX) FONTsetter

Retrieves or sets the font of EDITBOX.

editbox-text-color / editbox-text-color-set!
editbox-text-color EDITBOXprocedure
editbox-text-color-set! EDITBOX TEXT-COLORprocedure
set! (editbox-text-color EDITBOX) TEXT-COLORsetter

Retrieves or sets the text color of EDITBOX. Note that this will default to black.

editbox-text-color-set?
editbox-text-color-set? EDITBOXprocedure

Returns #t if the text color of EDITBOX has been set by the user.

Toggle widget

toggle
toggle GUI PARENT GEOMETRYprocedure

Creates and returns a toggle widget. PARENT must either be a widget or #f to create a top-level widget. GEOMETRY is a rectangle describing the position and dimensions of the widget.

toggle-checked? / toggle-checked?-set!
toggle-checked? TOGGLEprocedure
toggle-checked?-set! TOGGLE CHECKED?procedure
set! (toggle-checked? TOGGLE) CHECKED?setter

Retrieves or sets the activation state of TOGGLE. CHECKED? must be either #t or #f.

Widget helpers

widget?
widget? ARGprocedure

Returns #t if ARG is an widget, otherwise #f.

widget-type
widget-type WIDGETprocedure

Returns a symbol describing the widget type. It will be one of (frame scrollbox label button editbox).

widget-gui
widget-gui WIDGETprocedure

Returns the GUI associated with WIDGET. This is a convenience procedure intended for use in event handlers.

widget-driver
widget-driver WIDGETprocedure

Returns the driver associated with WIDGET. This is a convenience procedure intended for use in event handlers.

widget-tileset-surface / widget-tileset-surface-set!
widget-tileset-surface WIDGETprocedure
widget-tileset-surface-set! WIDGET TILESET-SURFACEprocedure
set! (widget-tileset-surface WIDGET) TILESET-SURFACEsetter

Retrieves or sets the tileset surface of WIDGET.

widget-parent
widget-parent WIDGETprocedure

Returns the parent widget of WIDGET or #f if WIDGET is a top-level widget.

widget-children
widget-children WIDGETprocedure

Returns the children widgets of WIDGET as list. If WIDGET has no children, an empty list is returned.

reparent-widget!
reparent-widget! WIDGET PARENTprocedure

Changes the parent of WIDGET to PARENT. Note that this will not update the geometry of WIDGET. To make WIDGET a top-level widget, use #f as value for PARENT.

bring-widget-to-front!
bring-widget-to-front! WIDGETprocedure

Modifies the widget tree to make WIDGET appear on the front.

widget-focus-set!
widget-focus-set! WIDGETprocedure

Sets the GUI focus to WIDGET.

widget-clip-children?-set!
widget-clip-children?-set! WIDGET FLAGprocedure

Change whether the children of WIDGET should be clipped to its geometry. FLAG must be either #t or #f.

destroy-widget!
destroy-widget! WIDGET #!optional CHILDREN?procedure

Destroys WIDGET and frees its resources. If CHILDREN? is #t, destroy its children as well, otherwise reparent them to the parent of WIDGET. While this procedure can be used to remove widgets while the GUI is still running, consider hiding them instead.

hide-widget!
hide-widget! WIDGETprocedure

Hides WIDGET and its children. This is equivalent to (enable-widget-hint! WIDGET 'hidden #t).

show-widget!
show-widget! WIDGETprocedure

Displays WIDGET and its children again. This is equivalent to (disable-widget-hint! WIDGET 'hidden #t).

widget-hidden?
widget-hidden? WIDGETprocedure

Returns #t if WIDGET is hidden, otherwise #f. This is equivalent to (query-widget-hint WIDGET 'hidden).

block-widget-input-events!
block-widget-input-events! WIDGETprocedure

Blocks WIDGET and its children from receiving events. This is equivalent to (enable-widget-hint! WIDGET 'block-input-events #f).

unblock-widget-input-events!
unblock-widget-input-events WIDGETprocedure

Unblocks input event blocking for WIDGET. This is equivalent to (disable-widget-hint! WIDGET 'block-input-events #f).

widget-input-events-blocked?
widget-input-events-blocked? WIDGETprocedure

Returns #t if events are blocked for WIDGET, otherwise #f. This is equivalent to (query-widget-hint WIDGET 'block-input-events).

enable-widget-hint!
enable-widget-hint! WIDGET HINT RECUR?procedure

Enables the widget hint HINT for WIDGET. If RECUR? is #t, enable it recursively. HINT must be one of (allow-tile-stretch block-input-events ignore-input-events frameless hidden).

disable-widget-hint!
disable-widget-hint! WIDGET HINT RECUR?procedure

Disables the widget hint HINT for WIDGET. If RECUR? is #t, disable it recursively. HINT must be one of (allow-tile-stretch block-input-events ignore-input-events frameless hidden).

query-widget-hint
query-widget-hint WIDGET HINTprocedure

Query WIDGET for HINT, returning either #t if enabled or #f if disabled. HINT must be one of (allow-tile-stretch block-input-events ignore-input-events frameless hidden).

widget-geometry / widget-geometry-set!
widget-geometry WIDGETprocedure
widget-geometry-set! WIDGET GEOMETRYprocedure
set! (widget-geometry WIDGET) GEOMETRYsetter

Retrieves or sets the geometry of WIDGET.

widget-absolute-geometry
widget-absolute-geometry WIDGETprocedure

Returns the absolute geometry of WIDGET. Its coordinates are relative to the root instead of the parent widget.

widget-composed-geometry
widget-composed-geometry WIDGETprocedure

Returns the composed geometry of WIDGET. Its coordinates are relative to the root widget and its dimensions are equivalent to those of a rectangle enclosing it and its children.

widget-center-in-parent!
widget-center-in-parent! PARENT INNERprocedure

Centers INNER in PARENT vertically and horizontally.

widget-center-in-parent-vertically!
widget-center-in-parent-vertically! PARENT INNERprocedure

Centers INNER in PARENT vertically.

widget-center-in-parent-horizontally!
widget-center-in-parent-horizontally! PARENT INNERprocedure

Centers INNER in PARENT horizontally.

widget-layout-vertically!
widget-layout-vertically! WIDGETS PADDING #!optional HALIGNprocedure

Layouts WIDGETS as a vertical list. See rect-layout-vertically! for further details.

widget-layout-horizontally!
widget-layout-horizontally! WIDGETS PADDING #!optional VALIGNprocedure

Layouts WIDGETS as horizontal list. See rect-layout-horizontally! for further details.

widget-fill-parent-vertically!
widget-fill-parent-vertically! PARENT RECTS WEIGHTS PADDINGprocedure

Layouts and resizes WIDGETS to fit PARENT. See rect-fill-parent-vertically! for further details.

widget-fill-parent-horizontally!
widget-fill-parent-horizontally! PARENT RECTS WEIGHTS PADDING VALIGNprocedure

Layouts and resizes WIDGETS to fit PARENT. See rect-fill-parent-horizontally! for further details.

rect-margin!
widget-margin! PARENT INNER MARGINprocedure

Resizes and repositions INNER to be centered inside PARENT with MARGIN pixels of margin.

Handlers

handler-set!
handler-set! WIDGET TYPE PROCprocedure

Sets an event handler of TYPE for WIDGET to PROC. TYPE must be one of (mouse-over mouse-leave mouse-down mouse-up focus-gain focus-lose text-input drag-start drag-stop drag). Depending on TYPE, PROC must be a procedure accepting the corresponding argument list:

mouse-over
(lambda (widget) ...)
mouse-leave
(lambda (widget) ...)
mouse-down
(lambda (widget button) ...)
mouse-up
(lambda (widget button) ...)
focus-gain
(lambda (widget) ...)
focus-lose
(lambda (widget) ...)
text-input
(lambda (widget text) ...)
drag-start
(lambda (widget x y) ...)
drag-stop
(lambda (widget x y) ...)
drag
(lambda (widget x y relx rely) ...)
handler-remove!
handler-remove! WIDGET TYPEprocedure

Removes an event handler of TYPE for WIDGET. TYPE must be one of (mouse-over mouse-leave mouse-down mouse-up focus-gain focus-lose text-input drag-start drag-stop drag).

SXML interface

widgets
(widgets GUI [PARENT] SXML)procedure

Creates widgets based on SXML. If PARENT is specified, use that widget as the parent of the newly created widgets, otherwise create top-level widgets.

Elements must be one of (frame scrollbox label button editbox toggle). Each element has mandatory attributes that correspond to their constructor procedures and optional attributes that correspond to their other setter procedures plus generic setter procedures. The following definition lists summarizes them for quick reference:

Mandatory attributes for all widget types:

x
X coordinate
y
Y coordinate
w
width
h
height

Mandatory attributes for specific widget types:

text
Text for label, button and editbox widgets

Optional attributes for all widget types:

tileset
Tileset surface
hidden?
Hide widget, value must be #t
id
Symbol identifier for lookup with widget-by-id
<event handler type>
Procedure, see handler-set! for the attribute name and function signature of the value

Optional attributes for specific widget types:

icon
List of x, y, w and h attributes for label widgets
align
List as specified in label-alignment-set! for label widgets
style
Style symbol as specified in label-style-set! for label widgets
font
Font for label and editbox widgets
color
Color for label and editbox widgets
position
Index for editbox widgets
checked?
Activation state for toggle widgets
widget-by-id
widget-by-id IDprocedure

Returns either a widget that has been defined previously with the widgets procedure and an id attribute or #f if it couldn't be found.

Examples

Frame with "Hello World!" label (requires a tileset.png and Fontin-Regular.ttf in your cwd):

(use (prefix sdl2 sdl2:)
     (prefix kiwi kw:))

(import (only sdl2-internals unwrap-renderer unwrap-window))

(sdl2:set-main-ready!)
(sdl2:init! '(everything))

(define width 320)
(define height 240)

(define-values (window renderer)
  (sdl2:create-window-and-renderer! width height))

(sdl2:render-draw-color-set! renderer (sdl2:make-color 100 100 100))

(define driver (kw:create-sdl2-driver (unwrap-renderer renderer)
                                      (unwrap-window window)))

(define tileset (kw:load-surface driver "tileset.png"))
(define gui (kw:init! driver tileset))

(define font (kw:load-font driver "Fontin-Regular.ttf" 12))
(kw:gui-font-set! gui font)

(define geometry (kw:rect 0 0 width height))
(define frame (kw:frame gui #f geometry))
(define label (kw:label gui frame "Hello World!" geometry))

(let loop ()
  (when (not (sdl2:quit-requested?))
    (sdl2:render-clear! renderer)
    (kw:process-events! gui)
    (kw:paint! gui)
    (sdl2:delay! 1)
    (sdl2:render-present! renderer)
    (loop)))

(kw:quit! gui)
(sdl2:quit!)

Same example, but with the SXML interface:

(use (prefix sdl2 sdl2:)
     (prefix kiwi kw:))

(import (only sdl2-internals unwrap-renderer unwrap-window))

(sdl2:set-main-ready!)
(sdl2:init! '(everything))

(define width 320)
(define height 240)

(define-values (window renderer)
  (sdl2:create-window-and-renderer! width height))

(sdl2:render-draw-color-set! renderer (sdl2:make-color 100 100 100))

(define driver (kw:create-sdl2-driver (unwrap-renderer renderer)
                                      (unwrap-window window)))

(define tileset (kw:load-surface driver "tileset.png"))
(define gui (kw:init! driver tileset))

(define font (kw:load-font driver "Fontin-Regular.ttf" 12))
(kw:gui-font-set! gui font)

(kw:widgets gui
 `(frame
   (@ (x 0) (y 0) (w ,width) (h ,height))
   (label
    (@ (x 0) (y 0) (w ,width) (h ,height)
       (text "Hello World!")))))

(let loop ()
  (when (not (sdl2:quit-requested?))
    (sdl2:render-clear! renderer)
    (kw:process-events! gui)
    (kw:paint! gui)
    (sdl2:delay! 1)
    (sdl2:render-present! renderer)
    (loop)))

(kw:quit! gui)
(sdl2:quit!)

Further examples can be found in the repository and contain the original set of examples as well as two new ones, a more advanced "Hello World!" and a simple image viewer. The sdl2 and sdl2-image eggs are required to compile and run them.

Notes

License

Copyright (c) 2016, Vasilij Schneidermann

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
   claim that you wrote the original software. If you use this software
   in a product, an acknowledgement in the product documentation would be
   appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
   misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

Version history

0.3

0.2

0.1

Contents »