Canvas snippets: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
Line 2: Line 2:
{{Stub}}
{{Stub}}
{{WIP}}
{{WIP}}
{{Canvas Navigation}}


== Creating a Canvas GUI Window ==
== Creating a Canvas GUI Window ==
Line 19: Line 21:
</syntaxhighlight>
</syntaxhighlight>


{{Canvas Navigation}}
== Canvas Input Dialog ==
 
<syntaxhighlight lang="nasal" enclose="div">
# create a new InputDialog with a title, label, and a callback
canvas.InputDialog.getText("Input Dialog Title", "Please enter some text", func(btn,value) {
    if (value) gui.popupTip("You entered: "~value);
});
</syntaxhighlight>

Revision as of 20:15, 14 September 2014

This article is a stub. You can help the wiki by expanding it.
WIP.png Work in progress
This article or section will be worked on in the upcoming hours or days.
See history for the latest developments.


Creating a Canvas GUI Window

Note  This example uses so called method chaining, if you're not familiar with the concept, please see: Method Chaining.
This is what the Nasal/Canvas snippet will look like once you pasted it into the Nasal Console and click "Execute".
# create a new window, dimensions are 320 x 160, using the dialog decoration (i.e. titlebar)
var window = canvas.Window.new([320,160],"dialog");

# adding a canvas to the new window and setting up background colors/transparency
var myCanvas = window.createCanvas().setColorBackground(1,1,1,1);

# creating the top-level/root group which will contain all other elements/group
var root = myCanvas.createGroup();

Canvas Input Dialog

# create a new InputDialog with a title, label, and a callback
canvas.InputDialog.getText("Input Dialog Title", "Please enter some text", func(btn,value) {
    if (value) gui.popupTip("You entered: "~value);
});