Example #1
0
 public virtual void SetBackground(string imagePath, ContentStretch stretch)
 {
     BackgroundHexCode = null;
     Backer            = new ImageControl {
         Size = Size.ToSize(), Stretch = stretch,
     };
     Backer.Loaded  += (o, ev) => Redraw();
     Backer.FilePath = imagePath;
 }
Example #2
0
        public void FitText()
        {
            if (!_hasMeasured)
            {
                return;
            }
            const string ellipsisChars = "... ";
            var          constraints   = Size.ToSize();
            Size         s             = CoreDll.MeasureString(" " + _title + " ", Font.ToFont(), constraints, false, true) + _margins;

            // control is large enough to display the whole text
            if (s.Width <= Width)
            {
                return;
            }

            int    len = 0;
            int    seg = _title.Length;
            string fit = string.Empty;

            // find the longest string that fits into the control boundaries using bisection method
            while (seg > 1)
            {
                seg -= seg / 2;

                int left  = len + seg;
                int right = _title.Length;

                if (left > right)
                {
                    continue;
                }

                // build and measure a candidate string with ellipsis
                string tst = " " + _title.Substring(0, left).TrimEnd() + ellipsisChars;

                s = CoreDll.MeasureString(tst, Font.ToFont(), constraints, false, true) + _margins;

                // candidate string fits into control boundaries,
                // try a longer string
                // stop when seg <= 1
                if (s.Width <= Width)
                {
                    len += seg;
                    fit  = tst;
                }
            }

            base.Text = len == 0 ? ellipsisChars : fit;
        }
Example #3
0
        protected override void OnResize(EventArgs e)
        {
            var t = CompactFactory.MetricStopwatch.ElapsedTicks;

            if (Parent == null || Width == _width)
            {
                return;
            }
            var minSize = new Size(MinWidth, MinHeight);
            var maxSize = new Size(MaxWidth, MaxHeight);
            var size    = this.PerformLayout(minSize, maxSize);

            if (Backer != null && Backer.Size != size)
            {
                Backer.Size = size;
                if (CellBitmap != null)
                {
                    var bit = CellBitmap;
                    Bitmaps.Remove(this);
                    bit.Dispose();
                    mem -= Width * Height * 4;
                }
            }

            if (size.ToSize() == Size)
            {
                Debug.WriteLine(string.Format("Unnecessary resize at {0}", size));
                return;
            }
            Debug.WriteLine(string.Format("Resize {0} -> {1}", Size.ToSize(), size));

            if (Size.Height != (int)size.Height)
            {
                Size = size.ToSize();
                if (Parent != null && Parent.Parent is SmoothListbox)
                {
                    ((SmoothListbox)Parent.Parent).LayoutItems(this);
                }
            }
            else
            {
                Size = size.ToSize();
            }

            _width = Size.Width;

            Debug.WriteLineIf(CompactFactory.MetricStopwatch.IsRunning, string.Format("[{1}] Grid resize took {0}ms", new TimeSpan(CompactFactory.MetricStopwatch.ElapsedTicks - t).TotalMilliseconds, CompactFactory.MetricStopwatch.ElapsedMilliseconds));
        }