20,741
edits
Line 270: | Line 270: | ||
Once the underlying script is working well enough, we can look into providing a configuration 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 configuration 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,400); | ||
var title = 'GCA Dialog '; | var title = 'GCA Dialog '; | ||
Line 298: | Line 298: | ||
var setupWidgetTooltip = func(widget, tooltip) { | var setupWidgetTooltip = func(widget, tooltip) { | ||
widget._view._root.addEventListener("mouseover", func gui.popupTip(tooltip) ); | widget._view._root.addEventListener("mouseover", func gui.popupTip(tooltip) ); | ||
} # setupWidgetTooltip | |||
var setupLabeledInput = func(root, layout, input) { | |||
var setupLabeledInput = func(root, layout, text, default_value, focus, tooltip) { | #text, default_value, focus, tooltip, unit) { | ||
var label = canvas.gui.widgets.Label.new(root, canvas.style, {wordWrap: 0}); | var label = canvas.gui.widgets.Label.new(root, canvas.style, {wordWrap: 0}); | ||
label.setText(text); | var unit_suffix = sprintf(" (%s):", input.unit); | ||
label.setText(input.text~unit_suffix); | |||
layout.addItem(label); | layout.addItem(label); | ||
var | var field = canvas.gui.widgets.LineEdit.new(root, canvas.style, {}); | ||
layout.addItem( | layout.addItem(field); | ||
field.setText(input.default_value); | |||
## TODO: add widget to hash | ## TODO: add widget to hash | ||
if (focus) | if (input.focus) | ||
field.setFocus(); | |||
setupWidgetTooltip(widget:field, tooltip: input.tooltip); | |||
setupWidgetTooltip(widget: | return field; # return to caller | ||
} # setupLabeledInput() | } # setupLabeledInput() | ||
Line 369: | Line 370: | ||
}, | }, | ||
'TransmissionInterval': func(input) { | |||
return 0; | |||
}, | |||
}; # validationHelpers; | }; # validationHelpers; | ||
Line 374: | Line 379: | ||
var inputs = [ | var inputs = [ | ||
{text: 'Aircraft root | {text: 'Aircraft root', default_value:'/position', focus:1, callback:nil, tooltip:'property path', validate: 'AircraftRoot', convert:nil, unit: 'property path'}, | ||
{text: 'Airport | {text: 'Airport', default_value:'KSFO', focus:0, callback:nil, tooltip:'ICAO ID, e.g. KSFO', validate: 'Airport', convert:nil, unit:'ICAO'}, | ||
{text: 'Runway | {text: 'Runway', default_value:'28R', focus:0, callback:nil, tooltip:'runway identifier, e.g. 28L', validate: 'Runway', convert:nil, unit:'RWY'}, | ||
{text: 'Final Approach | {text: 'Final Approach', default_value:'10.00', focus:0, callback:nil, tooltip:'length of final approach leg', validate: 'FinalApproach', convert:nil, unit:'nm'}, | ||
{text: ' | {text: 'Glidepath', default_value:'3.00', focus:0, callback:nil, tooltip:'glidepath in degrees, e.g. 3', validate: 'Glidepath', convert:nil, unit:'degrees'}, | ||
{text: ' | {text: 'Safety Slope', default_value:'2.00', focus:0, callback:nil, tooltip:'safety slope in degrees', validate: 'SafetySlope', convert:nil, unit:'degrees'}, | ||
{text: 'Decision Height', default_value:'200.00', focus:0, callback:nil, tooltip:'decision height (vertical offset)', validate: 'DecisionHeight', convert:nil, unit:'ft'}, | |||
{text: 'Touchdown Offset', default_value:'0.00', focus:0, callback:nil, tooltip:'touchdown offset', validate: 'TouchdownOffset', convert:nil, unit:'m'}, | |||
{text: 'Transmission interval', default_value:'5.00', focus:0, callback:nil, tooltip:'Controller/timer resolution', validate: 'TransmissionInterval', convert:nil, unit:'secs'}, | |||
]; # input fields | ]; # input fields | ||
foreach(var input; inputs) { | foreach(var input; inputs) { | ||
# TODO: pass input hash | # TODO: pass input hash | ||
setupLabeledInput(root, myLayout, input | var widget = setupLabeledInput(root, myLayout, input); | ||
} | } | ||
Line 409: | Line 414: | ||
} # error handling | } # error handling | ||
} # foreach | } # foreach | ||
return 0; # all validations passed | |||
} # validateFields() | } # validateFields() | ||