Ejemplo n.º 1
0
        private static Task <DropDownListSelection <T> > ShowInternal <T>(
            UIView containerView,
            object anchorUIElement,
            UITableViewCellStyle itemStyle,
            UITableViewStyle viewStyle,
            IEnumerable <T> items,
            Func <T, GenericCellDescriptor> itemDescriber,
            string dropDownTitle,
            UIPopoverArrowDirection arrowDirection,
            CGSize?fitSize
            )
        {
            if (itemDescriber == null)
            {
                throw new ArgumentNullException("displayNameGetter");
            }

            return(ShowInternal(
                       containerView,
                       anchorUIElement,
                       itemStyle,
                       viewStyle,
                       new [] { items },
                       (s) => new GenericTableViewSection <T>(dropDownTitle, items),
                       itemDescriber,
                       arrowDirection,
                       fitSize
                       ));
        }
Ejemplo n.º 2
0
 protected void SetCGSizeValue(NSString key, CGSize?value)
 {
     if (NullCheckAndRemoveKey(key, !value.HasValue))
     {
         Dictionary [key] = value.Value.ToDictionary();
     }
 }
Ejemplo n.º 3
0
        private void Initialize(
            UIImage verticalIcon,
            UIImage landscapeIcon,
            CGSize?verticalSize,
            CGSize?landscapeSize,
            SemiTransparentType semiTransparentType = SemiTransparentType.None)
        {
            _background = new Circle {
                UserInteractionEnabled = false
            };

            _background.Layer.ShadowColor   = ThemeColors.ContentDarkBackground.CGColor;
            _background.Layer.ShadowOpacity = 0.13f;
            _background.Layer.ShadowOffset  = new CGSize(2, 2);

            Add(_background);

            VerticalIcon        = verticalIcon;
            LandscapeIcon       = landscapeIcon;
            VerticalSize        = verticalSize ?? DefaultVerticalSize;
            LandscapeSize       = landscapeSize ?? DefaultLandscapeSize;
            SemiTransparentType = semiTransparentType;
            UpdateBackgroundState();

            TouchDown += (sender, e) =>
                         _background.FillColor = ThemeColors.ContentLightHighlight.ColorWithAlpha(0.58f);
            TouchUpInside  += (sender, e) => UpdateBackgroundState();
            TouchUpOutside += (sender, e) => UpdateBackgroundState();
        }
        private CGSize PrepareLayout(bool createLayoutInfo, CGSize?size = null)
        {
            using (
                _trace.WriteEventActivity(
                    TraceProvider.ListViewBaseLayout_PrepareLayoutStart,
                    TraceProvider.ListViewBaseLayout_PrepareLayoutStop
                    )
                )
            {
                if (size.HasValue && _lastAvailableSize != size)
                {
                    _dirtyState = DirtyState.NeedsRelayout;
                }

                if (_dirtyState == DirtyState.NeedsRelayout)
                {
                    _lastReportedSize  = PrepareLayoutInternal(createLayoutInfo, size);
                    _lastAvailableSize = size ?? CGSize.Empty;

                    if (createLayoutInfo)
                    {
                        _dirtyState = DirtyState.None;
                        (CollectionView as ListViewBase)?.SetLayoutCreated();
                    }
                }
                else if (_dirtyState == DirtyState.NeedsHeaderRelayout)
                {
                    UpdateHeaderPositions();
                    _dirtyState = DirtyState.None;
                }

                return(_lastReportedSize);
            }
        }
Ejemplo n.º 5
0
        public void Begin(CGRect frame, NSView controlView)
        {
            var size = controlView.Frame.Size;

            if (size.Width <= 0 || size.Height <= 0)
            {
                _realSize = null;
                return;
            }
            if (_image == null || size != _image.Size)
            {
                if (_image != null)
                {
                    _image.Dispose();
                }

                _image = new NSImage(size);
            }

            if (supportsConvertSizeToBacking)
            {
                _realSize = controlView.ConvertSizeToBacking(size);
            }
            else
            {
                _realSize = controlView.ConvertSizeToBase(size);
            }

            _image.LockFocusFlipped(!controlView.IsFlipped);
            NSGraphicsContext.CurrentContext.GraphicsPort.ClearRect(new CGRect(CGPoint.Empty, size));
        }
Ejemplo n.º 6
0
        private static void MakeMask(this UIView view,
                                     Func <CGRect, UIBezierPath> getPath,
                                     CGSize?size = null)
        {
            var       maskWidth  = !size.HasValue ? view.Frame.Width : size.Value.Width;
            var       maskHeight = !size.HasValue ? view.Frame.Height : size.Value.Height;
            const int maskGap    = 0;

            var path  = getPath(new CGRect(0, 0, maskWidth, maskHeight));
            var frame = new CGRect(maskGap, maskGap,
                                   maskGap + maskWidth,
                                   maskGap + maskHeight);

            var maskLayer = view.Layer.Mask as CAShapeLayer;

            if (maskLayer != null)
            {
                maskLayer.Frame = frame;
                maskLayer.Path  = path.CGPath;
            }
            else
            {
                var mask = new CAShapeLayer {
                    Frame = frame,
                    Path  = path.CGPath
                };

                view.Layer.Mask = mask;
            }
        }
