How do I create a hierarchical structure with the Canvas Editor Outliner?

1
Looking at this image, “Combo”, “Slider”, and “Radio” belong to “Shape”. What kind of operation can make “Combo” belong to “Shape”?

Furthermore, does anyone know how to return an element that once belonged to the lower hierarchy to the upper hierarchy again?

Thanks.

You can’t do it in Armory2D for now, but you can do it in two other way:

  1. Edit the outputed json.(not recommended, just to say that this works too)
  2. Use Haxe script.(recommended ofc)

Editing Json:

Edit the outputed json in Root folder - Bundled - canvas - NameOfCanvas.json:

{
~
"anchor":0,
"parent":null,//<---
"children":[],//<---
~
},
  1. Set parent to id(Int) of element you want to parent it to.(edit Combo, Slider and Radio and set parent to id of shape)
  2. Set children to array of ids(Int) of the kids.(edit shape and add ids of Combo, Slider and Radio).

Haxe script:

You can create a scene script and the edit canvas in notifyOnInit func.

//! this psuedocode, haven't tried if this actually work, but it should !
import armory.trait.internal.CanvasScript;
class CanvasTrait extends iron.Trait {
	
	var canvas:CanvasScript;

        public function new() {
		super();

		notifyOnInit(function() {
			canvas = Scene.active.getTrait(CanvasScript);
                        // This
                        canvas.getElement("Shape").children = [id_of_combo, id_of_slider, id_of_radio];
                       // Or this
                       canvas.getElement("combo").parent = id_of_shape;
                       canvas.getElement("slider").parent = id_of_shape;
                       canvas.getElement("radio").parent = id_of_shape;
		});
	}
}

(I don’t know if you only have to set children or parent, might have to set both, as I haven’t tried)

2 Likes

Thank you for teaching me.

import iron.Scene;    

I needed to add this sentence, but I was able to build a parent-child relationship.
This is useful when switch canvases, because when hide the parent, all the children are also hidden.

Both had to be set.

1 Like

Digging in code of Armory2D, I found out parenting is already there.
here how to do it(need 2 separate mouse button, can’t do it on magic mouse and macbook trackpad):

  1. select the element you want it to be parent (eg: combo / slider / radio)
  2. right click-hold on parent (eg: Shape).
  3. left click on parent(eg: Shape).
  4. tada! combo/slider/radio is now parent to shape!

to unparent:

  1. select parented element.
  2. right click-hold on parented element.
  3. left click parent element.
  4. tada! element unparented

will push fix for proper parenting keyboard-mouse combination, so that you don’t have to use 2 mouse button and flex on apple

5 Likes

When I tried this operation, I was able to build a parent-child relationship.

Using left and right clicks at the same time seems unusual. It seems that Mac can also be right-clicked, but not simultaneously.

Thank you for teaching me.

1 Like