20,741
edits
Line 258: | Line 258: | ||
Once the underlying script is working well enough, we can look into providing a GUI on top of the script using the Canvas GUI library: | Once the underlying script is working well enough, we can look into providing a GUI on top of the script using the Canvas GUI library: | ||
<syntaxhighlight lang="nasal"> | <syntaxhighlight lang="nasal"> | ||
var (width,height) = (320, | var (width,height) = (320,350); | ||
var title = 'GCA Dialog '; | var title = 'GCA Dialog '; | ||
# create a new window, dimensions are WIDTH x HEIGHT, using the dialog decoration (i.e. titlebar) | # 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); | var window = canvas.Window.new([width,height],"dialog").set('title',title); | ||
## | ## | ||
Line 296: | Line 295: | ||
layout.addItem(input); | layout.addItem(input); | ||
input.setText(default_value); | input.setText(default_value); | ||
## TODO: add widget to hash | |||
if (focus) | if (focus) | ||
Line 302: | Line 303: | ||
var validateAircraftRoot = func(input) { | var validateAircraftRoot = func(input) { | ||
var root = props.getNode(input); | |||
if (root == nil) return 1; # error | |||
var required_props = ['altitude-ft', 'longitude-deg', 'latitude-deg']; | |||
foreach(var rp; required_props) { | |||
if (root.getNode(rp) == nil) return 1; | |||
} | } | ||
return 0; # valid root node | |||
} | } | ||
var | var validationHelpers = { | ||
} | |||
'AircraftRoot': func(input) { | |||
return 0; | |||
}, | |||
'Airport': func(input) { | |||
return 0; | |||
}, | |||
'Runway': func(input) { | |||
return 0; | |||
}, | |||
'FinalApproach': func(input) { | |||
return 0; | |||
}, | |||
'Glidepath': func(input) { | |||
return 0; | |||
}, | |||
'SafetySlope': func(input) { | |||
return 0; | |||
}, | |||
'DecisionHeight': func(input) { | |||
return 0; | |||
}, | |||
'TouchdownOffset': func(input) { | |||
return 0; | |||
}, | |||
}; # validationHelpers; | |||
} | |||
var inputs = [ | var inputs = [ | ||
{text: 'Aircraft root property:', default_value:'/position', focus:1, callback:nil, tooltip:nil, validate: | {text: 'Aircraft root property:', default_value:'/position', focus:1, callback:nil, tooltip:nil, validate: 'AircraftRoot', convert:nil}, | ||
{text: 'Airport:', default_value:'KSFO', focus:0, callback:nil, tooltip:nil, validate: | {text: 'Airport:', default_value:'KSFO', focus:0, callback:nil, tooltip:nil, validate: 'Airport', convert:nil}, | ||
{text: 'Runway:', default_value:'28R', focus:0, callback:nil, tooltip:nil, validate: | {text: 'Runway:', default_value:'28R', focus:0, callback:nil, tooltip:nil, validate: 'Runway', convert:nil}, | ||
{text: 'Glidepath:', default_value:'3.00', focus:0, callback:nil, tooltip:nil, validate: | {text: 'Final Approach (nm):', default_value:'10.00', focus:0, callback:nil, tooltip:nil, validate: 'FinalApproach', convert:nil}, | ||
{text: 'Touchdown Offset (m):', default_value:'0.00', focus:0, callback:nil, tooltip:nil, validate: | |||
{text: 'Glidepath:', default_value:'3.00', focus:0, callback:nil, tooltip:nil, validate: 'Glidepath', convert:nil}, | |||
{text: 'Safety Slope:', default_value:'2.00', focus:0, callback:nil, tooltip:nil, validate: 'SafetySlope', convert:nil}, | |||
{text: 'Decision Height (ft):', default_value:'200.00', focus:0, callback:nil, tooltip:nil, validate: 'DecisionHeight', convert:nil}, | |||
{text: 'Touchdown Offset (m):', default_value:'0.00', focus:0, callback:nil, tooltip:nil, validate: 'TouchdownOffset', convert:nil}, | |||
]; | ]; # input fields | ||
foreach(var input; inputs) { | foreach(var input; inputs) { | ||
# TODO: pass input hash | |||
setupLabeledInput(root, myLayout, input.text, input.default_value, input.focus); | setupLabeledInput(root, myLayout, input.text, input.default_value, input.focus); | ||
} | } | ||
Line 332: | Line 374: | ||
var validateFields = func() { | var validateFields = func() { | ||
foreach(var f; inputs) { | foreach(var f; inputs) { | ||
var result = f.validate(); | |||
var widget = nil; # TODO | |||
var result = validationHelpers[f.validate] ("/position"); | |||
if (result == 1) { | if (result == 1) { | ||
Line 340: | Line 384: | ||
cb = nil, | cb = nil, | ||
buttons = canvas.MessageBox.Ok | buttons = canvas.MessageBox.Ok | ||
); | ); # MessageBox | ||