diff options
author | Samantha Houts <samantha@teamredwall.com> | 2017-03-14 03:51:28 -0700 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2017-03-22 10:52:57 +0000 |
commit | 16f142344a83e2f8386257b7677e122ef5ab402c (patch) | |
tree | 85ea9803bdccc587b2fe06c5005c68874a15dfe3 /Xamarin.Forms.Platform.WinRT | |
parent | 69ff55a62fd2e35bd945513fcf594d3541ea6651 (diff) | |
download | xamarin-forms-16f142344a83e2f8386257b7677e122ef5ab402c.tar.gz xamarin-forms-16f142344a83e2f8386257b7677e122ef5ab402c.tar.bz2 xamarin-forms-16f142344a83e2f8386257b7677e122ef5ab402c.zip |
[Win] Labels will now wrap when inside horizontally infinite layouts (#639)
* Add repro for 42559
* [Win] Override GetDesiredSize for LabelRenderer
* [Win] Invalidate size on font/align change
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT')
-rw-r--r-- | Xamarin.Forms.Platform.WinRT/LabelRenderer.cs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/LabelRenderer.cs b/Xamarin.Forms.Platform.WinRT/LabelRenderer.cs index 33f1fee3..5101b167 100644 --- a/Xamarin.Forms.Platform.WinRT/LabelRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/LabelRenderer.cs @@ -35,6 +35,8 @@ namespace Xamarin.Forms.Platform.WinRT { bool _fontApplied; bool _isInitiallyDefault; + SizeRequest _perfectSize; + bool _perfectSizeValid; protected override Windows.Foundation.Size ArrangeOverride(Windows.Foundation.Size finalSize) { @@ -61,6 +63,29 @@ namespace Xamarin.Forms.Platform.WinRT return finalSize; } + public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint) + { + if (!_perfectSizeValid) + { + _perfectSize = base.GetDesiredSize(double.PositiveInfinity, double.PositiveInfinity); + _perfectSize.Minimum = new Size(Math.Min(10, _perfectSize.Request.Width), _perfectSize.Request.Height); + _perfectSizeValid = true; + } + + if (widthConstraint >= _perfectSize.Request.Width && heightConstraint >= _perfectSize.Request.Height) + return _perfectSize; + + var result = base.GetDesiredSize(widthConstraint, heightConstraint); + result.Minimum = new Size(Math.Min(10, result.Request.Width), result.Request.Height); + if (Element.LineBreakMode != LineBreakMode.NoWrap) + { + if (result.Request.Width > widthConstraint || Element.LineBreakMode == LineBreakMode.WordWrap || Element.LineBreakMode == LineBreakMode.CharacterWrap) + result.Request = new Size(Math.Max(result.Minimum.Width, widthConstraint), result.Request.Height); + } + + return result; + } + protected override void OnElementChanged(ElementChangedEventArgs<Label> e) { base.OnElementChanged(e); @@ -100,6 +125,8 @@ namespace Xamarin.Forms.Platform.WinRT void UpdateAlign(TextBlock textBlock) { + _perfectSizeValid = false; + if (textBlock == null) return; @@ -129,6 +156,8 @@ namespace Xamarin.Forms.Platform.WinRT void UpdateFont(TextBlock textBlock) { + _perfectSizeValid = false; + if (textBlock == null) return; @@ -146,6 +175,8 @@ namespace Xamarin.Forms.Platform.WinRT void UpdateLineBreakMode(TextBlock textBlock) { + _perfectSizeValid = false; + if (textBlock == null) return; @@ -164,6 +195,7 @@ namespace Xamarin.Forms.Platform.WinRT textBlock.TextWrapping = TextWrapping.Wrap; break; case LineBreakMode.HeadTruncation: + // TODO: This truncates at the end. textBlock.TextTrimming = TextTrimming.WordEllipsis; textBlock.TextWrapping = TextWrapping.NoWrap; break; @@ -172,6 +204,7 @@ namespace Xamarin.Forms.Platform.WinRT textBlock.TextWrapping = TextWrapping.NoWrap; break; case LineBreakMode.MiddleTruncation: + // TODO: This truncates at the end. textBlock.TextTrimming = TextTrimming.WordEllipsis; textBlock.TextWrapping = TextWrapping.NoWrap; break; @@ -182,6 +215,8 @@ namespace Xamarin.Forms.Platform.WinRT void UpdateText(TextBlock textBlock) { + _perfectSizeValid = false; + if (textBlock == null) return; |