private void GenerateDom() { int total = m_Instructions.Count; if (m_Elements == null || m_Elements.Length != total) { m_Elements = new AutomatedIMElement[total]; } m_Root = new AutomatedIMElement(this, -1); m_Root.descendants = new ArraySegment <AutomatedIMElement>(m_Elements); Stack <AutomatedIMElement> ancestors = new Stack <AutomatedIMElement>(); Stack <int> ancestorsIndex = new Stack <int>(); ancestors.Push(m_Root); ancestorsIndex.Push(-1); for (int i = 0; i < total; ++i) { var instruction = m_Instructions[i]; var parent = ancestors.Peek(); AutomatedIMElement element = CreateAutomatedElement(instruction, i); m_Elements[i] = element; element.parent = parent; parent.AddChild(element); if (i + 1 < total) { var nextInstruction = m_Instructions[i + 1]; if (nextInstruction.level > instruction.level) { ancestors.Push(element); ancestorsIndex.Push(i); } if (nextInstruction.level < instruction.level) { for (int j = instruction.level - nextInstruction.level; j > 0; --j) { var closingParent = ancestors.Pop(); var closingParentIndex = ancestorsIndex.Pop(); closingParent.descendants = new ArraySegment <AutomatedIMElement>(m_Elements, closingParentIndex + 1, i - closingParentIndex); } } } } while (ancestors.Peek() != m_Root) { var closingParent = ancestors.Pop(); var closingParentIndex = ancestorsIndex.Pop(); closingParent.descendants = new ArraySegment <AutomatedIMElement>(m_Elements, closingParentIndex, (total - 1) - closingParentIndex); } }
private AutomatedIMElement CreateAutomatedElement(IMGUIInstruction imguiInstruction, int index) { AutomatedIMElement element = new AutomatedIMElement(this, index); element.enabled = imguiInstruction.enabled; switch (imguiInstruction.type) { case InstructionType.kStyleDraw: { var drawInstruction = m_DrawInstructions[imguiInstruction.typeInstructionIndex]; element.rect = drawInstruction.rect; element.style = drawInstruction.usedGUIStyle; element.guiContent = drawInstruction.usedGUIContent; break; } case InstructionType.kLayoutBeginGroup: { var layoutInstruction = m_LayoutList[imguiInstruction.typeInstructionIndex]; element.rect = layoutInstruction.unclippedRect; element.style = layoutInstruction.style; break; } case InstructionType.kLayoutNamedControl: { var namedControlInstruction = m_NamedControlList[imguiInstruction.typeInstructionIndex]; element.rect = namedControlInstruction.rect; element.controlName = namedControlInstruction.name; break; } } return(element); }
public void AddChild(AutomatedIMElement element) { m_Children.Add(element); }