Esempio n. 1
0
        public override void Layout()
        {
            const int padding            = 10;
            nfloat    availableHeight    = Frame.Height;
            nfloat    availableWidth     = Frame.Width - padding * 2;
            nfloat    imageWidth         = 0;
            nfloat    accessoryViewWidth = 0;

            if (ImageView != null)
            {
                nfloat imageHeight = imageWidth = availableHeight;
                ImageView.Frame = new CGRect(padding, 0, imageWidth, imageHeight);
            }

            if (AccessoryView != null)
            {
                accessoryViewWidth  = _style == NSTableViewCellStyle.Value1 ? 50 : availableWidth - 100;
                AccessoryView.Frame = new CGRect(availableWidth - accessoryViewWidth + padding, 0, accessoryViewWidth,
                                                 availableHeight);
                foreach (var subView in AccessoryView.Subviews)
                {
                    //try to find the size the control wants, if no width use default width
                    var size = subView.FittingSize;
                    if (size.Width == 0)
                    {
                        size.Width = accessoryViewWidth;
                    }

                    var x = AccessoryView.Bounds.Width - size.Width;
                    var y = (AccessoryView.Bounds.Height - size.Height) / 2;
                    subView.Frame = new CGRect(new CGPoint(x, y), size);
                }
            }

            nfloat labelHeights = availableHeight;
            nfloat labelWidth   = availableWidth - imageWidth - accessoryViewWidth;

            if (DetailTextLabel != null)
            {
                if (!string.IsNullOrEmpty(DetailTextLabel?.StringValue))
                {
                    labelHeights = availableHeight / 2;
                    DetailTextLabel.CenterTextVertically(new CGRect(imageWidth + padding, 0, labelWidth, labelHeights));
                }
            }

            TextLabel?.CenterTextVertically(new CGRect(imageWidth + padding, availableHeight - labelHeights, labelWidth,
                                                       labelHeights));

            var topNSView = Subviews.LastOrDefault();

            if (_contexActionsTrackingView != topNSView)
            {
                _contexActionsTrackingView.RemoveFromSuperview();
                _contexActionsTrackingView.Frame = Frame;
                AddSubview(_contexActionsTrackingView, NSWindowOrderingMode.Above, Subviews.LastOrDefault());
            }
            base.Layout();
        }