diff --git a/Testing/Tests/LabelTests.cs b/Testing/Tests/LabelTests.cs index 349f7d18..abb168dd 100644 --- a/Testing/Tests/LabelTests.cs +++ b/Testing/Tests/LabelTests.cs @@ -51,7 +51,7 @@ namespace Xwt var la = new Label ("Some text here"); la.TextAlignment = Alignment.Center; la.BackgroundColor = Xwt.Drawing.Colors.LightGray; - CheckWidgetRender ("Label.AlignCenter", la); + CheckWidgetRender ("Label.AlignCenter.png", la); } [Test] @@ -62,7 +62,25 @@ namespace Xwt la.Wrap = WrapMode.Word; la.WidthRequest = 200; la.BackgroundColor = Xwt.Drawing.Colors.LightGray; - CheckWidgetRender ("Label.AlignCenterWrapped", la); + CheckWidgetRender ("Label.AlignCenterWrapped.png", la); + } + + [Test] + public void AlignCenterWrappedChangeText () + { + var la = new Label ("Some text here"); + la.TextAlignment = Alignment.Center; + la.Wrap = WrapMode.Word; + la.WidthRequest = 200; + + using (var win = new Window { Width = 200, Height = 100 }) { + win.Content = la; + ShowWindow (win); + la.Text = "Some text here Some text here"; + WaitForEvents (); + var img = Toolkit.CurrentEngine.RenderWidget (la); + ReferenceImageManager.CheckImage ("Label.AlignCenterWrappedChangeText.png", img); + } } [Test] @@ -71,7 +89,7 @@ namespace Xwt var la = new Label ("Some text here"); la.TextAlignment = Alignment.Start; la.BackgroundColor = Xwt.Drawing.Colors.LightGray; - CheckWidgetRender ("Label.AlignLeft", la); + CheckWidgetRender ("Label.AlignLeft.png", la); } [Test] @@ -82,7 +100,7 @@ namespace Xwt la.Wrap = WrapMode.Word; la.WidthRequest = 200; la.BackgroundColor = Xwt.Drawing.Colors.LightGray; - CheckWidgetRender ("Label.AlignLeftWrapped", la); + CheckWidgetRender ("Label.AlignLeftWrapped.png", la); } [Test] @@ -91,7 +109,7 @@ namespace Xwt var la = new Label ("Some text here"); la.TextAlignment = Alignment.End; la.BackgroundColor = Xwt.Drawing.Colors.LightGray; - CheckWidgetRender ("Label.AlignRight", la); + CheckWidgetRender ("Label.AlignRight.png", la); } [Test] @@ -102,7 +120,7 @@ namespace Xwt la.Wrap = WrapMode.Word; la.WidthRequest = 200; la.BackgroundColor = Xwt.Drawing.Colors.LightGray; - CheckWidgetRender ("Label.AlignRightWrapped", la); + CheckWidgetRender ("Label.AlignRightWrapped.png", la); } } } diff --git a/Testing/Tests/ReferenceImageVerifierDialog.cs b/Testing/Tests/ReferenceImageVerifierDialog.cs index ceea784d..d04cfdf6 100644 --- a/Testing/Tests/ReferenceImageVerifierDialog.cs +++ b/Testing/Tests/ReferenceImageVerifierDialog.cs @@ -55,13 +55,28 @@ namespace Xwt nameLabel.Font = nameLabel.Font.WithWeight (Xwt.Drawing.FontWeight.Bold); img1 = new ImageView (); - table.Add (img1, 0, 2, hexpand:true, vexpand:true); + var frame = new FrameBox { + Content = img1, + BorderColor = Xwt.Drawing.Colors.Gray, + BorderWidth = 1 + }; + table.Add (frame, 0, 2, hexpand:true, vexpand:true, hpos:WidgetPlacement.Center, vpos:WidgetPlacement.Center); imgDiff = new ImageView (); - table.Add (imgDiff, 1, 2, hexpand:true, vexpand:true); + frame = new FrameBox { + Content = imgDiff, + BorderColor = Xwt.Drawing.Colors.Gray, + BorderWidth = 1 + }; + table.Add (frame, 1, 2, hexpand:true, vexpand:true, hpos:WidgetPlacement.Center, vpos:WidgetPlacement.Center); img2 = new ImageView (); - table.Add (img2, 2, 2, hexpand:true, vexpand:true); + frame = new FrameBox { + Content = img2, + BorderColor = Xwt.Drawing.Colors.Gray, + BorderWidth = 1 + }; + table.Add (frame, 2, 2, hexpand:true, vexpand:true, hpos:WidgetPlacement.Center, vpos:WidgetPlacement.Center); var buttonBox = new HBox (); table.Add (buttonBox, 0, 3, colspan:2, hexpand:true); diff --git a/Testing/Tests/ReferenceImages/Label.AlignCenter b/Testing/Tests/ReferenceImages/Label.AlignCenter.png similarity index 100% rename from Testing/Tests/ReferenceImages/Label.AlignCenter rename to Testing/Tests/ReferenceImages/Label.AlignCenter.png diff --git a/Testing/Tests/ReferenceImages/Label.AlignCenterWrapped b/Testing/Tests/ReferenceImages/Label.AlignCenterWrapped.png similarity index 100% rename from Testing/Tests/ReferenceImages/Label.AlignCenterWrapped rename to Testing/Tests/ReferenceImages/Label.AlignCenterWrapped.png diff --git a/Testing/Tests/ReferenceImages/Label.AlignCenterWrappedChangeText.png b/Testing/Tests/ReferenceImages/Label.AlignCenterWrappedChangeText.png new file mode 100644 index 00000000..f1398bc9 Binary files /dev/null and b/Testing/Tests/ReferenceImages/Label.AlignCenterWrappedChangeText.png differ diff --git a/Testing/Tests/ReferenceImages/Label.AlignLeft b/Testing/Tests/ReferenceImages/Label.AlignLeft.png similarity index 100% rename from Testing/Tests/ReferenceImages/Label.AlignLeft rename to Testing/Tests/ReferenceImages/Label.AlignLeft.png diff --git a/Testing/Tests/ReferenceImages/Label.AlignLeftWrapped b/Testing/Tests/ReferenceImages/Label.AlignLeftWrapped.png similarity index 100% rename from Testing/Tests/ReferenceImages/Label.AlignLeftWrapped rename to Testing/Tests/ReferenceImages/Label.AlignLeftWrapped.png diff --git a/Testing/Tests/ReferenceImages/Label.AlignRight b/Testing/Tests/ReferenceImages/Label.AlignRight.png similarity index 100% rename from Testing/Tests/ReferenceImages/Label.AlignRight rename to Testing/Tests/ReferenceImages/Label.AlignRight.png diff --git a/Testing/Tests/ReferenceImages/Label.AlignRightWrapped b/Testing/Tests/ReferenceImages/Label.AlignRightWrapped.png similarity index 100% rename from Testing/Tests/ReferenceImages/Label.AlignRightWrapped rename to Testing/Tests/ReferenceImages/Label.AlignRightWrapped.png diff --git a/Xwt.Gtk/Xwt.GtkBackend/LabelBackend.cs b/Xwt.Gtk/Xwt.GtkBackend/LabelBackend.cs index c9e7ea74..e7a7f691 100644 --- a/Xwt.Gtk/Xwt.GtkBackend/LabelBackend.cs +++ b/Xwt.Gtk/Xwt.GtkBackend/LabelBackend.cs @@ -175,15 +175,20 @@ namespace Xwt.GtkBackend Label.Layout.GetPixelSize (out unused, out wrapHeight); if (wrapWidth != args.Allocation.Width || oldHeight != wrapHeight) { wrapWidth = args.Allocation.Width; - // GTK renders the text using the calculated pixel width, not the allocated width. - // If the calculated width is smaller and text is not left aligned, then a gap is - // shown at the right of the label. We then have the adjust the allocation. - if (Label.Justify == Gtk.Justification.Right) - Label.Xpad = wrapWidth - unused; - else if (Label.Justify == Gtk.Justification.Center) - Label.Xpad = (wrapWidth - unused) / 2; Label.QueueResize (); } + // GTK renders the text using the calculated pixel width, not the allocated width. + // If the calculated width is smaller and text is not left aligned, then a gap is + // shown at the right of the label. We then have the adjust the allocation. + if (Label.Justify == Gtk.Justification.Right) { + var w = wrapWidth - unused; + if (w != Label.Xpad) + Label.Xpad = w; + } else if (Label.Justify == Gtk.Justification.Center) { + var w = (wrapWidth - unused) / 2; + if (w != Label.Xpad) + Label.Xpad = w; + } } void HandleLabelDynamicSizeRequest (object o, Gtk.SizeRequestedArgs args)