Ejemplo n.º 7
0
 public GenericTableViewCell(UITableViewCellStyle style, string reuseID, CGSize?imageViewSize = null) : base(style, reuseID, false)
 {
     _imageViewSize = imageViewSize != null ? imageViewSize.Value : new CGSize(DefaultImageViewWidth, DefaultImageViewHeight);
     if (ImageView != null)
     {
         ImageView.Layer.MasksToBounds = true;
     }
 }
Ejemplo n.º 8
0
        public override CGSize SizeThatFits(CGSize size)
        {
            var hasSameDesiredSize =
                !_measureInvalidated &&
                _previousAvailableSize != null &&
                _previousDesiredSize.Width == size.Width &&
                _previousDesiredSize.Height == size.Height;

            var isSingleLineNarrower =
                !_measureInvalidated &&
                _previousAvailableSize != null &&
                _previousDesiredSize.Width <= size.Width &&
                _previousDesiredSize.Height == size.Height;

            if (hasSameDesiredSize || isSingleLineNarrower)
            {
                return(_previousDesiredSize);
            }
            else
            {
                _previousAvailableSize = size;
                _measureInvalidated    = false;

                UpdateTypography();

                var horizontalPadding = Padding.Left + Padding.Right;
                var verticalPadding   = Padding.Top + Padding.Bottom;

                // available size considering min/max width/height
                // necessary, because the height of a wrapping TextBlock depends on its width
                size = IFrameworkElementHelper.SizeThatFits(this, size);

                // available size considering padding
                size.Width  -= (nfloat)horizontalPadding;
                size.Height -= (nfloat)verticalPadding;

                var result = base.SizeThatFits(size);

                if (result.Height == 0)                 // this can happen when Text is null or empty
                {
                    // This measures the height correctly, even if the Text is null or empty
                    // This matches Windows where empty TextBlocks still have a height (especially useful when measuring ListView items with no DataContext)
                    result = (Text ?? NSString.Empty).StringSize(this.Font, size);
                }

                if (AdjustsFontSizeToFitWidth && !nfloat.IsNaN(size.Width))
                {
                    result.Width = size.Width;
                }

                result.Width  += (nfloat)horizontalPadding;
                result.Height += (nfloat)verticalPadding;

                result = IFrameworkElementHelper.SizeThatFits(this, result);
                return(_previousDesiredSize = new CGSize(Math.Ceiling(result.Width), Math.Ceiling(result.Height)));
            }
        }
Ejemplo n.º 9
0
        internal CGSize?XamlMeasure(CGSize availableSize)
        {
            if (((ILayouterElement)this).XamlMeasureInternal(availableSize, _lastAvailableSize, out var measuredSize))
            {
                _lastAvailableSize = availableSize;
                _lastMeasure       = measuredSize;
                SetLayoutFlags(LayoutFlag.ArrangeDirty);
            }

            return(_lastMeasure);
        }
Ejemplo n.º 10
0
 public static Task <DropDownListSelection <T> > Show <T>(
     UIBarButtonItem barButton,
     UITableViewCellStyle itemStyle,
     IEnumerable <T> items,
     Func <T, GenericCellDescriptor> itemDescriber,
     string dropDownTitle                   = null,
     UITableViewStyle headerStyle           = UITableViewStyle.Plain,
     UIPopoverArrowDirection arrowDirection = UIPopoverArrowDirection.Up,
     CGSize?fitSize = null
     )
 {
     return(ShowInternal(null, barButton, itemStyle, headerStyle, items, itemDescriber, dropDownTitle, arrowDirection, fitSize));
 }
Ejemplo n.º 11
0
        private CGSize ResolveItemSize(int currentGroup)
        {
            if ((double.IsNaN(ItemWidth) || double.IsNaN(ItemHeight)) && _implicitItemSize == null)
            {
                //TODO: this should measure the databound item, currently it only measures the empty template
                _implicitItemSize = GetItemSizeForIndexPath(GetNSIndexPathFromRowSection(0, currentGroup));
            }

            return(new CGSize(
                       double.IsNaN(ItemWidth) ? _implicitItemSize.Value.Width : ItemWidth,
                       double.IsNaN(ItemHeight) ? _implicitItemSize.Value.Height : ItemHeight
                       ));
        }
