20,741
edits
(→Ideas) |
|||
Line 217: | Line 217: | ||
demo.start();</syntaxhighlight> | demo.start();</syntaxhighlight> | ||
== GUI frontend == | |||
<syntaxhighlight lang="nasal"> | |||
var (width,height) = (320,200); | |||
var title = 'GCA Dialog '; | |||
# create a new window, dimensions are WIDTH x HEIGHT, using the dialog decoration (i.e. titlebar) | |||
var window = canvas.Window.new([width,height],"dialog").set('title',title); | |||
## | |||
# the del() function is the destructor of the Window | |||
# which will be called upon termination (dialog closing) | |||
# you can use this to do resource management (clean up timers, listeners or background threads) | |||
window.del = func() | |||
{ | |||
print("Cleaning up window:",title,"\n"); | |||
# explanation for the call() technique at: http://wiki.flightgear.org/Object_oriented_programming_in_Nasal#Making_safer_base-class_calls | |||
call(canvas.Window.del, [], me); | |||
}; | |||
# adding a canvas to the new window and setting up background colors/transparency | |||
var myCanvas = window.createCanvas().set("background", canvas.style.getColor("bg_color")); | |||
# creating the top-level/root group which will contain all other elements/group | |||
var root = myCanvas.createGroup(); | |||
# create a new layout | |||
var myLayout = canvas.VBoxLayout.new(); | |||
# assign it to the Canvas | |||
myCanvas.setLayout(myLayout); | |||
var setupLabeledInput = func(root, layout, text, default_value, focus) { | |||
var label = canvas.gui.widgets.Label.new(root, canvas.style, {wordWrap: 0}); | |||
label.setText(text); | |||
layout.addItem(label); | |||
var input = canvas.gui.widgets.LineEdit.new(root, canvas.style, {}); | |||
layout.addItem(input); | |||
input.setText(default_value); | |||
if (focus) | |||
input.setFocus(); | |||
} | |||
var inputs = [ | |||
{text: 'Aircraft root property:', default_value:'/position', focus:1}, | |||
{text: 'Airport:', default_value:'KSFO', focus:0}, | |||
{text: 'Runway:', default_value:'28R', focus:0}, | |||
{text: 'Glidepath:', default_value:'3.00', focus:0}, | |||
]; | |||
foreach(var input; inputs) { | |||
setupLabeledInput(root, myLayout, input.text, input.default_value, input.focus); | |||
} | |||
# click button | |||
var button = canvas.gui.widgets.Button.new(root, canvas.style, {}) | |||
.setText("Start/Stop") | |||
.setFixedSize(75, 25); | |||
button.listen("clicked", func { | |||
# add code here to react on click on button. | |||
print("Button clicked !"); | |||
}); | |||
myLayout.addItem(button); | |||
</syntaxhighlight> | |||
== Ideas == | == Ideas == | ||
* make the touchdown point configurable ? | * make the touchdown point configurable ? | ||
* Implement the whole thing as a GUI dialog for prototyping purposes (e.g. allow the aircraft/airport etc to be entered/changed easily) {{Progressbar|60}} | * Implement the whole thing as a GUI dialog for prototyping purposes (e.g. allow the aircraft/airport etc to be entered/changed easily) {{Progressbar|60}} |