Howto:Implementing a simple GCA system: Difference between revisions

Jump to navigation Jump to search
m
→‎GUI frontend: validate inputs at runtime
m (→‎GUI frontend: validate inputs at runtime)
Line 267: Line 267:


[[File:Extended-gca-dialog.png|thumb|Extended GCA dialog showing additional configuration options]]
[[File:Extended-gca-dialog.png|thumb|Extended GCA dialog showing additional configuration options]]
[[File:Gca-dialog-with-ai-support.png|thumb|GCA dialog showing support for AI/MP models]]


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:  
Line 320: Line 322:


setupWidgetTooltip(widget:field, tooltip: input.tooltip);
setupWidgetTooltip(widget:field, tooltip: input.tooltip);
var el = field._view._root;
el.addEventListener("keypress", func (e) {
# print("field changed, value:", field.text() );
var color = (validationHelpers[input.validate]( field.text() ) == 0) ? [0,1,0] : [1,0,0];
field._view._root.setColor(color);
});
   
return field; # return to caller
return field; # return to caller
} # setupLabeledInput()
} # setupLabeledInput()


var validateAircraftRoot = func(input) {
var validationHelpers = {
 
'AircraftRoot': func(input) {
var root = props.getNode(input);
var root = props.getNode(input);
if (root == nil) return 1; # error
if (root == nil) return 1; # error
Line 331: Line 348:
foreach(var rp; required_props) {
foreach(var rp; required_props) {
  if (root.getNode(rp) == nil) return 1;
  if (root.getNode(rp) == nil) return 1;
}
} # foreach


return 0; # valid root node
return 0; # valid root node
}
var validationHelpers = {
'AircraftRoot': func(input) {
return 0;
},
},


Navigation menu