Ejemplo n.º 12
0
 public static Task <DropDownListSelection <TItem> > Show <TSection, TItem>(
     UIBarButtonItem barButton,
     UITableViewCellStyle itemStyle,
     IEnumerable <TSection> sections,
     Func <TSection, GenericTableViewSection <TItem> > sectionDescriber,
     Func <TItem, GenericCellDescriptor> itemDescriber,
     UITableViewStyle headerStyle           = UITableViewStyle.Plain,
     UIPopoverArrowDirection arrowDirection = UIPopoverArrowDirection.Up,
     CGSize?fitSize = null
     ) where TSection : IEnumerable <TItem>
 {
     return(ShowInternal(null, barButton, itemStyle, headerStyle, sections, sectionDescriber, itemDescriber, arrowDirection, fitSize));
 }
Ejemplo n.º 13
0
        public Layout Size(CGSize?size = null)
        {
            var v = Child;

            if (v == null)
            {
                return(debugChildNotAvailableMessage());
            }
            if (size == null)
            {
                size = CGSize.Empty;
            }
            return(this.Size(v, size.Value));
        }
Ejemplo n.º 14
0
        public static ButtonBarButton Create(
            UIImage verticalIcon,
            UIImage landscapeIcon,
            CGSize?verticalSize,
            CGSize?landscapeSize,
            SemiTransparentType semiTransparentType = SemiTransparentType.None)
        {
            var button = new ButtonBarButton(
                verticalIcon,
                landscapeIcon,
                verticalSize,
                landscapeSize,
                semiTransparentType);

            return(button);
        }
Ejemplo n.º 15
0
 public ButtonBarButton(
     UIImage verticalIcon,
     UIImage landscapeIcon,
     CGSize?verticalSize,
     CGSize?landscapeSize,
     SemiTransparentType semiTransparentType = SemiTransparentType.None)
     : base()
 {
     Initialize(
         verticalIcon,
         landscapeIcon,
         verticalSize,
         landscapeSize,
         semiTransparentType);
     UpdateState();
 }
Ejemplo n.º 16
0
        public void PresentMenuStart(CGSize?size = null)
        {
            if (size == null)
            {
                size = SideMenuManager.appScreenRect.Size;
            }

            var menuView           = SideMenuManager.LeftNavigationController?.View;
            var mainViewController = this.viewControllerForPresentedMenu;

            if (menuView == null || mainViewController == null)
            {
                return;
            }

            menuView.Transform = CGAffineTransform.MakeIdentity();
            mainViewController.View.Transform = CGAffineTransform.MakeIdentity();
            var menuFrame = menuView.Frame;

            menuFrame.Size = new CGSize(SideMenuManager.MenuWidth, size.Value.Height);
            menuFrame.X    = (float)(this.PresentDirection == UIRectEdge.Left ? 0 : size.Value.Width - SideMenuManager.MenuWidth);
            menuView.Frame = menuFrame;

            if (this.StatusBarView != null)
            {
                this.StatusBarView.Frame = UIApplication.SharedApplication.StatusBarFrame;
                this.StatusBarView.Alpha = 1;
            }

            int    direction = 0;
            CGRect frame;

            switch (SideMenuManager.PresentMode)
            {
            case SideMenuManager.MenuPresentMode.ViewSlideOut:
                menuView.Alpha = 1;
                direction      = this.PresentDirection == UIRectEdge.Left ? 1 : -1;
                frame          = mainViewController.View.Frame;
                frame.X        = direction * (menuView.Frame.Width);
                mainViewController.View.Frame               = frame;
                mainViewController.View.Layer.ShadowColor   = SideMenuManager.ShadowColor.CGColor;
                mainViewController.View.Layer.ShadowRadius  = (float)SideMenuManager.ShadowRadius;
                mainViewController.View.Layer.ShadowOpacity = (float)SideMenuManager.ShadowOpacity;
                mainViewController.View.Layer.ShadowOffset  = new CGSize(0, 0);
                break;
            }
        }
Ejemplo n.º 17
0
        private CGSize?XamlMeasure(CGSize availableSize)
        {
            // If set layout has not been called, we can
            // return a previously cached result for the same available size.
            if (
                !RequiresMeasure &&
                _lastAvailableSize.HasValue &&
                availableSize == _lastAvailableSize
                )
            {
                return(_lastMeasure);
            }

            _lastAvailableSize = availableSize;
            RequiresMeasure    = false;

            var result = _layouter.Measure(SizeFromUISize(availableSize));

            // Result here exclude the margins on the element
            return(_lastMeasure = result.LogicalToPhysicalPixels());
        }
