Howto:Creating a Canvas GUI dialog file: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
mNo edit summary
Line 57: Line 57:
== Adding Widgets ==
== Adding Widgets ==
== Using Layouts ==
== Using Layouts ==
== Using Styling ==

Revision as of 16:25, 29 June 2014

This article is a stub. You can help the wiki by expanding it.

Editing Translations/en/menu.xml

Navigate to the sub-menu where you'd like to add your new dialog, e.g. "Equipment" in this case, and then add a key:

<equipment>Equipment</equipment>
<canvas-demo-dialog>Canvas Demo Dialog</canvas-demo-dialog>

Editing gui/menubar.xml

Next, open $FG_ROOT/gui/menubar.xml and navigate to the corresponding sub-menu and add a new item/binding:

<item>
<name>canvas-demo-dialog</name>
<binding>
<command>nasal</command>
<script>
canvas.loadDialog("CanvasDemo");
</script>
</binding>
</item>


Editing gui/menubar.xml

Next, open/create $FG_ROOT/Nasal/canvas/gui/dialogs/CanvasDemo.nas and add some boilerplate code:

var DemoDialog = {
  new: func
  {
    var m = {
      parents: [DemoDialog],
      _dlg: canvas.Window.new([400,300], "dialog")
                         .set("title", "Demo Dialog")
                         .set("resize", 1),
      _active_button: nil
    };

    m._dlg.getCanvas(1)
          .set("background", canvas.style.getColor("bg_color"));
    m._root = m._dlg.getCanvas().createGroup();

    var vbox = VBoxLayout.new();
    m._dlg.setLayout(vbox);

    return m;
  },
};

var demo = DemoDialog.new();

Finally, start FlightGear and open your new dialog

Adding Widgets

Using Layouts

Using Styling