예제 #1
0
        /*
         * Purely invalidating the layout as text is added to the TextBox will not cause it to expand.
         * If the TextBox is set to WordWrap and it is part of the layout it will refuse to Measure itself beyond its established width.
         * Even giving it infinite constraints will cause it to always set its DesiredSize to the same width but with a vertical growth.
         * The only way I was able to grow it was by setting layout renderers width explicitly to some value but then it just set its own Width to that Width which is not helpful.
         * Even vertically it would measure oddly in cases of rapid text changes.
         * Holding down the backspace key or enter key would cause the final result to be not quite right.
         * Both of these issues were fixed by just creating a static TextBox that is not part of the layout which let me just measure
         * the size of the text as it would fit into the TextBox unconstrained and then just return that Size from the GetDesiredSize call.
         * */
        Size GetCopyOfSize(FormsTextBox control, global::Windows.Foundation.Size constraint)
        {
            if (_copyOfTextBox == null)
            {
                _copyOfTextBox = CreateTextBox();

                // This causes the copy to be initially setup correctly.
                // I found that if the first measure of this copy occurs with Text then it will just keep defaulting to a measure with no text.
                _copyOfTextBox.Measure(_zeroSize);
            }

            _copyOfTextBox.Text        = control.Text;
            _copyOfTextBox.FontSize    = control.FontSize;
            _copyOfTextBox.FontFamily  = control.FontFamily;
            _copyOfTextBox.FontStretch = control.FontStretch;
            _copyOfTextBox.FontStyle   = control.FontStyle;
            _copyOfTextBox.FontWeight  = control.FontWeight;
            _copyOfTextBox.Margin      = control.Margin;
            _copyOfTextBox.Padding     = control.Padding;

            // have to reset the measure to zero before it will re-measure itself
            _copyOfTextBox.Measure(_zeroSize);
            _copyOfTextBox.Measure(constraint);

            Size result = new Size
                          (
                Math.Ceiling(_copyOfTextBox.DesiredSize.Width),
                Math.Ceiling(_copyOfTextBox.DesiredSize.Height)
                          );

            return(result);
        }
예제 #2
0
        protected override global::Windows.Foundation.Size ArrangeOverride(global::Windows.Foundation.Size finalSize)
        {
            if (Element == null)
            {
                return(finalSize);
            }

            double childHeight = Math.Max(0, Math.Min(Element.Height, Control.DesiredSize.Height));
            var    rect        = new WRect();

            switch (Element.VerticalTextAlignment)
            {
            case TextAlignment.Start:
                break;

            default:
            case TextAlignment.Center:
                rect.Y = (int)((finalSize.Height - childHeight) / 2);
                break;

            case TextAlignment.End:
                rect.Y = finalSize.Height - childHeight;
                break;
            }
            rect.Height = childHeight;
            rect.Width  = finalSize.Width;

            Control.Arrange(rect);
            Control.RecalculateSpanPositions(Element, _inlineHeights);
            return(finalSize);
        }
예제 #3
0
 void CreateDrawingSurface(global::Windows.Foundation.Size drawSize)
 {
     _drawingSurface = _graphicsDevice.CreateDrawingSurface(
         drawSize,
         DirectXPixelFormat.B8G8R8A8UIntNormalized,
         DirectXAlphaMode.Premultiplied);
 }
예제 #4
0
        protected override global::Windows.Foundation.Size MeasureOverride(global::Windows.Foundation.Size availableSize)
        {
            var width  = availableSize.Width;
            var height = availableSize.Height;

            if (double.IsInfinity(width))
            {
                width = XamlRoot.Size.Width;
            }

            if (double.IsInfinity(height))
            {
                height = XamlRoot.Size.Height;
            }

            var size = new global::Windows.Foundation.Size(width, height);

            // Measure the children (should only be one, the Page)
            foreach (var child in Children)
            {
                child.Measure(size);
            }

            return(size);
        }
