用红色语言制作GUI对象

时间:2017-09-16 04:47:05

标签: user-interface object rebol red

我有一个小面板的简单代码:

    FAILURE: Build failed with an exception.

    * Where:
    Script
    'C:\Users\pini\Desktop\Drivercheckcall\platforms\android\phonegap-plugin-push\DriverCheckCall-push.gradle' line:
    38

    * What went wrong:
    A problem occurred evaluating root project 'android'.
    > Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlugin']
        > For input string: "+"

    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

    BUILD FAILED

    Total time: 23.062 secs
    Error: cmd: Command failed with exit code 1 Error output:
    FAILURE: Build failed with an exception.

    * Where:
    Script
    'C:\Users\pini\Desktop\Drivercheckcall\platforms\android\phonegap-plugin-push\DriverCheckCall-push.gradle' line:
    38

    * What went wrong:
    A problem occurred evaluating root project 'android'.
    > Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlugin']
        > For input string: "+"

    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

但是我必须把它们中的两个放在一个窗口上。我想创建单个对象类并从中创建2个对象。我看到可以按如下方式创建对象:

view [
    t: text "label"
    f: field
    button "Click here" [t/text: f/text]    ]

但我得到以下错误:

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 ,但只能使用do

进行管理
does

3 个答案:

答案 0 :(得分:2)

我猜你要找的是样式而不是对象才能创建布局。到目前为止,Red还没有官方的样式化功能。但您可以像这样动态创建布局

view repeat i 2 [
    tname: to-word rejoin ['t i]
    fname: to-word rejoin ['f i]
    append v: [] compose/deep [ 
        (to-set-word tname) text "label"
        (to-set-word fname) field
        button "click here"   [
          (to-set-path  compose [(tname) text])  
          (to-path  compose [(fname) text])
        ] 
    ] 
]

您可以多次将预定义的单词块附加到要查看的块中,您将获得重复的元素。

 txt_btn: [
    t: text "label"
    f: field
    button "Click here" [t/text: f/text] 
 ] 
 view append append [] txt_btn txt_btn

当您在块中引用命名元素时,会出现问题。但是一个词不能指向重复元素的多个元素,因此在完整解决方案中使用compose来创建唯一的名称。

也许Red中有一个错误,因为我认为compose/deep也会在内部做括号而不需要更多的编写 -

答案 1 :(得分:2)

要使用对象而不是 VID 方言,请将view替换为layout

lay: layout [
    t: text "label"
    f: field
    button "Click here" [t/text: f/text]
]

view lay

然后,您可以像检查任何其他对象一样进行检查:?? lay

例如,要使用lay访问pane的内容:

>> ? lay/pane/1

但是,更有用的功能可能是dump-face

>> dump-face lay
 Type: window Style: none Offset: 833x548 Size: 270x45 Text: "Red: untitled"
     Type: text Style: text Offset: 10x10 Size: 80x24 Text: "label"
     Type: field Style: field Offset: 100x10 Size: 80x24 Text: none
     Type: button Style: button Offset: 190x9 Size: 70x25 Text: "Click here"
== make object! [
    type: 'window
    offset: 833x548
 ...

panel对于将对象组合在一起非常有用:

>> dump-face blay: layout [p: panel button "hi"]
 Type: window Style: none Offset: none Size: 292x220 Text: none
     Type: panel Style: panel Offset: 10x10 Size: 200x200 Text: none
     Type: button Style: button Offset: 220x9 Size: 62x25 Text: "hi"
== make object! [
    type: 'window
    offset: none
    ...

但使用compose VID 方言可能更容易首先构建内容。

另见this question

答案 2 :(得分:1)

  

我想创建单个对象类并从中创建2个对象。

Red中没有对象 class 系统,因此在尝试更复杂的GUI构造之前,您应该首先尝试掌握基本的Red概念。 Red是一种非常灵活的面向数据的语言,因此您可以利用它,例如,构建参数化块模板,并组装它们以形成正确的VID代码块。这是一个例子:

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开始),欢迎您在red/help Gitter房间提出实时问题。