public void Measure_should_use_measure_all_content() { var box = new Size(20, 30); var font1 = new FontInfo("Test", 14); var font2 = new FontInfo("Test", 16); var textBox = new TextBox(); textBox.AddComponent(new Label { Text = "foo bar", Font = font1 }); textBox.AddComponent(new Link { Text = "baz", Font = font2 }); textBox.Measure(box, TestRendererContext.Instance); textBox.DesiredSize.ShouldBe(new Size("foo bar baz".Length, (int)Math.Ceiling(TestRendererContext.Instance.GetHeight(font2)))); }
public void It_should_render_text_with_alignments() { var renderer = new BitmapRenderer(); var labelBox = new HBox { Width = SizeUnit.Unlimited }; foreach (var align in new[] { TextAlignment.Left, TextAlignment.Right, TextAlignment.Center, TextAlignment.Justify }) { labelBox.AddComponent(new Panel { Width = 100, Height = SizeUnit.Unlimited, BackgroundColor = Color.Yellow, Margin = new Spacer(1), Border = new Border(1, Color.White), Padding = new Spacer(2), Inner = new Label { Width = SizeUnit.Unlimited, TextColor = Color.Red, TextAlignment = align, Font = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic), Text = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?" } }); } var areaBox = new HBox { Width = SizeUnit.Unlimited }; foreach (var align in new[] { TextAlignment.Left, TextAlignment.Right, TextAlignment.Center, TextAlignment.Justify }) { var textBox = new TextBox { Width = SizeUnit.Unlimited, TextAlignment = align }; textBox.AddComponent(new Label { TextColor = Color.Red, Text = "Hi Bob!", Font = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic) }); textBox.AddComponent(new Link { TextColor = Color.Black, Text = "Check out this: ", Font = new FontInfo(TestFontFamily.Serif, 12, FontInfoStyle.Regular) }); textBox.AddComponent(new Link { TextColor = Color.Purple, Text = "great link!!!", Font = new FontInfo(TestFontFamily.Serif, 8, FontInfoStyle.Underline), Uri = "http://google.com" }); areaBox.AddComponent(new Panel { Width = 100, Height = SizeUnit.Unlimited, BackgroundColor = Color.Green, Margin = new Spacer(1), Border = new Border(1, Color.White), Padding = new Spacer(2), Inner = textBox }); } var content = new VBox { Width = SizeUnit.Unlimited }; content.AddComponent(labelBox); content.AddComponent(areaBox); var form = new Form(content); var bmp = new Bitmap(400, 400); renderer.Render(form, bmp); BitmapComparer.CompareBitmaps("text_box_align", bmp); }
public void It_should_render_text() { var renderer = new BitmapRenderer(); var content = new HBox { Width = SizeUnit.Unlimited }; content.AddComponent(new Panel { Width = 100, Height = SizeUnit.Unlimited, BackgroundColor = Color.Yellow, Margin = new Spacer(1), Border = new Border(1, Color.White), Padding = new Spacer(2), Inner = new Label { TextColor = Color.Red, Font = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic), Text = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?" } }); content.AddComponent(new Panel { Width = 100, Height = SizeUnit.Unlimited, BackgroundColor = Color.DarkSeaGreen, Margin = new Spacer(1), Border = new Border(1, Color.White), Padding = new Spacer(2), Inner = new Link { TextColor = Color.Blue, Font = new FontInfo(TestFontFamily.Serif, 14, FontInfoStyle.Bold), Text = "How are you doing today?", Uri = "http://google.com" } }); var textBox = new TextBox(); textBox.AddComponent(new Label { Text = "Hello!\n", TextColor = Color.Green, Font = new FontInfo(TestFontFamily.Monospace, 20, FontInfoStyle.Underline) }); textBox.AddComponent(new Label { Text = "Hi Bob, nice to see you after", TextColor = Color.Black, Font = new FontInfo(TestFontFamily.SansSerif, 10) }); textBox.AddComponent(new Label { Text = "20", TextColor = Color.Red, Font = new FontInfo(TestFontFamily.SansSerif, 10, FontInfoStyle.Bold) }); textBox.AddComponent(new Label { Text = "years!\n", TextColor = Color.Black, Font = new FontInfo(TestFontFamily.SansSerif, 10) }); textBox.AddComponent(new Label { Text = "I'm sure you'd love to see my new", TextColor = Color.Black, Font = new FontInfo(TestFontFamily.SansSerif, 10) }); textBox.AddComponent(new Link { Text = "web", TextColor = Color.Blue, Font = new FontInfo(TestFontFamily.SansSerif, 12, FontInfoStyle.Italic), Uri = "http://google.com" }); textBox.AddComponent(new Link { Text = "site", TextColor = Color.Green, TextContinuation = true, Font = new FontInfo(TestFontFamily.SansSerif, 12, FontInfoStyle.Italic), Uri = "http://google.com" }); content.AddComponent(new Panel { Width = SizeUnit.Unlimited, Height = SizeUnit.Unlimited, BackgroundColor = Color.LightYellow, Margin = new Spacer(1), Border = new Border(1, Color.White), Padding = new Spacer(2), Inner = textBox }); var form = new Form(content); var bmp = new Bitmap(320, 400); renderer.Render(form, bmp); BitmapComparer.CompareBitmaps("text_box", bmp); }