| 
				 | 
				
| Line 96: | 
Line 96: | 
 | * Checkbox  |  | * Checkbox  | 
 | * ScrollArea  |  | * ScrollArea  | 
 | 
  |  | 
 | New widgets are implemented by adding a corresponding Nasal file to $FG_ROOT/Nasal/canvas/gui/widgets - e.g. myWidget.nas
  |  | 
 | Each widget should then implement a minimal interface, for example:
  |  | 
 | 
  |  | 
 | <syntaxhighlight lang="nasal">
  |  | 
 | gui.widgets.myWidget = {
  |  | 
 |   new: func(parent, style, cfg)
  |  | 
 |   {
  |  | 
 |     var m = gui.Widget.new(gui.widgets.myWidget);
  |  | 
 |     m._cfg = Config.new(cfg);
  |  | 
 |     m._focus_policy = m.NoFocus;
  |  | 
 |     m._setView( style.createWidget(parent, "mywidget", m._cfg) );
  |  | 
 | 
  |  | 
 |     return m;
  |  | 
 |   },
  |  | 
 |   setImage: func(img)
  |  | 
 |   {
  |  | 
 |     me._view.setImage(me, img);
  |  | 
 |     return me;
  |  | 
 |   },
  |  | 
 |   setBackground: func(bg)
  |  | 
 |   {
  |  | 
 |     me._view.setBackground(me, bg);
  |  | 
 |     return me;
  |  | 
 |   }
  |  | 
 | };
  |  | 
 | </syntaxhighlight>
  |  | 
 | 
  |  | 
 | For this to work, the next thing that needs to be done is opening $FG_ROOT/Nasal/canvas/gui/styles/DefaultStyle.nas in order to add a default style for your new widget to the end of the file, the hash entry's name must match the key used in the _setView() method call above (e.g. mywidget in this case):
  |  | 
 | 
  |  | 
 | 
  |  | 
 | <syntaxhighlight lang="nasal">
  |  | 
 | 
  |  | 
 | </syntaxhighlight>
  |  | 
 | 
  |  | 
  | 
 | == Widget Candidates ==  |  | == Widget Candidates ==  |