Ejemplo n.º 18
0
        void InitializeContext(bool viewFlipped)
        {
            Control.SaveState();

                        #if OSX
            // os x has different flipped states (depending on layers, etc), so compensate to make 0,0 at the top-left
            if (view != null)
            {
                // we have a view (drawing directly to the screen), so adjust to where it is
                Control.ClipToRect(view.ConvertRectToView(view.VisibleRect(), null));
                var pos = view.ConvertPointToView(CGPoint.Empty, null);
                if (!viewFlipped)
                {
                    pos.Y += view.Frame.Height;
                }
                currentTransform = new CGAffineTransform(1, 0, 0, -1, (float)pos.X, (float)pos.Y);
                Control.ConcatCTM(currentTransform);
            }
            else
            {
                // drawing to a bitmap or during a drawRect operation
                currentTransform = new CGAffineTransform(1, 0, 0, -1, 0, viewFlipped ? ViewHeight : 0);
                if (viewFlipped)
                {
                    Control.ConcatCTM(currentTransform);
                }
            }

            phase = null;
                        #elif IOS
            if (viewFlipped)
            {
                // on ios, we flip the context if we're drawing on a bitmap otherwise we don't need to
                currentTransform = new CGAffineTransform(1, 0, 0, -1, 0, ViewHeight);
                Control.ConcatCTM(currentTransform);
            }
                        #endif
        }
Ejemplo n.º 19
0
        void UpdateBackground()
        {
            if (_buttonScheme?.ColorScheme is SemanticColorScheme colorScheme)
            {
                var color = Element.BackgroundColor;
                var brush = Element.Background;

                if (Brush.IsNullOrEmpty(brush))
                {
                    if (color.IsDefault)
                    {
                        colorScheme.PrimaryColor   = _defaultButtonScheme.ColorScheme.PrimaryColor;
                        colorScheme.OnSurfaceColor = _defaultButtonScheme.ColorScheme.OnSurfaceColor;
                    }
                    else
                    {
                        UIColor uiColor = color.ToUIColor();

                        colorScheme.PrimaryColor   = uiColor;
                        colorScheme.OnSurfaceColor = uiColor;
                    }
                }
                else
                {
                    var backgroundImage = Control.GetBackgroundImage(brush);
                    _backgroundSize = backgroundImage?.Size;
                    UIColor uiColor = backgroundImage != null?UIColor.FromPatternImage(backgroundImage) : UIColor.Clear;

                    colorScheme.PrimaryColor   = uiColor;
                    colorScheme.OnSurfaceColor = uiColor;
                }

                if (Control != null)
                {
                    ApplyTheme();
                }
            }
        }
Ejemplo n.º 20
0
        private CGSize?XamlMeasure(CGSize availableSize)
        {
            // If set layout has not been called, we can
            // return a previously cached result for the same available size.
            if (
                !RequiresMeasure &&
                _lastAvailableSize.HasValue &&
                availableSize == _lastAvailableSize
                )
            {
                return(_lastMeasure);
            }

            _lastAvailableSize = availableSize;
            RequiresMeasure    = false;

            var result = _layouter.Measure(SizeFromUISize(availableSize));

            result = IFrameworkElementHelper
                     .SizeThatFits(this, result)
                     .ToFoundationSize();

            return(result.LogicalToPhysicalPixels());
        }
        public void SetPhase()
        {
            if (DisplayView == null)
            {
                return;
            }
            if (phase == null)
            {
                // find parent with layer, or goes up to window if none are found
                var layerView = DisplayView;
                while (layerView.Superview != null && layerView.Layer == null)
                {
                    layerView = layerView.Superview;
                }

                // convert bottom-left point relative to layer or window
                var pos = DisplayView.ConvertPointToView(CGPoint.Empty, layerView);

                // phase should be based on position of control within closest layer or window.
                phase = new CGSize(pos.X, pos.Y);
            }

            Control.SetPatternPhase(phase.Value);
        }
Ejemplo n.º 22
0
		public void SetPhase()
		{
			if (DisplayView == null)
				return;
			if (phase == null)
			{
				// find parent with layer, or goes up to window if none are found
				var layerView = DisplayView;
				while (layerView.Superview != null && layerView.Layer == null)
					layerView = layerView.Superview;

				// convert bottom-left point relative to layer or window
				var pos = DisplayView.ConvertPointToView(CGPoint.Empty, layerView);

				// phase should be based on position of control within closest layer or window.
				phase = new CGSize(pos.X, pos.Y);
			}

			Control.SetPatternPhase(phase.Value);
		}
Ejemplo n.º 23
0
		void InitializeContext(bool viewFlipped)
		{
			Control.SaveState();

			#if OSX
			// os x has different flipped states (depending on layers, etc), so compensate to make 0,0 at the top-left
			if (view != null)
			{
				// we have a view (drawing directly to the screen), so adjust to where it is
				Control.ClipToRect(view.ConvertRectToView(view.VisibleRect(), null));
				var pos = view.ConvertPointToView(CGPoint.Empty, null);
				if (!viewFlipped)
					pos.Y += view.Frame.Height;
				Control.ConcatCTM(new CGAffineTransform(1, 0, 0, -1, (float)pos.X, (float)pos.Y));
			}
			else
			{
				// drawing to a bitmap or during a drawRect operation
				if (viewFlipped)
					Control.ConcatCTM(new CGAffineTransform(1, 0, 0, -1, 0, ViewHeight));
			}

			phase = null;

			#elif IOS
			if (viewFlipped)
			{
				// on ios, we flip the context if we're drawing on a bitmap otherwise we don't need to
				Control.ConcatCTM(new CGAffineTransform(1, 0, 0, -1, 0, ViewHeight));
			}
			#endif

			ApplyAll();

		}
