20,741
edits
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 !! | ||
|- | |- | ||
| | | [[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 = 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!"); | |||
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> | ||
|- | |- | ||