Skip to content

Commit f3f61cf

Browse files
committed
update docs
1 parent 61c5600 commit f3f61cf

1 file changed

Lines changed: 154 additions & 1 deletion

File tree

docs/第四章 GUI库/4.2 gui库使用.md

Lines changed: 154 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,160 @@ gui是基于opengl写的一款鸭子gui,简单易用。
1313
一切基于`widget`,大多数方法都是`widget`操作,`widget-set-attrs`设置属性。
1414
常见的基本组件有`dialog button image text scroll edit video tab tree view pop progress`,基本上是3个参数,宽度、高度、内容。
1515

16-
## 1.2 简单例子
16+
## 1.2 组件
17+
18+
19+
### 1.2.1 按钮
20+
定义一个按钮组件
21+
```scheme
22+
(button 120.0 30.0 "主要")
23+
```
24+
定义一个checkbox
25+
```scheme
26+
(define (checkbox w h t)
27+
(let ((box (text w h t))
28+
(icon-check (load-texture "check.png"))
29+
(icon-checked (load-texture "checked.png"))
30+
)
31+
(widget-set-events box 'click (lambda (w p type data)
32+
(if (eq? #t (widget-get-attrs w 'checked))
33+
(widget-set-attrs w 'checked #f)
34+
(widget-set-attrs w 'checked #t)
35+
)))
36+
(widget-add-draw
37+
box
38+
(lambda (w p)
39+
(let ((x (widget-get-attr w %gx))
40+
(y (widget-get-attr w %gy))
41+
(checked (widget-get-attrs w 'checked))
42+
)
43+
(if (eq? #t checked)
44+
(draw-image (+ 6.0 x) (+ y 6.0) 20.0 20.0 icon-checked)
45+
(draw-image (+ 6.0 x) (+ y 6.0) 20.0 20.0 icon-check)
46+
))))
47+
box
48+
)
49+
)
50+
(checkbox 120.0 30.0 "我是checkbox")
51+
```
52+
53+
### 1.2.2 图片
54+
定义一个图片组件
55+
```scheme
56+
(image 180.0 180.0 "duck.png")
57+
```
58+
自定义网络下载图片组件
59+
```scheme
60+
(define (image-net w h src)
61+
(let ((img (image w h src))
62+
(file-name (format "~a.jpg" (string-hash src))))
63+
(widget-set-attrs img 'mode 'center-crop)
64+
(if (file-exists? file-name)
65+
(begin
66+
(widget-set-attrs img 'src file-name)
67+
(widget-set-attrs img 'load #f))
68+
(fork-thread
69+
(lambda ()
70+
(let ((file (url->file file-name src) ))
71+
(if (file-exists? file)
72+
(begin
73+
(widget-set-attrs img 'src file-name)
74+
(widget-set-attrs img 'load #f)
75+
(window-post-empty-event)
76+
))
77+
)
78+
))
79+
)
80+
img
81+
))
82+
;;使用图片下载
83+
(image-net 180.0 180.0 "http://www.cosplayjia.com/up/spw/img/171220/1712200840035a39b16346c5a/5a39b1646c7ff.jpg")
84+
```
85+
86+
### 1.2.3 文本
87+
```scheme
88+
(text 120.0 30.0 "我是文本文本,只读")
89+
```
90+
91+
### 1.2.3 对话框
92+
```scheme
93+
(dialog 430.0 10.0 230.0 600.0 "视频demo")
94+
```
95+
96+
### 1.2.4 树
97+
```scheme
98+
(tree 200.0 2500.0 "根节点")
99+
```
100+
自定义带图标的树
101+
```scheme
102+
(define (icon-tree w h text)
103+
(let ((it (tree w h text))
104+
(file-icon (load-texture "file-text.png"))
105+
(dir-icon (load-texture "folder.png"))
106+
)
107+
(widget-add-draw
108+
it
109+
(lambda (w p)
110+
(let ((x (vector-ref w %gx))
111+
(y (vector-ref w %gy)))
112+
(if (or (null? (widget-get-attrs w 'dir)) (<= (length (widget-get-child w) ) 0))
113+
(draw-image (+ -20.0 x) (+ y 4.0) 15.0 15.0 dir-icon)
114+
(draw-image (+ -20.0 x) (+ y 4.0) 15.0 15.0 dir-icon))
115+
)
116+
))
117+
(widget-set-padding it 15.0 20.0 20.0 20.0)
118+
it
119+
))
120+
121+
(icon-tree 200.0 200.0 (format "节点~a\n" i))
122+
```
123+
124+
125+
### 1.2.5 文本编辑
126+
```scheme
127+
(edit 260.0 120.0 "scheme-lib QQ群:Lisp兴趣小组239401374 啊哈哈")
128+
```
129+
130+
设置编辑属性
131+
```scheme
132+
;;显示行号
133+
(widget-set-attrs editor 'show-no 1)
134+
;;设置行号颜色
135+
(widget-set-attrs editor 'lineno-color #xff6272a4)
136+
;;设置选择背景色
137+
(widget-set-attrs editor 'select-color #xff44475a)
138+
;;设置光标颜色
139+
(widget-set-attrs editor 'cursor-color #xfff8f8f0)
140+
;;设置字体大小
141+
(widget-set-attrs editor 'font-size 20.0)
142+
(widget-set-attrs editor 'font-line-height 1.2)
143+
```
144+
145+
146+
### 1.2.6 视频
147+
```scheme
148+
(video (/ 640.0 3.0) (/ 360.0 3) "http://vfx.mtime.cn/Video/2019/02/04/mp4/190204084208765161.mp4")
149+
```
150+
151+
### 1.2.7 标签
152+
```scheme
153+
(tab 450.0 300.0 (list "标签1" "标签2" "标签3" ))
154+
```
155+
156+
### 1.2.8 容器
157+
```scheme
158+
(view 260.0 120.0)
159+
```
160+
### 1.2.9 弹出
161+
```scheme
162+
(pop 100.0 40.0 "根节点")
163+
```
164+
### 1.2.10 进度条
165+
```scheme
166+
(progress 200.0 10.0 20.0)
167+
```
168+
169+
## 1.3 简单例子
17170
```scheme
18171
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19172
;;Copyright 2016-2080 evilbinary.

0 commit comments

Comments
 (0)