Ejemplo n.º 24
0
        protected override CGSize PrepareLayoutInternal(bool createLayoutInfo = false, CGSize?availableSize = null)
        {
            var newLayoutInfo    = new Dictionary <string, Dictionary <NSIndexPath, UICollectionViewLayoutAttributes> >(StringComparer.Ordinal);
            var headerLayoutInfo = new Dictionary <NSIndexPath, UICollectionViewLayoutAttributes>();
            var itemLayoutInfo   = new Dictionary <NSIndexPath, UICollectionViewLayoutAttributes>();

            var contentSize = CGSize.Empty;

            if (CollectionView.NumberOfSections() != 0 && CollectionView.NumberOfItemsInSection(0) != 0)
            {
                _itemSize = GetItemSizeForIndexPath(GetNSIndexPathFromRowSection(0, 0));
            }


            bool hasSectionHeader   = Source.GetTarget()?.Owner.GroupStyle?.HeaderTemplate != null;
            var  sectionTitleHeight = GetSectionHeaderSize().Height;
            var  sectionTitleWidth  = GetSectionHeaderSize().Width;

            var availableWidth  = availableSize?.Width ?? CollectionView.Bounds.Width;
            var availableHeight = availableSize?.Height ?? CollectionView.Bounds.Height;

            switch (ScrollDirection)
            {
            case ListViewBaseScrollDirection.Horizontal:
                contentSize = CreateHorizontalLayout(createLayoutInfo, headerLayoutInfo, itemLayoutInfo, hasSectionHeader, sectionTitleWidth, sectionTitleHeight, availableWidth, availableHeight);
                break;

            case ListViewBaseScrollDirection.Vertical:
                contentSize = CreateVerticalLayout(createLayoutInfo, headerLayoutInfo, itemLayoutInfo, hasSectionHeader, sectionTitleHeight, availableWidth);
                break;
            }

            if (createLayoutInfo)
            {
                newLayoutInfo[ListViewBase.ListViewSectionHeaderElementKind] = headerLayoutInfo;
                newLayoutInfo[GridViewItemKind] = itemLayoutInfo;
                _layoutInfos = newLayoutInfo;

                if (AreStickyGroupHeadersEnabled)
                {
                    UpdateHeaderPositions();
                }
            }

            return(contentSize);
        }
