What you are doing now is mixing two distinct concepts: a group is a low-level Canvas element to organize drawables into a scene graph hierarchy, whereas layouts and widgets are much higher level concepts - which is why you cannot simply add a Widget to a group directly. There is no connection, you need to establish that connection first (see the Canvas Snippets wiki article): https://wiki.flightgear.org/Canvas_snippets
First, you need to assign a top-level layout to your canvas, then you can add other sub-layouts to that root layout - and each layout can then add different widgets, but these must use the Widget.nas API correctly (the meat of which can be found in DefaultStyle.nas) - it's basically an MVC abstraction: https://wiki.flightgear.org/Howto:Creat ... Widget.nas
In other words, you cannot easily use non-Widgets in conjunction with the Layout engine, you need to implement the widget first.
To learn how to do this properly, it's best to leave your code aside for 10-15 minutes and carefully inspect $FG_ROOT/Nasal/canvas/gui/styles/DefaultStyle.nas - you will find a hash with a list of supported widgets, including their implementation - next, search the file for related examples (you want to add a canvas path element, so look for "path").
The first example you can find there is this (I will just post the constructor):
- Code: Select all
# A button
DefaultStyle.widgets.button = {
new: func(parent, cfg)
{
me._root = parent.createChild("group", "button");
me._bg =
me._root.createChild("path");
me._border =
me._root.createChild("image", "button")
.set("slice", "10 12"); #"7")
me._label =
me._root.createChild("text")
.set("font", "LiberationFonts/LiberationSans-Regular.ttf")
.set("character-size", 14)
.set("alignment", "center-baseline");
},
There you can see how to access the Canvas system so that the Layout system knows how to align new/custom widgets.