예제 #5
0
        protected override WSize ArrangeOverride(global::Windows.Foundation.Size finalSize)
        {
            var myRect = new WRect(0, 0, finalSize.Width, finalSize.Height);

            if (Control != null)
            {
                Control.Arrange(myRect);
            }

            var mauiContext = Element?.Handler?.MauiContext;

            if (Element is not IVisualTreeElement vte || mauiContext == null)
            {
                return(finalSize);
            }

            var mauiRect = new Graphics.Rectangle(0, 0, finalSize.Width, finalSize.Height);

            foreach (var child in vte.GetVisualChildren())
            {
                if (child is Maui.IElement childElement && childElement.Handler is IPlatformViewHandler nvh)
                {
                    nvh.PlatformArrangeHandler(mauiRect);
                }
            }

            return(finalSize);
        }
예제 #6
0
 private void Update_ImageContent_RecommendSize(global::Windows.Foundation.Size obj, int phase)
 {
     if ((phase & (NOT_PHASED | (1 << 0))) != 0)
     {
         this.Update_ImageContent_RecommendSize_Width(obj.Width, phase);
         this.Update_ImageContent_RecommendSize_Height(obj.Height, phase);
     }
 }
예제 #7
0
        protected override global::Windows.Foundation.Size  MeasureOverride(global::Windows.Foundation.Size availableSize)
        {
            _textBlock.Measure(availableSize);

            // This deliberately does something wrong so we can demo fixing it
            var width = Window.Current.Bounds.Width * (int)DisplayProperties.ResolutionScale / 100;

            return(new global::Windows.Foundation.Size(width, _textBlock.DesiredSize.Height));
        }
예제 #8
0
        protected override global::Windows.Foundation.Size ArrangeOverride(global::Windows.Foundation.Size finalSize)
        {
            if (_formsEmptyView != null)
            {
                _formsEmptyView.Layout(new Rectangle(0, 0, finalSize.Width, finalSize.Height));
            }

            return(base.ArrangeOverride(finalSize));
        }
예제 #9
0
        protected override global::Windows.Foundation.Size ArrangeOverride(global::Windows.Foundation.Size finalSize)
        {
            foreach (var child in Children)
            {
                child.Arrange(new global::Windows.Foundation.Rect(new global::Windows.Foundation.Point(0, 0), finalSize));
            }

            return(finalSize);
        }
예제 #10
0
        static UWPPoint AdjustToCenter(UWPPoint point, UWPSize itemSize, ScrollViewer scrollViewer)
        {
            if (IsVertical(scrollViewer))
            {
                return(AdjustToCenterVertical(point, itemSize, scrollViewer));
            }

            return(AdjustToCenterHorizontal(point, itemSize, scrollViewer));
        }
예제 #11
0
        static UWPPoint AdjustToMakeVisible(UWPPoint point, UWPSize itemSize, ScrollViewer scrollViewer)
        {
            if (IsVertical(scrollViewer))
            {
                return(AdjustToMakeVisibleVertical(point, itemSize, scrollViewer));
            }

            return(AdjustToMakeVisibleHorizontal(point, itemSize, scrollViewer));
        }
예제 #12
0
        protected override global::Windows.Foundation.Size MeasureOverride(global::Windows.Foundation.Size availableSize)
        {
            var result = base.MeasureOverride(availableSize);

            if (!double.IsInfinity(availableSize.Width))
            {
                result.Width = availableSize.Width;
            }
            return(result);
        }
예제 #13
0
        protected override global::Windows.Foundation.Size ArrangeOverride(global::Windows.Foundation.Size finalSize)
        {
            Control.Arrange(new WRect(0, 0, finalSize.Width, finalSize.Height));
            if (Element is IContentView cv)
            {
                cv.CrossPlatformArrange(new Rect(0, 0, finalSize.Width, finalSize.Height));
            }

            return(finalSize);
        }
예제 #14
0
        protected override global::Windows.Foundation.Size MeasureOverride(global::Windows.Foundation.Size availableSize)
        {
            var size = base.MeasureOverride(availableSize);

            if (Element is IContentView cv)
            {
                size = cv.CrossPlatformMeasure(availableSize.Width, availableSize.Height).ToPlatform();
            }

            return(size);
        }