Ejemplo n.º 25
0
        private static async Task <DropDownListSelection <TItem> > ShowInternal <TSection, TItem>(
            UIView containerView,
            object anchorUIElement,
            UITableViewCellStyle itemStyle,
            UITableViewStyle headerStyle,
            IEnumerable <TSection> sections,
            Func <TSection, GenericTableViewSection <TItem> > sectionDescriber,
            Func <TItem, GenericCellDescriptor> itemDescriber,
            UIPopoverArrowDirection arrowDirection,
            CGSize?fitSize
            ) where TSection : IEnumerable <TItem>
        {
            if (anchorUIElement == null)
            {
                throw new ArgumentNullException("anchorView");
            }

            if (!(anchorUIElement is UIView || anchorUIElement is UIBarButtonItem))
            {
                throw new ArgumentOutOfRangeException("anchorView", "Must be a UIView or a UIBarButtonItem");
            }

            var sectionsArray = sections.Select(sectionDescriber).ToArray();


            if (sectionsArray.Count() == 1 && string.IsNullOrWhiteSpace(sectionsArray.First().Title))
            {
                headerStyle = UITableViewStyle.Plain;
            }

            var selectSignal = new ManualResetEventSlim();
            var table        = new UITableViewController(headerStyle);

            table.AutomaticallyAdjustsScrollViewInsets = false;
            var result            = new DropDownListSelection <TItem>();
            var popOverController = new UIPopoverController(table);

            var dropDownSource = new GenericTableViewSource <TItem>(
                table.TableView,
                itemStyle,
                sectionsArray,
                itemDescriber,
                (x) => {
                result.SelectedItem = x;
                popOverController.Dismiss(false);
                selectSignal.Set();
            }
                );

            popOverController.DidDismiss += (object sender, EventArgs e) => {
                if (!selectSignal.IsSet)
                {
                    selectSignal.Set();
                }
            };

            ((UITableView)table.View).Source = dropDownSource;

            // Calculate how wide the view should be by finding how
            if (fitSize == null)
            {
                // calculate the fit size
                var    tableView     = (UITableView)table.View;
                nfloat largestWidth  = 0.0f;
                var    sectionHeight = (headerStyle == UITableViewStyle.Plain ? (float)tableView.SectionHeaderHeight : Tools.iOSTool.DefaultGroupedTableViewHeaderHeight);
                nfloat totalHeight   = sectionHeight * sectionsArray.Count(s => !string.IsNullOrWhiteSpace(s.Title));
                foreach (var section in sectionsArray)
                {
                    foreach (var itemDescriptor in ((IEnumerable <TItem>)section.Items).WithDescriptions())
                    {
                        var index    = itemDescriptor.Index;
                        var item     = itemDescriptor.Description;
                        var cellSize = (CGSize)dropDownSource.GetCell(tableView, (NSIndexPath)(NSIndexPath.FromRowSection(index, 0))).SizeThatFits((CGSize)CGSize.Empty);
                        if (cellSize.Width > largestWidth)
                        {
                            largestWidth = cellSize.Width;
                        }
                        totalHeight += cellSize.Height;
                    }
                }

                fitSize = new CGSize(largestWidth + ItemPadding, totalHeight);
            }
            popOverController.SetPopoverContentSize(fitSize.Value, false);

            TypeSwitch.Do(
                anchorUIElement,
                TypeSwitch.Case <UIBarButtonItem>(bbi =>
                                                  popOverController.PresentFromBarButtonItem(
                                                      (UIBarButtonItem)anchorUIElement,
                                                      arrowDirection,
                                                      true
                                                      )
                                                  ),
                TypeSwitch.Case <UIView>(v =>
                                         popOverController.PresentFromRect(
                                             ((UIView)anchorUIElement).Frame,
                                             containerView,
                                             arrowDirection,
                                             true
                                             )
                                         ),
                TypeSwitch.Case <UITabBarItem>(tb => {
                var tabBar = containerView as UITabBar;
                if (tabBar == null)
                {
                    throw new ArgumentException("Container view must be an UITabBar when the anchor view is an UITabBarItem");
                }

                if (!tabBar.Items.Contains(tb))
                {
                    throw new ArgumentException("Container view UITabBar does not contain the anchor view UITabBarItem");
                }

                var index           = tabBar.Items.IndexOf(tb);
                var tabBarItemWidth = tabBar.Frame.Size.Width / tabBar.Items.Count();
                var rect            = new CGRect(tabBarItemWidth * index, 0f, tabBarItemWidth, tabBar.Frame.Height);

                popOverController.PresentFromRect(
                    rect,
                    tabBar,
                    arrowDirection,
                    true
                    );
            }),
                TypeSwitch.Default(() => { throw new NotSupportedException("anchorUIElement was {0}".FormatWith(anchorUIElement.GetType().Name)); })
                );

            await Task.Run(() => selectSignal.Wait());

            table.View.DisposeEx();
            table.TableView.DisposeEx();
            table.Dispose();
            popOverController.Dispose();

            return(result);
        }
