Exemple #1
0
            public override sd.Size GetPreferredSize(sd.Size proposedSize)
            {
                var bordersAndPadding = this.Margin.Size;                 // this.SizeFromClientSize (SD.Size.Empty);

                if (measuredSize == null)
                {
                    proposedSize       -= bordersAndPadding;
                    proposedSize.Height = Math.Max(0, proposedSize.Height);
                    if (proposedSize.Width <= 1)
                    {
                        proposedSize.Width = int.MaxValue;
                    }
                    measuredSize = graphics.MeasureString(this.Text, this.Font, proposedSize.Width, stringFormat);
                }
                var size = measuredSize.Value;

                size += bordersAndPadding;
                if (size.Width < MinimumSize.Width)
                {
                    size.Width = MinimumSize.Width;
                }
                if (size.Height < MinimumSize.Height)
                {
                    size.Height = MinimumSize.Height;
                }
                return(sd.Size.Ceiling(size));
            }
Exemple #2
0
            public override sd.Size GetPreferredSize(sd.Size proposedSize)
            {
                var bordersAndPadding = Padding.Size;

                if (proposedSize.Width <= 1)
                {
                    proposedSize.Width = int.MaxValue;
                }
                else if (IsHandleCreated && Width > 1)
                {
                    proposedSize.Width = Width;
                }

                sd.SizeF size;
                if (proposedSize.Width == int.MaxValue)
                {
                    if (measuredSizeMax == null && string.IsNullOrEmpty(Text))
                    {
                        var emptySize = swf.TextRenderer.MeasureText(" ", Font, new sd.Size(proposedSize.Width, int.MaxValue), textFormat);
                        measuredSizeMax = new sd.SizeF(0, emptySize.Height);
                    }
                    else if (measuredSizeMax == null)
                    {
                        proposedSize.Height = Math.Max(0, proposedSize.Height - bordersAndPadding.Height);
                        measuredSizeMax     = swf.TextRenderer.MeasureText(Text, Font, new sd.Size(proposedSize.Width, int.MaxValue), textFormat);
                    }
                    size = measuredSizeMax.Value;
                }
                else if (measuredSize == null || proposedSizeCache != proposedSize.Width)
                {
                    /*
                     * if (measuredSize != null)
                     *      Debug.WriteLine("Miss! {0} != {1}, {2}", proposedSizeCache, proposedSize.Width, Text);
                     * else
                     *      Debug.WriteLine(string.Format("Calc! {0}", Text));*/
                    proposedSizeCache   = proposedSize.Width;
                    proposedSize       -= bordersAndPadding;
                    proposedSize.Height = Math.Max(0, proposedSize.Height);
                    if (wrapMode == WrapMode.Character)
                    {
                        size = CalculatePositions(proposedSize, true);
                    }
                    else
                    {
                        size = swf.TextRenderer.MeasureText(Text, Font, new sd.Size(proposedSize.Width, int.MaxValue), textFormat);
                    }
                    measuredSize = size;
                }
                else
                {
                    size = measuredSize.Value;
                }

                size       += bordersAndPadding;
                size.Width  = Math.Max(MinimumSize.Width, size.Width);
                size.Height = Math.Max(MinimumSize.Height, size.Height);
                return(sd.Size.Ceiling(size));
            }
Exemple #3
0
            public override sd.Size GetPreferredSize(sd.Size proposedSize)
            {
                var bordersAndPadding = Margin.Size;                 // this.SizeFromClientSize (SD.Size.Empty);

                if (proposedSize.Width <= 1)
                {
                    proposedSize.Width = int.MaxValue;
                }

                if (proposedSize.Width == int.MaxValue)
                {
                    if (measuredSizeMax == null && string.IsNullOrEmpty(Text))
                    {
                        var emptySize = swf.TextRenderer.MeasureText(" ", Font, new sd.Size(proposedSize.Width, int.MaxValue), textFormat);
                        measuredSizeMax = new sd.SizeF(0, emptySize.Height);
                    }
                    else if (measuredSizeMax == null)
                    {
                        proposedSize       -= bordersAndPadding;
                        proposedSize.Height = Math.Max(0, proposedSize.Height);
                        measuredSizeMax     = swf.TextRenderer.MeasureText(Text, Font, new sd.Size(proposedSize.Width, int.MaxValue), textFormat);
                    }
                    measuredSize = measuredSizeMax;
                }
                else if (measuredSize == null || proposedSizeCache != proposedSize)
                {
                    proposedSizeCache   = proposedSize;
                    proposedSize       -= bordersAndPadding;
                    proposedSize.Height = Math.Max(0, proposedSize.Height);
                    measuredSize        = swf.TextRenderer.MeasureText(Text, Font, new sd.Size(proposedSize.Width, int.MaxValue), textFormat);
                }
                var size = measuredSize.Value;

                size += bordersAndPadding;
                if (size.Width < MinimumSize.Width)
                {
                    size.Width = MinimumSize.Width;
                }
                if (size.Height < MinimumSize.Height)
                {
                    size.Height = MinimumSize.Height;
                }
                return(sd.Size.Ceiling(size));
            }
Exemple #4
0
        protected virtual Size GetNaturalSize()
        {
            if (naturalSize != null)
            {
                return(naturalSize.Value);
            }
            var control = Control as NSControl;

            if (control != null)
            {
                SD.SizeF?size = (Widget.Loaded) ? (SD.SizeF?)control.Frame.Size : null;
                control.SizeToFit();
                naturalSize = Generator.ConvertF(control.Frame.Size);
                if (size != null)
                {
                    control.SetFrameSize(size.Value);
                }
                return(naturalSize.Value);
            }
            return(Size.Empty);
        }
Exemple #5
0
        protected virtual Size GetNaturalSize(Size availableSize)
        {
            if (naturalSize != null)
            {
                return(naturalSize.Value);
            }
            var control = Control as UIView;

            if (control != null)
            {
                SD.SizeF?size = (Widget.Loaded) ? (SD.SizeF?)control.Frame.Size : null;
                control.SizeToFit();
                naturalSize = control.Frame.Size.ToEtoSize();
                if (size != null)
                {
                    control.SetFrameSize(size.Value);
                }
                return(naturalSize.Value);
            }
            return(Size.Empty);
        }
Exemple #6
0
 public void ClearSize()
 {
     measuredSize = measuredSizeMax = null;
     positions    = null;
 }
Exemple #7
0
 void ClearSize()
 {
     measuredSize = measuredSizeMax = null;
 }