用Red语言制作GUI对象 [英] Making GUI objects in Red language
问题描述
对于一个小面板,我有以下简单的代码:
I have following simple code for a small panel:
view [
t: text "label"
f: field
button "Click here" [t/text: f/text] ]
但是我必须将它们中的2个放在一个窗口上.我想创建单个对象类,并从中创建2个对象.我看到可以按如下方式创建对象:
But I have to make 2 of them and put them on one window. I want to create single object class and make 2 objects out of it. I see that objects can be created as follows:
obj: object [
view [
t: text "label"
f: field
button "Click here" [t/text: f/text] ] ]
view [
obj
obj ]
但是出现以下错误:
*** Script Error: VID - invalid syntax at: [obj obj]
*** Where: do
*** Stack: view layout cause-error
这怎么办?谢谢你的帮助.
How can this be done? Thanks for your help.
我尝试使用do
,但只能使用does
进行管理:
I tried with do
but could manage only with does
:
myview: object [
show: does [view[
below
t: text "1st time"
f: field "Enter value"
button "Click here" [f/text "clicked"]
area] ] ]
myview/show
print "READY TO SHOW 2nd OBJECT: "
myview2: copy myview
myview2/show
推荐答案
我想创建单个对象类,并从中创建2个对象.
I want to create single object class and make 2 objects out of it.
Red中没有对象 class 系统,因此在尝试更复杂的GUI构造之前,您应该首先尝试掌握Red的基本概念. Red是一种非常灵活的面向数据的语言,因此您可以利用它,例如,通过构建参数化的块模板,然后将它们组装起来以形成正确的VID代码块,从而发挥自己的优势.这是一个示例:
There is no object class system in Red, so you should really try first to grasp the basic Red concepts before trying more complex GUI constructs. Red is a very flexible data-oriented language, so you can use that to your advantage by, for example, building parametrized block templates, and assembling them to form a correct block of VID code. Here is an example:
make-row: func [label [string!] but-label [string!]][
compose [
t: text (label)
f: field
b: button (but-label) [face/extra/1/text: face/extra/2/text]
do [b/extra: reduce [t f]]
]
]
view compose [
(make-row "label" "Click") return
(make-row "label2" "Click2")
]
了解面部树(类似于HTML DOM,就更简单了),是掌握Red的GUI系统的重要组成部分.由于尚无太多文档(您可以从 http://docs.red-lang.org ),欢迎您在红色/帮助垃圾室中提出现场问题.
Understanding the face tree (analog to the HTML DOM, just way simpler), is an important part of mastering Red's GUI system. As there is no much documentation yet (you can start with http://docs.red-lang.org), you are welcome to ask live questions on red/help Gitter room.
这篇关于用Red语言制作GUI对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!