Esempio n. 1
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;
        }
Esempio n. 2
0
        public Size Measure(Size constraints)
        {
            var s = CoreDll.MeasureString(Text, Font.ToFont(), constraints, false, true);

            return(new Size(constraints.Width, s.Height));
        }
Esempio n. 3
0
 protected override double GetLineHeight(Font font)
 {
     return(CoreDll.MeasureString("Wq", font.ToFont(), new Size(1000, 1000), false, true).Height);
 }
Esempio n. 4
0
        public Size Measure(Size constraints)
        {
            var measure = CoreDll.MeasureString(" " + _title + " ", Font.ToFont(), constraints, false, true) + _margins;

            return(new Size(measure.Width, Math.Max(measure.Height, 33 * CompactFactory.Instance.DpiScale)));
        }
Esempio n. 5
0
 public Size Measure(Size constraints)
 {
     return(CoreDll.MeasureString(Text, Font.ToFont(), constraints, Lines != 1, false));
 }