Ejemplo n.º 26
0
        void ResizeSubviews(CGSize oldSize2)
        {
            var splitView        = Control;
            var dividerThickness = splitView.DividerThickness;
            var newFrame         = splitView.Frame;

            var panel1Rect = splitView.Subviews[0].Frame;
            var panel2Rect = splitView.Subviews[1].Frame;

            bool isSmall = newFrame.Height <= 1 || newFrame.Width <= 1;

            if (!isSmall && initialPositionSet)
            {
                SetRelative();
            }

            var oldSize = oldSizeCache ?? newFrame.Size;

            oldSizeCache = newFrame.Size;

            if (oldSize.Height <= 0 && oldSize.Width <= 0)
            {
                oldSize = newFrame.Size;
            }

            if (panel1?.Visible != true)
            {
                if (splitView.IsVertical)
                {
                    panel1Rect = new CGRect(0, 0, 0, newFrame.Height);
                    panel2Rect = new CGRect(dividerThickness, 0, newFrame.Width - dividerThickness, newFrame.Height);
                }
                else
                {
                    panel1Rect = new CGRect(0, 0, newFrame.Width, 0);
                    panel2Rect = new CGRect(0, dividerThickness, newFrame.Width, newFrame.Height - dividerThickness);
                }
            }
            else if (panel2?.Visible != true)
            {
                if (splitView.IsVertical)
                {
                    panel1Rect = new CGRect(0, 0, Math.Max(0, newFrame.Width - dividerThickness), newFrame.Height);
                    panel2Rect = new CGRect(newFrame.Width, 0, 0, newFrame.Height);
                }
                else
                {
                    panel1Rect = new CGRect(0, 0, newFrame.Width, Math.Max(0, newFrame.Height - dividerThickness));
                    panel2Rect = new CGRect(0, newFrame.Height, newFrame.Width, 0);
                }
            }
            else
            {
                nfloat totalSize;
                nfloat panel1Size;
                nfloat panel2Size;
                nfloat old;
                if (splitView.IsVertical)
                {
                    panel2Rect.Y      = 0;
                    panel2Rect.Height = panel1Rect.Height = newFrame.Height;
                    totalSize         = newFrame.Width;
                    old = oldSize.Width;
                }
                else
                {
                    panel2Rect.X     = 0;
                    panel2Rect.Width = panel1Rect.Width = newFrame.Width;
                    totalSize        = newFrame.Height;
                    old = oldSize.Height;
                }
                panel1Rect = new CGRect(CGPoint.Empty, panel1Rect.Size);

                if (position == null)
                {
                    panel1Size = (nfloat)Math.Max(0, totalSize / 2);
                    panel2Size = (nfloat)Math.Max(0, totalSize - panel1Size - dividerThickness);
                }
                else
                {
                    var pos = position.Value;
                    switch (fixedPanel)
                    {
                    case SplitterFixedPanel.Panel1:
                        panel1Size = (nfloat)Math.Max(0, Math.Min(totalSize - dividerThickness, pos));
                        panel2Size = (nfloat)Math.Max(0, totalSize - panel1Size - dividerThickness);
                        break;

                    case SplitterFixedPanel.Panel2:
                        panel2Size = (nfloat)Math.Max(0, Math.Min(totalSize - dividerThickness, old - pos - dividerThickness));
                        panel1Size = (nfloat)Math.Max(0, totalSize - panel2Size - dividerThickness);
                        break;

                    default:
                    case SplitterFixedPanel.None:
                        var oldscale = old > 0 ? totalSize / old : 1;
                        panel1Size = (nfloat)Math.Round(Math.Max(0, Math.Min(totalSize - dividerThickness, pos * oldscale)));
                        panel2Size = (nfloat)Math.Max(0, totalSize - panel1Size - dividerThickness);
                        break;
                    }
                }

                // ensure we don't shrink panels beyond minimum sizes
                if (panel2Size < Panel2MinimumSize)
                {
                    panel2Size = (nfloat)Math.Min(Panel2MinimumSize, totalSize);
                    panel1Size = (nfloat)Math.Max(0, totalSize - panel2Size - dividerThickness);
                }
                if (panel1Size < Panel1MinimumSize)
                {
                    panel1Size = (nfloat)Math.Min(Panel1MinimumSize, totalSize);
                    panel2Size = (nfloat)Math.Max(0, totalSize - panel1Size - dividerThickness);
                }

                if (splitView.IsVertical)
                {
                    panel2Rect.X     = (nfloat)Math.Min(panel1Size + dividerThickness, totalSize);
                    panel1Rect.Width = panel1Size;
                    panel2Rect.Width = panel2Size;
                }
                else
                {
                    panel2Rect.Y      = (nfloat)Math.Min(panel1Size + dividerThickness, totalSize);
                    panel1Rect.Height = panel1Size;
                    panel2Rect.Height = panel2Size;
                }
            }

            splitView.Subviews[0].Frame = panel1Rect;
            splitView.Subviews[1].Frame = panel2Rect;
            //Console.WriteLine($"Splitter resize: frame: {splitView.Frame.Size}, position: {position}, panel1({panel1?.Visible}): {panel1Rect}, panel2({panel2?.Visible}): {panel2Rect}");
        }
Ejemplo n.º 27
0
        public static UIImage MakeImageWithRoundedCorners(this UIImage image, nfloat cornerRadius, CGSize?size = null)
        {
            var newImageSize = size ?? image.Size;
            var circleRect   = new CGRect(CGPoint.Empty, newImageSize);

            UIGraphics.BeginImageContextWithOptions(circleRect.Size, false, 0);

            var circle = UIBezierPath.FromRoundedRect(circleRect, cornerRadius);

            circle.AddClip();

            image.Draw(circleRect);

            var roundedImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(roundedImage);
        }
Ejemplo n.º 28
0
 public static void MakeRect(this UIView view, CGSize?size = null)
 {
     view.MakeMask(UIBezierPath.FromRect, size);
 }
