示例#1
0
        public override void PerformLayout(NanoVGDotNet.NVGcontext ctx, Widget widget)
        {
            int height         = this.margin;
            int width          = (int)((0 < widget.fixedSize.X) ? widget.fixedSize.X : widget.width);
            int availableWidth = width - 2 * this.margin;

            Window window = widget as Window;

            if (window && window.HasTitle())
            {
                height += (widget.theme.windowHeaderHeight - this.margin / 2);
            }

            bool first      = true;
            bool indent     = false;
            int  childCount = widget.childCount;

            for (int i = 0; childCount > i; ++i)
            {
                Widget child = widget.GetChild(i);
                if (!child.isVisible)
                {
                    continue;
                }

                Label label = child as Label;
                if (!first)
                {
                    height += (null == label) ? this.spacing : this.groupSpacing;
                }
                else
                {
                    first = false;
                }

                int currIndent = (indent && (null == label)) ? this.groupIndent : 0;

                Vector2 ps = child.GetPreferredSize(ctx);
                ps.X = availableWidth - currIndent;
                Vector2 targetSize = child.GetTargetSize(ctx, ps);

                Vector2 pos;
                pos.X = this.margin + currIndent;
                pos.Y = height;

                child.localPosition = pos;
                child.size          = targetSize;
                child.PerformLayout(ctx);

                height += (int)targetSize.Y;

                if (label)
                {
                    indent = label.HasCaption();
                }
            }
        }
示例#2
0
 public override void PerformLayout(NVGcontext ctx)
 {
     if (this.layout || 1 != this.childCount)
     {
         base.PerformLayout(ctx);
     }
     else
     {
         Widget child = GetChild(0);
         child.localPosition = Vector2.Zero;
         child.size          = this.size;
         child.PerformLayout(ctx);
     }
 }
示例#3
0
        public virtual void PerformLayout(NVGcontext ctx)
        {
            if (this.layout)
            {
                this.layout.PerformLayout(ctx, this);
                return;
            }

            int childCount = this.childCount;

            for (int i = 0; childCount > i; ++i)
            {
                Widget child = this.GetChild(i);
                child.ApplyTargetSize(ctx);
                child.PerformLayout(ctx);
            }
        }
示例#4
0
        public override void PerformLayout(NVGcontext ctx, Widget widget)
        {
            Vector2 fixedSize     = widget.fixedSize;
            Vector2 containerSize = fixedSize;

            if (0 >= containerSize.X)
            {
                containerSize.X = widget.width;
            }
            if (0 >= containerSize.Y)
            {
                containerSize.Y = widget.height;
            }
            int axis1    = (int)this.orientation;
            int axis2    = (int)(this.orientation + 1) % 2;
            int position = this.margin;
            int offsetY  = 0;

            Window window = widget as Window;

            if (window && !string.IsNullOrEmpty(window.title))
            {
                if (Orientation.Vertical == this.orientation)
                {
                    position += widget.theme.windowHeaderHeight;// - this.margin / 2; // why margin / 2?
                }
                else
                {
                    offsetY          = widget.theme.windowHeaderHeight;
                    containerSize.Y -= offsetY;
                }
            }

            //bool first = true;
            int childCount = widget.childCount;

            for (int i = 0; childCount > i; ++i)
            {
                Widget child = widget.GetChild(i);
                if (!child.isVisible)
                {
                    continue;
                }
                //if (first)
                //{
                //    first = false;
                //}
                //else
                //{
                //    position += this.spacing;
                //}

                Vector2 ps = child.GetPreferredSize(ctx);
                Vector2 fs = child.fixedSize;
                Vector2 targetSize;
                targetSize.X = 0 < fs.X ? fs.X : ps.X;
                targetSize.Y = 0 < fs.Y ? fs.Y : ps.Y;

                Vector2 pos;
                pos.X = 0f;
                pos.Y = offsetY;

                pos[axis1] = position;

                switch (this.alignment)
                {
                case Alignment.Min:
                {
                    pos[axis2] += this.margin;
                }
                break;

                case Alignment.Middle:
                {
                    pos[axis2] += (containerSize[axis2] - targetSize[axis2]) / 2;
                }
                break;

                case Alignment.Max:
                {
                    pos[axis2] += containerSize[axis2] - targetSize[axis2] - this.margin * 2;     // why margin * 2 (instead of margin * 1)?
                }
                break;

                case Alignment.Fill:
                {
                    pos[axis2]       += this.margin;
                    targetSize[axis2] = (0 < fs[axis2]) ? fs[axis2] : (containerSize[axis2] - this.margin * 2);
                }
                break;

                default:
                    break;
                }

                child.localPosition = pos;
                child.size          = targetSize;
                child.PerformLayout(ctx);
                position += ((int)targetSize[axis1] + this.spacing);
            }
        }