Canvas snippets: Difference between revisions

Jump to navigation Jump to search
m
→‎Adding GUI Buttons (Layouts): generalize & simplify snippet, add screen shot
m (→‎Adding GUI Labels: simplify & generalize snippet, add dependencies)
m (→‎Adding GUI Buttons (Layouts): generalize & simplify snippet, add screen shot)
Line 117: Line 117:
! Screenshot !! Code !!  
! Screenshot !! Code !!  
|-
|-
| please upload ...||  
| [[File:Canvas-demo-layouts-and-buttons-by-Necolatis.png|thumb|Canvas snippet: buttons and layouts (by Necolatis)]]||  


|
|
{{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.}}
{{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">
<syntaxhighlight lang="nasal" enclose="div">
    # click button
# create a new layout
var myLayout = canvas.HBoxLayout.new();
# assign it to the Canvas
myCanvas.setLayout(myLayout);


    var button = gui.widgets.Button.new(root, style, {})
# click button
        .setText("Click on me")
        .setFixedSize(75, 25);


    button.listen("clicked", func {
var button = canvas.gui.widgets.Button.new(root, canvas.style, {})
.setText("Click on me")
.setFixedSize(75, 25);
 
button.listen("clicked", func {
         # add code here to react on click on button.
         # add code here to react on click on button.
    });
print("Button clicked !");
});


    myLayoutItem.addItem(button);
myLayout.addItem(button);
</syntaxhighlight>
</syntaxhighlight>


Navigation menu