예제 #15
0
        protected override global::Windows.Foundation.Size MeasureOverride(global::Windows.Foundation.Size availableSize)
        {
            _textBlock.Measure(availableSize);

            // This deliberately does something wrong so we can demo fixing it
            var    bounds      = ApplicationView.GetForCurrentView().VisibleBounds;
            double scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
            var    size        = new Size(bounds.Width * scaleFactor, bounds.Height * scaleFactor);

            return(new global::Windows.Foundation.Size(size.Width, _textBlock.DesiredSize.Height));
        }
예제 #16
0
        protected override global::Windows.Foundation.Size MeasureOverride(global::Windows.Foundation.Size constraint)
        {
            if (_invalid)
            {
                Rebuild();
                _invalid = false;
            }

            _implementation !.Measure(new Size(constraint.Width, constraint.Height));
            return(_implementation.DesiredSize.ToWindowsFoundationSize());
        }
예제 #17
0
        protected override global::Windows.Foundation.Size MeasureOverride(global::Windows.Foundation.Size availableSize)
        {
            if (CrossPlatformMeasure == null)
            {
                return(base.MeasureOverride(availableSize));
            }

            var measure = CrossPlatformMeasure(availableSize.Width, availableSize.Height);

            return(measure.ToPlatform());
        }
예제 #18
0
        protected override XamlSize MeasureOverride(
            XamlSize availableSize)
        {
            // NOTE: Children must be measured in order to set the DesiredSize
            // required for the ArrangeOverride implementation.

            // Keep track of the space used by children
            double usedWidth  = 0;
            double usedHeight = 0;

            var remainingSize = availableSize;

            foreach (UIElement child in this.Children)
            {
                child.Measure(remainingSize);

                XamlSize childSize = child.DesiredSize;

                usedWidth += childSize.Width;
                usedHeight = Math.Max(usedHeight, childSize.Height);

                // Update the remaining size
                remainingSize = new XamlSize(
                    Math.Max(0, availableSize.Width - usedWidth),
                    Math.Max(0, availableSize.Height));
            }

            // Calculate the total size used by children
            XamlSize usedSize = new XamlSize(
                Math.Max(0, usedWidth),
                Math.Max(0, usedHeight));

            // Default the final size to the size used by children
            var finalSize = usedSize;

            // Adjust final size for horizontal stretch taking infinity into account
            if ((this.HorizontalAlignment == HorizontalAlignment.Stretch) &&
                (!double.IsInfinity(availableSize.Width)) &&
                (!double.IsNaN(availableSize.Width)))
            {
                finalSize.Width = availableSize.Width;
            }

            // Adjust final size for vertical stretch taking infinity into account
            if ((this.VerticalAlignment == VerticalAlignment.Stretch) &&
                (!double.IsInfinity(availableSize.Height)) &&
                (!double.IsNaN(availableSize.Height)))
            {
                finalSize.Height = availableSize.Height;
            }

            return(finalSize);
        }
예제 #19
0
        protected override global::Windows.Foundation.Size MeasureOverride(global::Windows.Foundation.Size availableSize)
        {
            ListView lv = _listView.Value;

            // set the Cell now that we have a reference to the ListView, since it will have been skipped
            // on DataContextChanged.
            if (_newValue != null)
            {
                SetCell(_newValue);
                _newValue = null;
            }

            if (Content == null)
            {
                if (lv != null)
                {
                    if (lv.HasUnevenRows)
                    {
                        var estimate = (double)lv.GetValue(MeasuredEstimateProperty);
                        if (estimate > -1)
                        {
                            return(new global::Windows.Foundation.Size(availableSize.Width, estimate));
                        }
                    }
                    else
                    {
                        double rowHeight = lv.RowHeight;
                        if (rowHeight > -1)
                        {
                            return(new global::Windows.Foundation.Size(availableSize.Width, rowHeight));
                        }
                    }
                }

                // This needs to return a size with a non-zero height;
                // otherwise, it kills virtualization.
                return(new global::Windows.Foundation.Size(0, Cell.DefaultCellHeight));
            }

            // Children still need measure called on them
            global::Windows.Foundation.Size result = base.MeasureOverride(availableSize);

            if (lv != null)
            {
                lv.SetValue(MeasuredEstimateProperty, result.Height);
            }

            SetDefaultSwitchColor();

            return(result);
        }
