示例#1
0
        /// Adding (selecting from a pool) of a new ui instance. Use this for non-static group adding
        public Cell Add(Layout layout, float size = 1, string name = null)
        {
            //get next pooled child
            if (children == null)
            {
                children = new List <Cell>();
            }
            if (childCounter >= children.Count)
            {
                children.Add(null);
            }
            if (childCounter >= children.Count)
            {
                throw new Exception("Could not add child");
            }

            Cell ui = children[childCounter] ?? new Cell();

            children[childCounter] = ui;
            childCounter++;


            //setting size
            switch (autoLayout)              //note parent layout used here, not the new one
            {
            case Layout.Horizontal:
                if (size > 1.0001f)
                {
                    ui.absSize.x = size; ui.relSize.x = 0;
                }
                else
                {
                    ui.relSize.x = size; ui.absSize.x = 0;
                }
                ui.relSize.y = 1; ui.absSize.y = 0;
                break;

            case Layout.Vertical:
                ui.relSize.x = 1; ui.absSize.x = 0;
                if (size > 1.0001f)
                {
                    ui.absSize.y = size; ui.relSize.y = 0;
                }
                else
                {
                    ui.relSize.y = size; ui.absSize.y = 0;
                }
                break;

            case Layout.Full:
            default:
                ui.relSize = new Float2(1, 1);
                ui.absSize = new Float2(0, 0);
                break;
            }


            ui.autoLayout = layout;
            ui.name       = name;
            ui.scrollZoom = scrollZoom;
            //ui.padding = padding;

            return(ui);
        }