Spry takes one more step towards being interesting?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Spry takes one more step towards being interesting?

Göran Krampe
Hey!

ESUG is going on (how I wish I could have been there!) and I just spent
a few hours to take an important step for Spry (sprylang.org) that I
hope will make things even more interesting: UI

So... I took the neat wrapper of libui (basis of Go's new UI) that
Andreas (author of Nim) has generated, then I hooked up a few primitives
that I needed (9 so far) so that I could write this Spry program:
--------------------------------------
# Initialize libui
uiInit

# Create a new Window
win = newWindow "Spry Awakens" 200 200 true

# Set a handler on closing window
win onClosing: [
   win message: "Time to close!" title: "Sorry..."
   echo "Okidoki closing window..."
   controlDestroy win
   echo "And quitting..."
   uiQuit
]

# Show the window
win show

# Enter libui's event loop
win uiMain
--------------------------------------

Screenshot: http://pasteboard.co/btzf03EMR.png

As you can see it creates a Window, hooks in an onClosing handler,
inside the handler it calls message:title: to show an alert and then
destroys window and quits libui.

Then we show the window and enter libuis event loop.

The above can be stuffed into a script and run like "spry win.sy" or use
the hashbang trick. BUT... even nicer, we can wrap it up in a Nim
program like this:
----------------------------------
# Spry sample single UI binary

import spryvm, spryio, spryoo, sprymodules, spryui
var spry = newInterpreter()
spry.addIO()
spry.addOO()
spry.addModules()
spry.addUI()

discard spry.eval("""[

# Initialize libui
uiInit

# Create a new Window
win = newWindow "Spry Awakens" 200 200 true

# Set a handler on closing window
win onClosing: [
   win message: "Time to close!" title: "Sorry..."
   echo "Okidoki closing window..."
   controlDestroy win
   echo "And quitting..."
   uiQuit
]

# Show the window
win show

# Enter libui's event loop
win uiMain
]""")
------------------------------

We can then compile it, strip it, etc into a single 51kb 64 bit Linux
binary!

I haven't managed to compile and link it fully statically (need to mess
around with gtk3, libui etc), so it probably doesn't run on your system
(given libui.so missing), but here is the binary:

http://krampe.se/win

I presume it would run fine if you first built and installed libui:

https://github.com/andlabs/libui

regards, Göran