示例#1
0
		public static void WidgetText(this CommandBuffer o, RectangleF b, StringSegment _string_, nk_text* t,
			nk_text_align a, nk_font f)
		{
			var label = new RectangleF();
			float text_width;
			if (o == null || t == null)
				return;
			b.Height = b.Height < 2 * t->padding.Y ? 2 * t->padding.Y : b.Height;
			label.X = 0;
			label.Width = 0;
			label.Y = b.Y + t->padding.Y;
			label.Height = f.Size < b.Height - 2 * t->padding.Y ? f.Size : b.Height - 2 * t->padding.Y;
			text_width = f.width(_string_);
			text_width += 2.0f * t->padding.X;
			if ((a & nk_text_align.NK_TEXT_ALIGN_LEFT) != 0)
			{
				label.X = b.X + t->padding.X;
				label.Width = 0 < b.Width - 2 * t->padding.X ? b.Width - 2 * t->padding.X : 0;
			}
			else if ((a & nk_text_align.NK_TEXT_ALIGN_CENTERED) != 0)
			{
				label.Width = 1 < 2 * t->padding.X + text_width ? 2 * t->padding.X + text_width : 1;
				label.X = b.X + t->padding.X + (b.Width - 2 * t->padding.X - label.Width) / 2;
				label.X = b.X + t->padding.X < label.X ? label.X : b.X + t->padding.X;
				label.Width = b.X + b.Width < label.X + label.Width ? b.X + b.Width : label.X + label.Width;
				if (label.Width >= label.X)
					label.Width -= label.X;
			}
			else if ((a & nk_text_align.NK_TEXT_ALIGN_RIGHT) != 0)
			{
				label.X =
					b.X + t->padding.X < b.X + b.Width - (2 * t->padding.X + text_width)
						? b.X + b.Width - (2 * t->padding.X + text_width)
						: b.X + t->padding.X;
				label.Width = text_width + 2 * t->padding.X;
			}
			else
			{
				return;
			}

			if ((a & nk_text_align.NK_TEXT_ALIGN_MIDDLE) != 0)
			{
				label.Y = b.Y + b.Height / 2.0f - f.Size / 2.0f;
				label.Height =
					b.Height / 2.0f < b.Height - (b.Height / 2.0f + f.Size / 2.0f)
						? b.Height - (b.Height / 2.0f + f.Size / 2.0f)
						: b.Height / 2.0f;
			}
			else if ((a & nk_text_align.NK_TEXT_ALIGN_BOTTOM) != 0)
			{
				label.Y = b.Y + b.Height - f.Size;
				label.Height = f.Size;
			}

			o.DrawText(label, _string_, f, t->Background,
				t->text);
		}
示例#2
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);
			}
		}