Inheritance: WidgetGroup
Exemplo n.º 1
0
        protected override void InitializeCore()
        {
            ShowDebug = true;

            _stage = new Stage(Context.GraphicsDevice);
            Context.Input.Processor = _stage;

            Skin skin = new Skin(Context.GraphicsDevice, "Data/uiskin.json");

            Table table = new Table();
            table.SetFillParent(true);
            _stage.AddActor(table);

            Tree tree = new Tree(skin);

            TreeNode node1 = new TreeNode(new TextButton("moo1", skin));
            TreeNode node2 = new TreeNode(new TextButton("moo2", skin));
            TreeNode node3 = new TreeNode(new TextButton("moo3", skin));
            TreeNode node4 = new TreeNode(new TextButton("moo4", skin));
            TreeNode node5 = new TreeNode(new TextButton("moo5", skin));

            tree.Add(node1);
            tree.Add(node2);
            node2.Add(node3);
            node3.Add(node4);
            tree.Add(node5);

            Label label = new Label("", skin, "default");

            tree.SelectionChanged += (sender, e) => {
                if (e.AddedItems.Count == 0)
                    return;

                StringBuilder txt = new StringBuilder();
                foreach (TreeNode node in e.AddedItems) {
                    TextButton button = node.Actor as TextButton;
                    txt.Append(button.Text + ", ");
                }

                label.Text = txt.ToString();
                label.Invalidate();
            };

            (node5.Actor as Button).Clicked += (sender, e) => {
                tree.Remove(node4);
            };

            //node5.Actor.AddListener(new DispatchClickListener() {
            //    OnClicked = (ev, x, y) => { tree.Remove(node4); }
            //});

            table.Add(tree).Configure.Fill().Expand();
            table.Row();
            table.Add(label).Configure.Fill().Expand();

            //Debugger.Launch();
        }
Exemplo n.º 2
0
        internal void RemoveFromTree(Tree tree)
        {
            tree.RemoveActor(_actor);
            if (!_expanded)
                return;

            foreach (TreeNode node in _children)
                node.RemoveFromTree(tree);
        }
Exemplo n.º 3
0
        internal void AddToTree(Tree tree)
        {
            tree.AddActor(_actor);
            if (!_expanded)
                return;

            foreach (TreeNode node in _children)
                node.AddToTree(tree);
        }