Canvas snippets: Difference between revisions

Jump to navigation Jump to search
m
→‎Adding GUI Labels: simplify & generalize snippet, add dependencies
m (→‎Adding Text Elements: adapt the example so that it works properly with the two canvas setup stubs at the beginning of the article)
m (→‎Adding GUI Labels: simplify & generalize snippet, add dependencies)
Line 91: Line 91:
! Screenshot !! Code !!  
! Screenshot !! Code !!  
|-
|-
| please upload ...||  
| [[File:Canvas-Layout-Label-example-by-Necolatis.png|thumb|Canvas demo: Layouts and Labels (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">
# create a new layout
var myLayout = canvas.HBoxLayout.new();
# assign it to the Canvas
myCanvas.setLayout(myLayout);


    var label = gui.widgets.Label.new(root, style, {wordWrap: 0}); # wordwrap: 0 will disable wordwrapping, to enable it use 1 instead
var label = canvas.gui.widgets.Label.new(root, canvas.style, {wordWrap: 0}); # wordwrap: 0 will disable wordwrapping, to enable it use 1 instead
    label.setText("Hello world.");
label.setText("Hello World!");
    myLayoutItem.addItem(label);
myLayout.addItem(label);
 
var label2 = canvas.gui.widgets.Label.new(root, canvas.style, {wordWrap: 0}); # wordwrap: 0 will disable wordwrapping, to enable it use 1 instead
label2.setText("Hello FlightGear");
myLayout.addItem(label2);
</syntaxhighlight>
</syntaxhighlight>
|-
|-

Navigation menu