From 75535dd38e52578246690dfd5adb0b6163d1bdcc Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Thu, 9 Nov 2017 18:12:02 -0800 Subject: [PATCH] Fix the size of renderer controls --- Ooui.Forms/Extensions/ElementExtensions.cs | 2 +- Ooui.Forms/IVisualElementRenderer.cs | 2 ++ Ooui.Forms/Renderers/ViewRenderer.cs | 11 +++++++++++ Ooui.Forms/VisualElementRenderer.cs | 4 ++++ Ooui.Forms/VisualElementTracker.cs | 1 + 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Ooui.Forms/Extensions/ElementExtensions.cs b/Ooui.Forms/Extensions/ElementExtensions.cs index 1fa4ec1..eb64812 100644 --- a/Ooui.Forms/Extensions/ElementExtensions.cs +++ b/Ooui.Forms/Extensions/ElementExtensions.cs @@ -8,7 +8,7 @@ namespace Ooui.Forms.Extensions public static SizeRequest GetSizeRequest (this Ooui.Element self, double widthConstraint, double heightConstraint, double minimumWidth = -1, double minimumHeight = -1) { - Size s = self.Text.MeasureSize (self.Style); + var s = self.Text.MeasureSize (self.Style); var request = new Size ( double.IsPositiveInfinity (s.Width) ? double.PositiveInfinity : s.Width, diff --git a/Ooui.Forms/IVisualElementRenderer.cs b/Ooui.Forms/IVisualElementRenderer.cs index e59decc..95f5cd1 100644 --- a/Ooui.Forms/IVisualElementRenderer.cs +++ b/Ooui.Forms/IVisualElementRenderer.cs @@ -16,5 +16,7 @@ namespace Ooui.Forms void SetElementSize (Size size); SizeRequest GetDesiredSize (double widthConstraint, double heightConstraint); + + void SetControlSize (Size size); } } diff --git a/Ooui.Forms/Renderers/ViewRenderer.cs b/Ooui.Forms/Renderers/ViewRenderer.cs index 04f85f7..75dfb02 100644 --- a/Ooui.Forms/Renderers/ViewRenderer.cs +++ b/Ooui.Forms/Renderers/ViewRenderer.cs @@ -97,6 +97,17 @@ namespace Ooui.Forms.Renderers this.AppendChild (uiview); } + public override void SetControlSize (Size size) + { + if (Control != null) { + //Control.Style.Position = "absolute"; + //Control.Style.Left = "0px"; + //Control.Style.Top = "0px"; + Control.Style.Width = size.Width + "px"; + Control.Style.Height = size.Height + "px"; + } + } + protected override void SendVisualElementInitialized (VisualElement element, Ooui.Element nativeView) { base.SendVisualElementInitialized (element, Control); diff --git a/Ooui.Forms/VisualElementRenderer.cs b/Ooui.Forms/VisualElementRenderer.cs index 36c4825..a9f9af1 100644 --- a/Ooui.Forms/VisualElementRenderer.cs +++ b/Ooui.Forms/VisualElementRenderer.cs @@ -129,6 +129,10 @@ namespace Ooui.Forms Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Element, new Rectangle (Element.X, Element.Y, size.Width, size.Height)); } + public virtual void SetControlSize (Size size) + { + } + protected virtual void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e) { if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName) { diff --git a/Ooui.Forms/VisualElementTracker.cs b/Ooui.Forms/VisualElementTracker.cs index ab65c78..6b1fdd7 100644 --- a/Ooui.Forms/VisualElementTracker.cs +++ b/Ooui.Forms/VisualElementTracker.cs @@ -145,6 +145,7 @@ namespace Ooui.Forms uiview.Style.Top = y + "px"; uiview.Style.Width = width + "px"; uiview.Style.Height = height + "px"; + Renderer.SetControlSize (new Size (width, height)); } else if (width <= 0 || height <= 0) { return;