Ejemplo n.º 29
0
 public static void MakeRound(this UIView view, CGSize?size = null)
 {
     view.MakeMask(UIBezierPath.FromOval, size);
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Get size of the view before any transform is applied.
        /// </summary>
        protected static CGSize GetViewSize(_View view)
        {
            CGSize?appliedFrame = (view as IFrameworkElement)?.AppliedFrame.Size;

            return(appliedFrame ?? view.Frame.Size);
        }
Ejemplo n.º 31
0
        public static NSImageRep Resize(this NSImageRep image, CGSize newsize, ImageInterpolation interpolation = ImageInterpolation.Default, CGSize?imageSize = null)
        {
            var newrep = new NSBitmapImageRep(IntPtr.Zero, (nint)newsize.Width, (nint)newsize.Height, 8, 4, true, false, NSColorSpace.DeviceRGB, 4 * (nint)newsize.Width, 32);

            newrep.Size = imageSize ?? newsize;

            var graphics = NSGraphicsContext.FromBitmap(newrep);

            NSGraphicsContext.GlobalSaveGraphicsState();
            NSGraphicsContext.CurrentContext           = graphics;
            graphics.GraphicsPort.InterpolationQuality = interpolation.ToCG();
#if XAMMAC
            // Xamarin.Mac doesn't allow null for hints, remove this when it does.
            Messaging.bool_objc_msgSend_CGRect_CGRect_UIntPtr_nfloat_bool_IntPtr(image.Handle, selDrawInRect_FromRect_Operation_Fraction_RespectFlipped_Hints_Handle, new CGRect(CGPoint.Empty, newrep.Size), CGRect.Empty, (UIntPtr)(ulong)NSCompositingOperation.SourceOver, 1f, true, IntPtr.Zero);
#else
            image.DrawInRect(new CGRect(CGPoint.Empty, newrep.Size), CGRect.Empty, NSCompositingOperation.SourceOver, 1f, true, null);
#endif
            NSGraphicsContext.GlobalRestoreGraphicsState();
            return(newrep);
        }
Ejemplo n.º 32
0
        public static NSImage Resize(this NSImage image, CGSize newsize, ImageInterpolation interpolation = ImageInterpolation.Default, CGSize?imageSize = null)
        {
            var newimage = new NSImage(imageSize ?? newsize);
            var newrep   = new NSBitmapImageRep(IntPtr.Zero, (nint)newsize.Width, (nint)newsize.Height, 8, 4, true, false, NSColorSpace.DeviceRGB, 4 * (nint)newsize.Width, 32);

            newrep.Size = imageSize ?? newsize;
            newimage.AddRepresentation(newrep);

            var graphics = NSGraphicsContext.FromBitmap(newrep);

            NSGraphicsContext.GlobalSaveGraphicsState();
            NSGraphicsContext.CurrentContext           = graphics;
            graphics.GraphicsPort.InterpolationQuality = interpolation.ToCG();
            image.DrawInRect(new CGRect(CGPoint.Empty, newimage.Size), CGRect.Empty, NSCompositingOperation.SourceOver, 1f);
            NSGraphicsContext.GlobalRestoreGraphicsState();
            return(newimage);
        }
		// On load, construct the CIRawFilter
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			var asset = Asset;
			if (asset == null)
				return;

			// Setup options to request original image.
			var options = new PHImageRequestOptions {
				Version = PHImageRequestOptionsVersion.Original,
				Synchronous = true
			};

			// Request the image data and UTI type for the image.
			PHImageManager.DefaultManager.RequestImageData (asset, options, (imageData, dataUTI, _, __) => {
				if (imageData == null || dataUTI == null)
					return;

				// Create a CIRawFilter from original image data.
				// UTI type is passed in to provide the CIRawFilter with a hint about the UTI type of the Raw file.
				//var rawOptions = [String (kCGImageSourceTypeIdentifierHint) : dataUTI ]
				var rawOptions = new NSMutableDictionary ();
				var imageIOLibrary = Dlfcn.dlopen ("/System/Library/Frameworks/ImageIO.framework/ImageIO", 0);
				var key = Dlfcn.GetIntPtr (imageIOLibrary, "kCGImageSourceTypeIdentifierHint");
				rawOptions.LowlevelSetObject (dataUTI, key);

				ciRawFilter = CIFilter.CreateRawFilter (imageData, rawOptions);
				if (ciRawFilter == null)
					return;

				// Get the native size of the image produced by the CIRawFilter.
				var sizeValue = ciRawFilter.ValueForKey (Keys.kCIOutputNativeSizeKey) as CIVector;
				if (sizeValue != null)
					imageNativeSize = new CGSize (sizeValue.X, sizeValue.Y);

				// Record the original value of the temperature, and setup the editing slider.
				var tempValue = (NSNumber)ciRawFilter.ValueForKey (Keys.kCIInputNeutralTemperatureKey);
				if (tempValue != null) {
					originalTemp = tempValue.FloatValue;
					TempSlider.SetValue (tempValue.FloatValue, animated: false);
				}

				// Record the original value of the tint, and setup the editing slider.
				var tintValue = (NSNumber)ciRawFilter.ValueForKey (Keys.kCIInputNeutralTintKey);
				if (tintValue != null) {
					originalTint = tintValue.FloatValue;
					TintSlider.SetValue (tintValue.FloatValue, animated: false);
				}
			});

			// Create EAGL context used to render the CIImage produced by the CIRawFilter to display.
			ImageView.Context = new EAGLContext (EAGLRenderingAPI.OpenGLES3);
			ciContext = CIContext.FromContext (ImageView.Context, new CIContextOptions { CIImageFormat = CIImage.FormatRGBAh });
		}