예제 #1
0
            private static string[] LinesFromString(string value, Rect rect, GUIStyle style)
            {
                //Split by line return
                string[] splitString = value.Split('\n');
                for (int i = 0; i < splitString.Length; i++)
                {
                    splitString[i] = splitString[i] + "\n";
                }

                //Insert split by word warp
                Rect          virtualRect = new Rect(0, 0, rect.width, 100);
                List <string> linesList   = new List <string>();

                for (int i = 0; i < splitString.Length; i++)
                {
                    string sub   = splitString[i];
                    int    cutID = style.GetCursorStringIndex(virtualRect, new GUIContent(sub), new Vector2(virtualRect.width, 8)) + 1;
                    int    a     = 0;
                    while (cutID != sub.Length && a < 20)
                    {
                        a++;
                        linesList.Add(sub.Substring(0, cutID));
                        sub   = sub.Remove(0, cutID);
                        cutID = style.GetCursorStringIndex(virtualRect, new GUIContent(sub), new Vector2(virtualRect.width, 8)) + 1;
                    }
                    linesList.Add(sub);
                }

                //Return result
                return(linesList.ToArray());
            }
예제 #2
0
            internal override void Render(ChannelGUI gui, float spaceWidth, float maxNameWidth)
            {
                initStyles(gui);


                GUIStyle style = (highlighted ? gui.textHighlightedStyle : gui.textStyle);

                GUILayout.BeginHorizontal();
                GUILayout.Label(sender, gui.senderStyle, GUILayout.Width(maxNameWidth), GUILayout.MaxWidth(maxNameWidth));
                if (GUILayout.Button(sourceText, style))
                {
                    int textIndex = style.GetCursorStringIndex(textRect, new GUIContent(textClickifiedText), Event.current.mousePosition);
                    handleClick(gui, textClickifiedText, textIndex);
                }
                if (Event.current.type == EventType.Repaint)
                {
                    textRect = GUILayoutUtility.GetLastRect();
                }
                GUILayout.EndHorizontal();
            }
예제 #3
0
        string[] GetLines(string text, GUIStyle textblockStyle)
        {
            string[] lines;
            if (!mWrappedTextLines.TryGetValue(text, out lines))
            {
                var content = new GUIContent(text);

                var textRect   = GUILayoutUtility.GetRect(content, textblockStyle);
                var lineHeight = textblockStyle.lineHeight;
                int lineCount  = (int)(textRect.height / lineHeight);

                int[] lineEnds = new int[lineCount];
                lines = new string[lineCount];
                for (int i = 0; i < lineCount; i++)
                {
                    int endLineIdx = 0;
                    for (float x = 0; x < textRect.width; x += 6)
                    {
                        Vector2 hitTestPos = textRect.position + new Vector2(textRect.width - x, i * lineHeight + lineHeight / 2);
                        endLineIdx = textblockStyle.GetCursorStringIndex(
                            textRect,
                            content,
                            hitTestPos);

                        if (endLineIdx > 0)
                        {
                            break;
                        }
                    }

                    lineEnds[i] = endLineIdx;

                    if (i == lines.Length - 1 && lines.Length > 1)
                    {
                        lines[i] = BuildLine.ForIndex(text, lineEnds[i - 1] + 1);
                    }
                    else if (i > 0)
                    {
                        lines[i] = BuildLine.ForIndexAndLenght(text, lineEnds[i - 1] + 1, endLineIdx - lineEnds[i - 1] - 1);
                    }
                    else
                    {
                        lines[0] = BuildLine.ForIndexAndLenght(text, 0, Mathf.Min(text.Length, endLineIdx + 1)).Trim();
                    }
                }

                bool validLines = false;
                for (int i = 0; i < lines.Length; i++)
                {
                    if (!string.IsNullOrEmpty(lines[i]))
                    {
                        validLines = true;
                        break;
                    }
                }

                if (validLines)
                {
                    mWrappedTextLines.Add(text, lines);
                    Repaint();
                    return(null); // The frame they are generated they shouldn't be drawn, for layout error reasons
                }
            }
            else
            {
                return(lines);
            }

            return(null);
        }