Canvas widgets: Difference between revisions

Jump to navigation Jump to search
m
→‎Dialog Parser: remove more obsolete stuff ... still surprising how this article got 35+k views ... =)
m (→‎Dialog Parser: remove more obsolete stuff ... still surprising how this article got 35+k views ... =))
Line 201: Line 201:


Given that all three file formats are PropertyList-encoded XML files, it should be possible to come up with a "Xml2Canvas" interface class which implements the XML parser and the Canvas interfaces. That will ensure a maximum degree of code reuse.
Given that all three file formats are PropertyList-encoded XML files, it should be possible to come up with a "Xml2Canvas" interface class which implements the XML parser and the Canvas interfaces. That will ensure a maximum degree of code reuse.
The GUI builder (currently CanvasWidget.cxx) would then merely need to instantiate a new Nasal object by calling the widget constructor:
<syntaxhighlight lang="nasal">
var is_hash = func(t) typeof(t)=='hash';
var is_func = func(f) typeof(f)=='func';
var is_class = func(c) is_hash(c) and isFunc(c.new);
var is_widget = func(w) is_class(w) and w.parents[0]=='widget';
var find_widget = func(w) contains(globals["widgets"], w) and is_widget(w);
var get_widget = func (w) globals["widgets"].[w].new;
var widget_name = "checkbox"; // retrieved from the XML parser
if (find_widget(widget_name))
  get_widget(widget_name) (parent,config);
else
  die("Widget not supported/found:", widget_name);
</syntaxhighlight>




Navigation menu