Canvas snippets: Difference between revisions

Jump to navigation Jump to search
→‎Adding GUI Buttons: Added 2 minimal examples
(→‎Adding GUI Labels: Adding minimalistic example.)
(→‎Adding GUI Buttons: Added 2 minimal examples)
Line 87: Line 87:


== Adding GUI Buttons ==
== Adding GUI Buttons ==
{| class="wikitable"
|-
! Screenshot !! Code !!
|-
| please upload ...||
|
{{Note|This assumes that you already have a top-level root group set up, and named it '''root''', just change this variable if you want it to be rendered elsewhere. It also assumes you have a Layout item setup and called '''myLayoutItem'''. You must also have either setup a layout called '''style''' or be calling this from inside a dialog showed using canvas.loadDialog(dialog), which will define it for you.}}
<syntaxhighlight lang="nasal" enclose="div">
    # click button
    var button = gui.widgets.Button.new(root, style, {})
        .setText("Click on me")
        .setFixedSize(75, 25);
    button.listen("clicked", func {
        # add code here to react on click on button.
    });
    myLayoutItem.addItem(button);
</syntaxhighlight>
<syntaxhighlight lang="nasal" enclose="div">
    # toggle button
    var button = gui.widgets.Button.new(root, style, {})
        .setText("Toggle me")
        .setCheckable(1) # this indicates that is should be a toggle button
        .setChecked(0) # depressed by default
        .setFixedSize(75, 25);
    button.listen("toggled", func (e) {
        if( e.detail.checked ) {
            # add code here to react on button being depressed.
        } else {
            # add code here to react on button not being depressed.
        }
    });
    myLayoutItem.addItem(button);
</syntaxhighlight>
|-
|}


== Using Layouts ==
== Using Layouts ==
579

edits

Navigation menu