20,741
edits
Line 57: | Line 57: | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
io.load_nasal( getprop("/sim/fg-root") ~ "/Nasal/canvas/widgets/loglist.nas" ); | io.load_nasal( getprop("/sim/fg-root") ~ "/Nasal/canvas/widgets/loglist.nas" ); | ||
</syntaxhighlight> | |||
To implement the widget-specific logic, you can access the parent canvas using the '''cmdarg()''' API: | |||
<syntaxhighlight lang="php"> | |||
var my_canvas = canvas.get( cmdarg() ); # this will get a handle to the parent canvas | |||
var root = my_canvas.createGroup(); | |||
var text = root.createChild("text") | |||
.setText("some custom canvas widget") | |||
.setTranslation(10, 30) | |||
.setAlignment("left-top") | |||
.setFontSize(20) | |||
.setFont("LiberationFonts/LiberationSans-Regular.ttf") | |||
.set("max-width", 380) | |||
.setColor(1,0,0); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 82: | Line 97: | ||
<pref-height>200</pref-height> | <pref-height>200</pref-height> | ||
<padding>6</padding> | <padding>6</padding> | ||
</canvas> | |||
</syntaxhighlight> | </syntaxhighlight> |