-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
80 lines (71 loc) · 2.63 KB
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
(ns strigui.core
(:require [strigui.button :as btn]
[strigui.label :as lbl]
[strigui.input :as inp]
[strigui.stacks :as st]
[strigui.window :as wnd]
[strigui.widget :as wdg]))
(defn find-by-name
[name]
(first (filter #(= (wdg/widget-name %) name) @wdg/widgets)))
(defn remove!
[name]
(when-let [box-to-remove (find-by-name name)]
(wdg/unregister (:canvas @wnd/context) box-to-remove)))
(defn update!
"name - name of the widget
key - either single key or vector of keys
value - the new property value"
[name key value]
(when-let [w (find-by-name name)]
(wdg/unregister (:canvas @wnd/context) w )
(let [keys (if (seqable? key) key (vector key))]
(wdg/register (:canvas @wnd/context) (assoc-in w keys value)))))
(defn window [width height]
(wnd/create-window width height))
(defn button
"name - name of the element
text - text displayed inside the button
args - map of:
x - x coordinate of top left corner
y - y coordinate of top left corner
color - vector consisting of [background-color font-color]
min-width - the minimum width"
[name text args]
(wdg/register (:canvas @wnd/context) (btn/button (:canvas @wnd/context) name text args)))
(defn label
"name - name of the element
text - text displayed inside the button
args - map of:
x - x coordinate of top left corner
y - y coordinate of top left corner
color - vector consisting of [font-color]
align - vector consisting of either :right :center :left
font-style - vector consisting of either :bold :italic :italic-bold
font-size - number"
[name text args]
(wdg/register (:canvas @wnd/context) (lbl/create (:canvas @wnd/context) name text args)))
(defn input
"name - name of the element
text - text displayed inside the button
args - map of:
x - x coordinate of top left corner
y - y coordinate of top left corner
color - vector consisting of [background-color font-color]
min-width - the minimum width"
[name text args]
(wdg/register (:canvas @wnd/context) (inp/input (:canvas @wnd/context) name text args)))
(defn stacks
"name - name of the elemnt
item-list - list consisting of the number of
items on each stack for example:
(5 4 5) for 3 stacks with 5 on the 1st,
4 on the 2nd and 5 and the last stack
args - map of:
x - x coordinate of top left corner
y - y coordinate of top left corner"
[name item-list args]
(wdg/register (:canvas @wnd/context) (st/create (:canvas @wnd/context) name item-list args)))
(defn info
[text]
(wnd/display-info @wnd/context text))