예제 #20
0
        protected override global::Windows.Foundation.Size MeasureOverride(global::Windows.Foundation.Size availableSize)
        {
            if (Element?.MeasureOverrideDelegate == null)
            {
                return(base.MeasureOverride(availableSize));
            }

            // The user has specified a different implementation of MeasureOverride
            global::Windows.Foundation.Size?result = Element.MeasureOverrideDelegate(this, availableSize);

            // If the delegate returns a Size, we use it;
            // if it returns null, fall back to the default implementation
            return(result ?? base.MeasureOverride(availableSize));
        }
예제 #21
0
        protected override global::Windows.Foundation.Size ArrangeOverride(global::Windows.Foundation.Size finalSize)
        {
            if (CrossPlatformArrange == null)
            {
                return(base.ArrangeOverride(finalSize));
            }

            var width  = finalSize.Width;
            var height = finalSize.Height;

            var actual = CrossPlatformArrange(new Rectangle(0, 0, width, height));

            return(new global::Windows.Foundation.Size(actual.Width, actual.Height));
        }
예제 #22
0
        protected override global::Windows.Foundation.Size ArrangeOverride(global::Windows.Foundation.Size finalSize)
        {
            if (Element?.ArrangeOverrideDelegate == null)
            {
                return(base.ArrangeOverride(finalSize));
            }

            // The user has specified a different implementation of ArrangeOverride
            global::Windows.Foundation.Size?result = Element.ArrangeOverrideDelegate(this, finalSize);

            // If the delegate returns a Size, we use it;
            // if it returns null, fall back to the default implementation
            return(result ?? base.ArrangeOverride(finalSize));
        }
예제 #23
0
 SizeRequest CalculateDesiredSizes(FormsTextBox control, global::Windows.Foundation.Size constraint, EditorAutoSizeOption sizeOption)
 {
     if (sizeOption == EditorAutoSizeOption.TextChanges)
     {
         Size result = GetCopyOfSize(control, constraint);
         control.Measure(constraint);
         return(new SizeRequest(result));
     }
     else
     {
         control.Measure(constraint);
         Size result = new Size(Math.Ceiling(control.DesiredSize.Width), Math.Ceiling(control.DesiredSize.Height));
         return(new SizeRequest(result));
     }
 }
예제 #24
0
        public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
        {
            if (Children.Count == 0 || Control == null)
            {
                return(new SizeRequest());
            }

            var          constraint = new global::Windows.Foundation.Size(widthConstraint, heightConstraint);
            FormsTextBox child      = Control;

            child.Measure(constraint);
            var result = new Size(Math.Ceiling(child.DesiredSize.Width), Math.Ceiling(child.DesiredSize.Height));

            return(new SizeRequest(result));
        }
예제 #25
0
        protected override global::Windows.Foundation.Size MeasureOverride(global::Windows.Foundation.Size availableSize)
        {
            if (Element == null)
            {
                return(new global::Windows.Foundation.Size(0, 0));
            }

            double width  = Math.Max(0, Element.Width);
            double height = Math.Max(0, Element.Height);
            var    result = new global::Windows.Foundation.Size(width, height);

            Control?.Measure(result);

            return(result);
        }
예제 #26
0
        protected override global::Windows.Foundation.Size ArrangeOverride(global::Windows.Foundation.Size finalSize)
        {
            if (Element == null || Control == null)
            {
                return(finalSize);
            }

            Element.IsInPlatformLayout = true;

            Control?.Arrange(new WRect(0, 0, finalSize.Width, finalSize.Height));

            Element.IsInPlatformLayout = false;

            return(finalSize);
        }
