Exemplo n.º 1
0
        public int nk_text_clamp(StringSegment text, float space, out int glyphs, out float text_width, uint *sep_list, int sep_count)
        {
            var   i          = 0;
            var   glyph_len  = 0;
            var   last_width = (float)0;
            var   unicode    = 0;
            var   widthV     = (float)0;
            var   len        = 0;
            var   g          = 0;
            float s;
            var   sep_len   = 0;
            var   sep_g     = 0;
            var   sep_width = (float)0;

            sep_count = sep_count < 0 ? 0 : sep_count;
            glyph_len = Nuklear.nk_utf_decode(text, &unicode);

            while (glyph_len != 0 && widthV < space && len < text.Length)
            {
                len += glyph_len;

                s = width(new StringSegment(text, text.Location, len));
                for (i = 0; i < sep_count; ++i)
                {
                    if (unicode != sep_list[i])
                    {
                        continue;
                    }
                    sep_width = last_width = widthV;
                    sep_g     = g + 1;
                    sep_len   = len;
                    break;
                }

                if (i == sep_count)
                {
                    last_width = sep_width = widthV;
                    sep_g      = g + 1;
                }

                widthV    = s;
                glyph_len = Nuklear.nk_utf_decode(text + len, &unicode);
                g++;
            }

            if (len >= text.Length)
            {
                glyphs     = g;
                text_width = last_width;
                return(len);
            }

            glyphs     = sep_g;
            text_width = sep_width;
            return(sep_len == 0 ? len : sep_len);
        }
Exemplo n.º 2
0
        public Vector2 nk_text_calculate_text_bounds(StringSegment begin, float row_height,
                                                     out StringSegment remaining, out Vector2 out_offset, out int glyphs, int op)
        {
            var   line_height = row_height;
            var   text_size   = new Vector2(0, 0);
            var   line_width  = 0.0f;
            float glyph_width;
            var   glyph_len = 0;
            var   unicode   = 0;
            var   text_len  = 0;

            out_offset = Vector2.Zero;
            glyphs     = 0;

            remaining = StringSegment.Null;
            if (begin.IsNullOrEmpty)
            {
                return(new Vector2(0, row_height));
            }
            glyph_len = Nuklear.nk_utf_decode(begin, &unicode);
            if (glyph_len == 0)
            {
                return(text_size);
            }

            glyph_width = width(new StringSegment(begin, begin.Location, glyph_len));

            glyphs = 0;
            while (text_len < begin.Length && glyph_len != 0)
            {
                if (unicode == '\n')
                {
                    text_size.X  = text_size.X < line_width ? line_width : text_size.X;
                    text_size.Y += line_height;
                    line_width   = 0;
                    glyphs      += 1;
                    if (op == Nuklear.NK_STOP_ON_NEW_LINE)
                    {
                        break;
                    }
                    text_len++;
                    glyph_len = Nuklear.nk_utf_decode(begin + text_len, &unicode);
                    continue;
                }

                if (unicode == '\r')
                {
                    text_len++;
                    glyphs   += 1;
                    glyph_len = Nuklear.nk_utf_decode(begin + text_len, &unicode);
                    continue;
                }

                glyphs      = glyphs + 1;
                text_len   += glyph_len;
                line_width += glyph_width;
                glyph_len   = Nuklear.nk_utf_decode(begin + text_len, &unicode);

                glyph_width = width(begin + text_len);
            }

            if (text_size.X < line_width)
            {
                text_size.X = line_width;
            }

            out_offset = new Vector2(line_width, text_size.Y + line_height);
            if (line_width > 0 || text_size.Y == 0.0f)
            {
                text_size.Y += line_height;
            }
            if (remaining != null)
            {
                remaining = begin + text_len;
            }
            return(text_size);
        }