Exemple #1
0
        public Size Measure(BoxConstraint constraint)
        {
            var lines = TextArray(constraint.GetMaxSize(), WrapContent, true);

            var max = lines.DefaultIfEmpty(string.Empty).Max(l => l.Length);

            return(constraint.Tighten(max, lines.Length).GetMinSize());
        }
Exemple #2
0
        public Size Measure(BoxConstraint constraint)
        {
            var size = constraint
                       .Constrain(Size);

            var childSize = Child.Measure(size);

            return(constraint
                   .Tighten(childSize)
                   .GetMinSize());
        }
Exemple #3
0
        public Size Draw(Point offset, BoxConstraint constraint, UIContext context)
        {
            var size = constraint
                       .Constrain(Size);

            var childSize = Child.Draw(offset, size, context);

            return(constraint
                   .Tighten(childSize)
                   .GetMinSize());
        }
Exemple #4
0
        public Size Measure(BoxConstraint constraint)
        {
            var scroll = GetConstraint(constraint);

            var min = Child.Measure(scroll);

            // fits whtaever the child returns into the constraint
            // so if the child doesn't use the full h/w, neither will this measure
            // but if it does, it will max at the constraint max.

            // offset isn't important here since if it's 'used' then this box already fills
            return(constraint.Tighten(min).GetMinSize());
        }
Exemple #5
0
        private Size GetUsedSize(BoxConstraint constraint, Size childSize)
        {
            // if alignment is 'set' then we use the minimum width or the child width, whichever is greater
            // (that's what we aligned to)
            var w = HorizontalAlignment != Alignment.Default
                ? Math.Max(constraint.MinWidth, childSize.Width)
                : childSize.Width;

            var h = VerticalAlignment != Alignment.Default
                ? Math.Max(constraint.MinHeight, childSize.Height)
                : childSize.Height;

            return(constraint.Tighten(w, h).GetMinSize());
        }
Exemple #6
0
        public Size Draw(Point offset, BoxConstraint constraint, UIContext context)
        {
            var lines = TextArray(constraint.GetMaxSize(), WrapContent, true);
            var max   = lines.DefaultIfEmpty(string.Empty).Max(l => l.Length);
            var size  = constraint.Tighten(max, lines.Length).GetMinSize();

            var bounds = new Rectangle(offset, size);

            for (var y = 0; y < lines.Length; y++)
            {
                var l = lines[y];
                for (var x = 0; x < l.Length; x++)
                {
                    context.Buffer.Modify(bounds, new Point(x, y), c =>
                    {
                        c.Char = l[x];
                        return(c);
                    });
                }
            }

            return(size);
        }
Exemple #7
0
 public Size Measure(BoxConstraint constraint)
 {
     return(constraint.Tighten(constraint.MaxWidth, 1).GetMinSize());
 }
Exemple #8
0
        public Size Draw(Point offset, BoxConstraint constraint, UIContext context)
        {
            var w    = constraint.IsBoundedWidth ? constraint.MaxWidth : constraint.MinWidth;
            var size = new Size(w, 1); // TODO yeuks

            // sanity check
            if (w < 1)
            {
                return(new Size(0, 0));
            }

            if (Input.CursorPosition < Input.StartVisiblePosition)
            {
                // cursor is behind start
                Input.StartVisiblePosition = Input.CursorPosition;
            }
            else if (Input.Text.Length + 1 <= w)
            {
                // everything fits, just remove 'visible' back to 0
                Input.StartVisiblePosition = 0;
            }
            else if (Input.CursorPosition - Input.StartVisiblePosition >= w)
            {
                // cursor is out of range ahoy!
                // move start pos to match cursor
                Input.StartVisiblePosition = Input.CursorPosition - w + 1;
            }
            else if (Input.Text.Length - Input.StartVisiblePosition + 1 < w)
            {
                // start pos is further right that it needs to be
                Input.StartVisiblePosition = Input.Text.Length - w + 1;
            }

            var bounds = new Rectangle(offset, size);

            if (Input.IsFocused)
            {
                // draw the cursor pos style if it has focus
                var z = new Point(Input.CursorPosition - Input.StartVisiblePosition, 0);
                if (CursorStyle != null)
                {
                    context.Buffer.Modify(bounds, z, CursorStyle.Apply);
                }
                else
                {
                    z.Offset(bounds.X, bounds.Y);
                    context.SetCursor(z, true);
                }
            }

            // cut the text as approp
            var output = Input.Text.Substring(Input.StartVisiblePosition);
            var l      = w > output.Length ? output.Length : w;

            for (var x = 0; x < l; x++)
            {
                context.Buffer.Modify(bounds, new Point(x, 0), c =>
                {
                    c.Char = output[x];
                    return(c);
                });
            }

            return(constraint.Tighten(size).GetMinSize());
        }