Changeset 33371 in project for wiki/eggref/4/kiwi


Ignore:
Timestamp:
06/03/16 13:16:19 (5 years ago)
Author:
Vasilij Schneidermann
Message:

Add wiki-specific example with and without SXML interface, add notes section

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/kiwi

    r33370 r33371  
    846846Mandatory attributes for specific widget types:
    847847
    848 ; text : Label, button and editbox widgets
     848; text : Text for label, button and editbox widgets
    849849
    850850Optional attributes for all widget types:
     
    852852; tileset : Tileset surface
    853853; hidden? : Hide widget, value must be {{#t}}
    854 ; id : Adds an identifier for lookup with {{widget-by-id}}
     854; id : Symbol identifier for lookup with {{widget-by-id}}
    855855; <event handler type> : Procedure, see {{handler-set!}} for the attribute name and function signature of the value
    856856
    857857Optional attributes for specific widget types:
    858858
    859 ; icon : Label and button widgets
     859; icon : List of {{x}}, {{y}}, {{w}} and {{h}} attributes for label and button widgets
    860860; align : Label widgets
    861861; style : Label widgets
    862 ; font : Label, button and editbox widgets
    863 ; color : Label, button and editbox widgets
    864 ; position : Editbox widgets
     862; font : Font for label, button and editbox widgets
     863; color : Color for label, button and editbox widgets
     864; position : Index for editbox widgets
    865865
    866866===== widget-by-id
     
    874874=== Examples
    875875
    876 Examples can be found in the repository and contain
    877 [[https://github.com/mobius3/KiWi/tree/master/examples|the original
    878 set of examples]] as well as two new ones. The [[sdl2]] and
     876Frame with "Hello World!" label (requires a {{tileset.png}} and
     877{{Fontin-Regular.ttf}} in your cwd):
     878
     879<enscript highlight="scheme">
     880(use (prefix sdl2 sdl2:)
     881     (prefix kiwi kw:))
     882
     883(import (only sdl2-internals unwrap-renderer unwrap-window))
     884
     885(sdl2:set-main-ready!)
     886(sdl2:init! '(everything))
     887
     888(define width 320)
     889(define height 240)
     890
     891(define-values (window renderer)
     892  (sdl2:create-window-and-renderer! width height))
     893
     894(sdl2:render-draw-color-set! renderer (sdl2:make-color 100 100 100))
     895
     896(define driver (kw:create-sdl2-driver (unwrap-renderer renderer)
     897                                      (unwrap-window window)))
     898
     899(define tileset (kw:load-surface driver "tileset.png"))
     900(define gui (kw:init! driver tileset))
     901
     902(define font (kw:load-font driver "Fontin-Regular.ttf" 12))
     903(kw:gui-font-set! gui font)
     904
     905(define geometry (kw:rect 0 0 width height))
     906(define frame (kw:frame gui #f geometry))
     907(define label (kw:label gui frame "Hello World!" geometry))
     908
     909(let loop ()
     910  (when (not (sdl2:quit-requested?))
     911    (sdl2:render-clear! renderer)
     912    (kw:process-events! gui)
     913    (kw:paint! gui)
     914    (sdl2:delay! 1)
     915    (sdl2:render-present! renderer)
     916    (loop)))
     917
     918(kw:quit! gui)
     919(sdl2:quit!)
     920</enscript>
     921
     922Same example, but with the SXML interface:
     923
     924<enscript highlight="scheme">
     925(use (prefix sdl2 sdl2:)
     926     (prefix kiwi kw:))
     927
     928(import (only sdl2-internals unwrap-renderer unwrap-window))
     929
     930(sdl2:set-main-ready!)
     931(sdl2:init! '(everything))
     932
     933(define width 320)
     934(define height 240)
     935
     936(define-values (window renderer)
     937  (sdl2:create-window-and-renderer! width height))
     938
     939(sdl2:render-draw-color-set! renderer (sdl2:make-color 100 100 100))
     940
     941(define driver (kw:create-sdl2-driver (unwrap-renderer renderer)
     942                                      (unwrap-window window)))
     943
     944(define tileset (kw:load-surface driver "tileset.png"))
     945(define gui (kw:init! driver tileset))
     946
     947(define font (kw:load-font driver "Fontin-Regular.ttf" 12))
     948(kw:gui-font-set! gui font)
     949
     950(kw:widgets gui
     951 `(frame
     952   (@ (x 0) (y 0) (w ,width) (h ,height))
     953   (label
     954    (@ (x 0) (y 0) (w ,width) (h ,height)
     955       (text "Hello World!")))))
     956
     957(let loop ()
     958  (when (not (sdl2:quit-requested?))
     959    (sdl2:render-clear! renderer)
     960    (kw:process-events! gui)
     961    (kw:paint! gui)
     962    (sdl2:delay! 1)
     963    (sdl2:render-present! renderer)
     964    (loop)))
     965
     966(kw:quit! gui)
     967(sdl2:quit!)
     968</enscript>
     969
     970Further examples can be found in
     971[[https://github.com/wasamasa/kiwi/examples|the repository]] and
     972contain [[https://github.com/mobius3/KiWi/tree/master/examples|the
     973original set of examples]] as well as two new ones, a more advanced
     974"Hello World!" and a simple image viewer. The [[sdl2]] and
    879975[[sdl2-image]] eggs are required to compile and run them.
     976
     977=== Notes
     978
     979* Unlike many other GUI toolkits, KiWi requires you to use your own
     980  resources.  Make sure your font and tileset can be found when
     981  running your application, otherwise it will segfault.
     982* There is no ready-made main loop implementation, therefore you'll
     983  have to write your own.  While this is sort of a hassle, it allows
     984  for more flexibility and better integration with your application
     985  than with GUI toolkits not offering that option.
     986* Increase the delay time in your main loop to lower the FPS and
     987  overall CPU usage.
     988* It's strongly recommended to use top-level definitions for the
     989  driver, GUI and its font and tileset to avoid references to them
     990  being garbage-collected early, possibly resulting in a segfault.
     991* Refer to [[https://github.com/mobius3/KiWi/tree/master/src|the KiWi
     992  headers]] for documentation on details not covered in this wiki
     993  page, such as how geometries work, creation of custom widgets and
     994  any functionality without bindings.
     995* If you want to create a new tileset, use
     996  [[https://github.com/mobius3/KiWi/raw/master/examples/tileset/tileset.xcf|tileset.xcd]]
     997  from the KiWi repository as basis.
     998* It's strongly recommended to use the {{(on-exit)}} and
     999  {{(current-exception-handler)}} parameters during development to
     1000  exit the application properly at all times.  This has been omitted
     1001  from the examples for brevity.  See
     1002  [[http://wiki.call-cc.org/eggref/4/sdl2#ensuring-proper-clean-up|the
     1003  relevant sdl2 egg section]] for further details.
    8801004
    8811005=== License
Note: See TracChangeset for help on using the changeset viewer.