예제 #27
0
        // TODO: Possibly reconcile this code with LayoutPanel.ArrangeOverride
        // If you make changes here please review if those changes should also
        // apply to LayoutPanel.ArrangeOverride
        internal static WSize?LayoutVirtualView(
            this IPlatformViewHandler viewHandler,
            WSize availableSize)
        {
            var virtualView  = viewHandler.VirtualView;
            var platformView = viewHandler.PlatformView;

            if (virtualView == null || platformView == null)
            {
                return(null);
            }

            virtualView.Arrange(new Rect(0, 0, availableSize.Width, availableSize.Height));
            return(availableSize);
        }
예제 #28
0
        public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
        {
            FormsTextBox child = Control;

            if (Children.Count == 0 || child == null)
            {
                return(new SizeRequest());
            }

            var constraint = new global::Windows.Foundation.Size(widthConstraint, heightConstraint);

            child.Measure(constraint);
            var result = FormsTextBox.GetCopyOfSize(child, constraint);

            return(new SizeRequest(result));
        }
예제 #29
0
        static UWPPoint AdjustToMakeVisibleHorizontal(UWPPoint point, UWPSize itemSize, ScrollViewer scrollViewer)
        {
            if (point.X > (scrollViewer.HorizontalOffset + scrollViewer.ViewportWidth))
            {
                return(AdjustToEndHorizontal(point, itemSize, scrollViewer));
            }

            if (point.X >= scrollViewer.HorizontalOffset &&
                point.X < (scrollViewer.HorizontalOffset + scrollViewer.ViewportWidth - itemSize.Width))
            {
                // The target is already in the viewport, no reason to scroll at all
                return(new UWPPoint(scrollViewer.HorizontalOffset, scrollViewer.VerticalOffset));
            }

            return(point);
        }
예제 #30
0
        protected override WSize MeasureOverride(WSize availableSize)
        {
            if (CrossPlatformMeasure == null)
            {
                return(base.MeasureOverride(availableSize));
            }

            var width  = availableSize.Width;
            var height = availableSize.Height;

            var crossPlatformSize = CrossPlatformMeasure(width, height);

            width  = crossPlatformSize.Width;
            height = crossPlatformSize.Height;

            return(new WSize(width, height));
        }
예제 #31
0
		internal static global::Windows.Foundation.Size[] Func_rg__Size__(
					global::System.__ComObject __this, 
					global::System.RuntimeTypeHandle __typeHnd, 
					int __targetIndex)
		{
			// Setup
			global::Windows.Foundation.Size* unsafe___value__retval = default(global::Windows.Foundation.Size*);
			global::Windows.Foundation.Size[] __value__retval = default(global::Windows.Foundation.Size[]);
			uint unsafe___value__retval_mcgLength = 0;
			int unsafe___return__;
			try
			{
				// Marshalling
				unsafe___value__retval = null;
				// Call to native method
				unsafe___return__ = global::McgInterop.ComCallHelpers.ComCall__HRESULT(
									__this, 
									__typeHnd, 
									__targetIndex, 
									&(unsafe___value__retval_mcgLength), 
									&(unsafe___value__retval)
								);
				global::System.Runtime.InteropServices.DebugAnnotations.PreviousCallContainsUserCode();
				if (unsafe___value__retval == null)
					__value__retval = null;
				else
				{
					__value__retval = new global::Windows.Foundation.Size[unsafe___value__retval_mcgLength];
					if (__value__retval != null)
						for (uint mcgIdx = 0; (mcgIdx < unsafe___value__retval_mcgLength); mcgIdx++)
						{
							// [fwd] [out] [retval] [nativebyref] [optional] [Mcg.CodeGen.BlittableValueMarshaller] Windows_Foundation_Size__Windows_Foundation__Size __value__retval
							__value__retval[mcgIdx] = unsafe___value__retval[mcgIdx];
						}
				}
				// Return
				return __value__retval;
			}
			finally
			{
				// Cleanup
				global::System.Runtime.InteropServices.ExternalInterop.SafeCoTaskMemFree(unsafe___value__retval);
			}
		}