Beispiel #1
0
        private static void DrawInputIcon(Rect inputRect, int fontSize, string glyph, float rightOffset)
        {
            if (string.IsNullOrEmpty(glyph))
            {
                return;
            }
            if (!Glyphs.CanParseAsGlyph(glyph))
            {
                return;
            }

            var glyphStyle = Glyphs.GetGlyphStyle(glyph);

            glyphStyle.fontSize = fontSize;
            string g = Glyphs.GlyphString(glyph);

            var iconContent = new GUIContent(g);
            var size        = glyphStyle.CalcSize(iconContent);

            GUI.Label(new Rect(inputRect.xMax - (size.x + rightOffset), inputRect.yMax - (inputRect.height / 2 + size.y / 2), size.x, size.y), g, glyphStyle);
        }
Beispiel #2
0
        public static string TextInputGroup(string text, string frontAddon, string backAddon, string glyph)
        {
            var   inputStyle = FlatEditor.DefaultPanelSkin.textArea;
            var   inputRect  = EditorGUILayout.GetControlRect(GUILayout.Height(EditorGUIUtility.singleLineHeight * 2));
            float iconOffset = 5;

            if (string.IsNullOrEmpty(frontAddon) && string.IsNullOrEmpty(backAddon))
            {
                DrawInputIcon(inputRect, inputStyle.fontSize, glyph, iconOffset);
                return(GUI.TextArea(inputRect, text, inputStyle));
            }

            GUIContent frontContent = null;
            GUIStyle   frontStyle   = null;

            if (!string.IsNullOrEmpty(frontAddon))
            {
                frontContent = new GUIContent(frontAddon);
                frontStyle   = new GUIStyle(FlatEditor.DefaultPanelSkin.customStyles[9]);

                if (Glyphs.CanParseAsGlyph(frontAddon))
                {
                    frontStyle.font   = Glyphs.FontAwesomeStyle.font;
                    frontContent.text = Glyphs.GlyphString(frontAddon);
                }

                var frontStyleSize = frontStyle.CalcSize(frontContent);

                inputStyle.contentOffset = new Vector2(frontStyleSize.x, 0);
            }

            string output = GUI.TextArea(inputRect, text, inputStyle);

            if (!string.IsNullOrEmpty(frontAddon))
            {
                var frontStyleSize = frontStyle.CalcSize(frontContent);
                var frontRect      = new Rect(inputRect.xMin, inputRect.yMin, frontStyleSize.x, inputRect.height);
                GUI.Box(frontRect, frontContent.text, frontStyle);
            }

            if (!string.IsNullOrEmpty(backAddon))
            {
                var backContent = new GUIContent(backAddon);
                var backStyle   = new GUIStyle(FlatEditor.DefaultPanelSkin.customStyles[10]);

                if (Glyphs.CanParseAsGlyph(backAddon))
                {
                    backStyle.font   = Glyphs.FontAwesomeStyle.font;
                    backContent.text = Glyphs.GlyphString(backAddon);
                }

                var frontStyleSize = backStyle.CalcSize(backContent);

                GUI.Box(
                    new Rect(inputRect.xMax - frontStyleSize.x, inputRect.yMin, frontStyleSize.x, inputRect.height),
                    backContent.text, backStyle);

                iconOffset += backStyle.CalcSize(backContent).x;
            }

            DrawInputIcon(inputRect, inputStyle.fontSize, glyph, iconOffset);

            return(output);
        }
        public static bool DrawButton(string buttonContent, string glyphName, string badge, Color buttonColor, Size size, bool block, bool noOutline = false)
        {
            GUI.color = buttonColor;
            Color textColor = ContrastingBinaryColor(buttonColor);

            if (buttonColor.a == 0)
            {
                textColor = Colors.Link;
            }


            var style = new GUIStyle(FlatEditor.DefaultPanelSkin.button);

            if (noOutline)
            {
                style.normal.background = FlatEditor.DefaultPanelSkin.customStyles[0].normal.background;
                style.hover.background  = FlatEditor.DefaultPanelSkin.customStyles[0].normal.background;
            }

            style.fontSize = (int)size;

            if (Glyphs.CanParseAsGlyph(buttonContent))
            {
                style.font    = Glyphs.GetGlyphStyle(buttonContent).font;
                buttonContent = Glyphs.GlyphString(buttonContent);
            }


            var     contentSize = style.CalcSize(new GUIContent(buttonContent));
            Vector2 glyphSize   = Vector2.zero;
            Vector2 badgeSize   = Vector2.zero;

            if (!string.IsNullOrEmpty(glyphName) && Glyphs.CanParseAsGlyph(glyphName))
            {
                var glyphStyle = Glyphs.GetGlyphStyle(glyphName);
                glyphStyle.fontSize = (int)size + 5;
                var glyph = Glyphs.GlyphString(glyphName);
                glyphSize = glyphStyle.CalcSize(new GUIContent(glyph));
            }

            if (!string.IsNullOrEmpty(badge))
            {
                var badgeStyle = new GUIStyle(style);
                badgeStyle.fontSize = Mathf.Clamp(style.fontSize - 5, 10, 100);
                badgeSize           = badgeStyle.CalcSize(new GUIContent(badge));
            }


            if (block)
            {
                style.stretchWidth = true;
            }
            else
            {
                style.fixedWidth     = contentSize.x + glyphSize.x + badgeSize.x + style.padding.horizontal;
                style.contentOffset += new Vector2(glyphSize.x - 5, 0) - new Vector2(badgeSize.x / 5, 0);
            }

            var output = GUILayout.Button(TypographyUtilities.ColoredText(textColor, buttonContent), style);

            var buttonRect = new Rect();

            if (!string.IsNullOrEmpty(glyphName))
            {
                buttonRect = GUILayoutUtility.GetLastRect();
                var glyphStyle = Glyphs.GetGlyphStyle(glyphName);
                glyphStyle.fontSize = (int)size + 5;
                var glyph = Glyphs.GlyphString(glyphName);

                GUI.Label(new Rect(buttonRect.x + style.padding.left, buttonRect.yMax - (buttonRect.height / 2) - glyphSize.y / 2, glyphSize.x, glyphSize.y), TypographyUtilities.ColoredText(textColor, glyph), glyphStyle);
            }

            if (!string.IsNullOrEmpty(badge))
            {
                if (buttonRect == new Rect())
                {
                    buttonRect = GUILayoutUtility.GetLastRect();
                }
                var badgeStyle = new GUIStyle(FlatEditor.DefaultPanelSkin.customStyles[8])
                {
                    fontSize = Mathf.Clamp(style.fontSize - 5, 10, 100)
                };
                badgeSize = badgeStyle.CalcSize(new GUIContent(badge));

                var badgeColor = buttonColor;
                if (buttonColor.a == 0)
                {
                    badgeColor = Colors.Default;
                }

                GUI.color = textColor;
                GUI.Label(new Rect(buttonRect.xMax - badgeSize.x - style.padding.left, buttonRect.yMax - (buttonRect.height / 2) - badgeSize.y / 2, badgeSize.x, badgeSize.y), TypographyUtilities.ColoredText(badgeColor, badge), badgeStyle);
                Colors.ResetUIColor();
            }

            Colors.ResetUIColor();
            return(output);
        }