示例#1
0
		public static void nk_widget_text_wrap(this CommandBuffer o, RectangleF b, StringSegment _string_, nk_text* t,
			nk_font f)
		{
			float width;
			var glyphs = 0;
			var fitting = 0;
			var done = 0;
			var line = new RectangleF();
			var text = new nk_text();
			var seperator = stackalloc uint[1];
			seperator[0] = ' ';

			if (o == null || t == null)
				return;
			text.padding = new Vector2(0, 0);
			text.Background = t->Background;
			text.text = t->text;
			b.Width = b.Width < 2 * t->padding.X ? 2 * t->padding.X : b.Width;
			b.Height = b.Height < 2 * t->padding.Y ? 2 * t->padding.Y : b.Height;
			b.Height = b.Height - 2 * t->padding.Y;
			line.X = b.X + t->padding.X;
			line.Y = b.Y + t->padding.Y;
			line.Width = b.Width - 2 * t->padding.X;
			line.Height = 2 * t->padding.Y + f.Size;
			fitting = f.nk_text_clamp(_string_, line.Width, out glyphs, out width, seperator, 1);
			while (done < _string_.Length)
			{
				if (fitting == 0 || line.Y + line.Height >= b.Y + b.Height)
					break;
				WidgetText(o, line, _string_ + done, &text, nk_text_align.NK_TEXT_LEFT, f);
				done += fitting;
				line.Y += f.Size + 2 * t->padding.Y;
				fitting = f.nk_text_clamp(_string_ + done, line.Width, out glyphs, out width,
					seperator, 1);
			}
		}
示例#2
0
        public void DrawText(RectangleF r, StringSegment _string_, nk_font font, Color bg, Color fg)
        {
            var         text_width = (float)0;
            CommandText cmd;

            if (_string_.IsNullOrEmpty || bg.A == 0 && fg.A == 0)
            {
                return;
            }
            if (UseClipping)
            {
                if (Clip.Width == 0 || Clip.Height == 0 ||
                    !!(Clip.X > r.X + r.Width || Clip.X + Clip.Width < r.X || Clip.Y > r.Y + r.Height ||
                       Clip.Y + Clip.Height < r.Y))
                {
                    return;
                }
            }

            text_width = font.width(_string_);
            if (text_width > r.Width)
            {
                var glyphs    = 0;
                var txt_width = text_width;
                var length    = font.nk_text_clamp(_string_, r.Width, out glyphs, out txt_width, null, 0);

                _string_.Length = length;
            }

            if (_string_.IsNullOrEmpty)
            {
                return;
            }
            cmd = (CommandText)Push(CommandType.Text);
            if (cmd == null)
            {
                return;
            }
            cmd.X          = (short)r.X;
            cmd.Y          = (short)r.Y;
            cmd.Width      = (ushort)r.Width;
            cmd.Height     = (ushort)r.Height;
            cmd.Background = bg;
            cmd.Foreground = fg;
            cmd.Font       = font;
            cmd.FontHeight = font.Size;
            cmd.Text       = _string_;
        }