Liking cljdoc? Tell your friends :D

strigui

Clojars Project

A small straightforward GUI library that can be extended with new Widgets. At the moment, it only contains widgets for a button, input and a label plus the window component itself. The goal is to provide an easy to use tool to create a simple UI in Clojure. It should provide a few simple widgets to start with, but you can create your own widgets too. It uses Clojure2d underneath. So anything that can be drawn could potentially be a widget (like the game board in Dame).

Note: This is in an alpha stage. I use it mainly to learn Clojure and to write simple desktop apps. Any suggestion or help on coding is absolutely welcome!

See Changes

In project.clj:

:dependencies [[strigui "0.0.1-alpha14"]]

Example

You need the core namespace.

(ns example.core
  (:require [strigui.core :as gui]))

Create the main window via

(gui/window! 600 600)

Basic widgets like buttons, input boxes and labels can be created via

(gui/label! "welcome" "Welcome to Strigui" {:x 190 :y 100
                                             :color [:green]
                                             :font-size 20 :font-style [:bold]})
(gui/button! "click" "Click me" {:x 400 :y 200 :color [:white :black]})
(gui/input! "input" "" {:x 100 :y 150 :color [:white :red] :min-width 420})

The parameters are the name of the widget, the value and a map for the position and optional settings like color, selected?, focused?, can-tab?, can-move? etc. ... The name is used when widgets are modified.

Events can be attached by using the chosen widget name.

(gui/update! "click" :events {:mouse-clicked (fn [wdg]
                                                (gui/info "Button A pressed"))})

A widget can be removed, updated with

(gui/update! "welcome" :value "A new title")
(gui/remove! "input")

It is also possible to retrieve a widget by name via

(gui/find-by-name "click")

Custom widgets can be defined by creating a record that implements the protocol of strigui.widget.Widget

(defprotocol Widget 
    "collection of functions around redrawing widgets, managing the border etc. ..."
  (coord [this canvas] "gets the coordinates of the widget")
  (defaults [this] "attach default values")
  (draw [this canvas] "draw the widget, returns the widget on success"))

See example for reference

A custom widget could be invoked via

...
(:require ...
            [strigui-sample.widget-stacks :as st])
...
(gui/create! (st/->Stack "stacks" '(5 1 8 2 0 3 0 5 7) {:x 100 :y 400}))

As mentioned in the begining, Dame is another example.

The game board and the 2 buttons are strigui widgets.

Edn file

Widgets can now be loaded from a edn file too.

Example: gui-test.edn

{:window [600 600 "From a edn file"]
 :strigui.label/Label [["welcome" "Welcome to Strigui" {:x 190 :y 100
                                                      :color [:green]
                                                      :font-size 20 :font-style [:bold]
                                                      :can-move? true}]]
 :strigui.button/Button [["click" "Click me" {:x 400 :y 250 :z 10 :color [:white :black] :can-tab? true}]]
 :strigui.input/Input [["input" "" {:x 100 :y 150 :color [:white :red] :min-width 420 :selected? true :can-tab? true}]
                       ["input1" "" {:x 100 :y 200 :color [:white :red] :min-width 420 :can-tab? true}]]}

And load it in your clj file via

(ns example.core
  (:require [strigui.core :as gui]))

....
(gui/from-file "gui-test.edn")
...

If a widget name already exists, the widget gets unregistered and replaced by the new widget.

Releasing standalone apps:

When releasing an app which uses strigui, delete the /org/bytedeco directory inside your jar file. This will make your jar about 960 mb smaller. I believe that is being used in clojure2d when working with images. There must be an alternative way skipping this dependency by default.

Can you improve this documentation? These fine people already did:
MikeHardIce & OgreBelly
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close