static void NamedGeneratorButton(ChiselPlacementToolInstance generator, Rect togglePosition, GUIStyle style, bool isActive)
        {
            var temp = togglePosition;

            temp.xMin += 5;
            temp.width = 20;
            {
                EditorGUI.BeginChangeCheck();
                var value = GUI.Toggle(temp, generator.InToolBox, GUIContent.none);
                if (EditorGUI.EndChangeCheck())
                {
                    SetInToolBox(generator, value);
                }
            }
            temp       = togglePosition;
            temp.xMin += 25;
            {
                EditorGUI.BeginChangeCheck();
                var content    = ChiselEditorResources.GetIconContentWithName(generator.ToolName, generator.ToolName)[0];
                var isSelected = ChiselGeneratorManager.GeneratorMode == generator;
                var value      = ToggleButton(temp, content, isSelected, style, isActive);
                if (EditorGUI.EndChangeCheck() && value)
                {
                    // TODO: make undoable
                    generator.InToolBox = true;
                    ChiselCreateTool.ActivateTool();
                    ChiselGeneratorManager.GeneratorMode = generator;
                    ChiselEditorSettings.Save();
                    SceneView.RepaintAll();
                }
            }
        }
        static void GeneratorButton(Rect position, ChiselPlacementToolInstance generator, GUIStyle style, bool isActive)
        {
            EditorGUI.BeginChangeCheck();
            var content    = generator.Content;
            var isSelected = ChiselGeneratorManager.GeneratorMode == generator;
            var value      = ToggleButton(position, content, isSelected && isActive, style, isActive);

            if (EditorGUI.EndChangeCheck())
            {
                if (Event.current.button == 2)
                {
                    ChiselPlacementToolsSelectionWindow.SetInToolBox(generator, false);
                }
                else
                {
                    ChiselCreateTool.ActivateTool();
                    ChiselGeneratorManager.GeneratorMode = generator;
                    if (value)
                    {
                        ChiselEditorSettings.Save();
                    }
                    SceneView.RepaintAll();
                }
            }
        }
        public void OnGUI()
        {
            // TODO: add search functionality
            // TODO: add automatic finding node based generators in project

            InitStyles();
            var generatorModes = ChiselGeneratorManager.generatorModes;
            var isActive       = ChiselCreateTool.IsActive();

            float height        = 0;
            var   previousGroup = string.Empty;

            for (int i = 0; i < generatorModes.Length; i++)
            {
                var generatorMode = generatorModes[i];
                if (previousGroup != generatorMode.Group)
                {
                    height       += kSingleLineHeight + kSingleSpacing;
                    previousGroup = generatorMode.Group;
                }
                height += kSingleLineHeight + kSingleSpacing;
            }

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            // TODO: figure out how to do this without needing layout stuff?
            EditorGUILayout.GetControlRect(false, height);

            var togglePosition = new Rect(0, 0, ChiselEditorUtility.ContextWidth, kSingleLineHeight);
            var style          = styles.namedToggleStyle;

            previousGroup = string.Empty;
            for (int i = 0; i < generatorModes.Length; i++)
            {
                var generatorMode = generatorModes[i];
                if (previousGroup != generatorMode.Group)
                {
                    EditorGUI.LabelField(togglePosition, generatorMode.Group, styles.groupTitleStyle);
                    togglePosition.y += kSingleLineHeight + kSingleSpacing;
                    previousGroup     = generatorMode.Group;
                }
                NamedGeneratorButton(generatorModes[i], togglePosition, style, isActive);
                togglePosition.y += kSingleLineHeight + kSingleSpacing;
            }
            EditorGUILayout.EndScrollView();
        }
        public static void RenderCreationTools()
        {
            InitStyles();

            var generatorModes = ChiselGeneratorManager.generatorModes;
            var isActive       = ChiselCreateTool.IsActive();

            var style = styles.toggleStyleMid;

            int usedModes = 0;

            for (int i = 0; i < generatorModes.Length; i++)
            {
                if (!generatorModes[i].InToolBox &&
                    ChiselGeneratorManager.GeneratorMode != generatorModes[i])
                {
                    continue;
                }
                usedModes++;
            }

            int rows      = Mathf.CeilToInt((usedModes + 1) / (float)kToolsWide);
            var groupRect = EditorGUILayout.GetControlRect(false, (rows * style.fixedHeight) + styles.boxStyleVerticalMargin, ChiselOverlay.kMinWidthLayout);

            groupRect.xMin -= 2;
            groupRect.yMin += 5;
            groupRect.xMax += 3;
            groupRect.yMax += 6;

            if (Event.current.type == EventType.Repaint)
            {
                var oldColor = GUI.color;
                var newColor = Color.black;
                newColor.a = 0.5f;
                GUI.color  = newColor;
                GUI.DrawTexture(new Rect(groupRect.x, groupRect.y - 1, groupRect.width, 1), Texture2D.whiteTexture);
                GUI.color = oldColor;

                styles.boxStyle.Draw(groupRect, false, false, false, false);
                styles.boxStyle.Draw(groupRect, false, false, false, false);
            }

            var topX = groupRect.x + 3;
            var topY = groupRect.y + 3;


            var leftMargin   = style.margin.left + topX + 1;
            var topMargin    = style.margin.top + topY;
            var buttonWidth  = style.fixedWidth + style.margin.horizontal - 1;
            var buttonHeight = style.fixedHeight + style.margin.vertical;
            var position     = new Rect(0, 0, buttonWidth, buttonHeight);

            int xpos = 0, ypos = 0;

            for (int i = 0; i < generatorModes.Length; i++)
            {
                if (!generatorModes[i].InToolBox &&
                    ChiselGeneratorManager.GeneratorMode != generatorModes[i])
                {
                    continue;
                }
                if (xpos >= kToolsWide)
                {
                    ypos++; xpos = 0;
                }
                position.x = leftMargin + xpos * buttonWidth;
                position.y = topMargin + ypos * buttonHeight;


                var toggleStyle = (xpos == 0) ? styles.toggleStyleLeft :
                                  (xpos == kToolsWide - 1) || (i == generatorModes.Length - 1) ? styles.toggleStyleRight :
                                  styles.toggleStyleMid;

                GeneratorButton(position, generatorModes[i], toggleStyle, isActive);
                xpos++;
            }
            if (xpos >= kToolsWide)
            {
                ypos++; xpos = 0;
            }
            {
                var addStyle = styles.addStyle;
                position.x = addStyle.margin.left + topX + xpos * buttonWidth;
                position.y = addStyle.margin.top + topY + ypos * buttonHeight;
                if (GUI.Button(position, kAddButton, addStyle))
                {
                    Create();
                }
            }
        }