Howto:Creating a Canvas GUI Widget: Difference between revisions

Jump to navigation Jump to search
Line 223: Line 223:


<syntaxhighlight lang="diff">
<syntaxhighlight lang="diff">
diff --git a/Nasal/canvas/gui/widgets/Map.nas b/Nasal/canvas/gui/widgets/Map.nas
new file mode 100644
index 0000000..d26a902
--- /dev/null
+++ b/Nasal/canvas/gui/widgets/Map.nas
@@ -0,0 +1,25 @@
+gui.widgets.Map = {
+  new: func(parent, style, cfg)
+  {
+    var m = gui.Widget.new(gui.widgets.Map);
+    m._cfg = Config.new(cfg);
+    m._focus_policy = m.NoFocus;
+    m._setView( style.createWidget(parent, "map", m._cfg) );
+
+    var TestMap = m._view._root.createChild("map");
+    TestMap.setController("Aircraft position");
+    TestMap.setRange(35);
+   
+    TestMap.setTranslation(160/2, 120/2);
+    var r = func(name,vis=1,zindex=nil) return caller(0)[0];
+    foreach(var type; [r('VOR'),r('APT'), r('APS') ] )
+            TestMap.addLayer(factory: canvas.SymbolLayer, type_arg: type.name, visible: type.vis, priority: type.zindex,);
+
+    return m;
+  },
+  setBackground: func(bg)
+  {
+    me._view.setBackground(me, bg);
+    return me;
+  }
+};
</syntaxhighlight>
</syntaxhighlight>


Navigation menu