Exemplo n.º 1
0
        public override void FromString(string s)
        {
            HorizontalAlignValues result;

            if (!Enum.TryParse(s, true, out result))
            {
                throw new Exception("Invalid horizontal-align value");
            }

            Align = result;
        }
Exemplo n.º 2
0
        private IBound Queue(IEnumerable <ILayoutable> controls, IBound styleBound, IBound maxBound, out float[] borders, bool horizontal, bool extensible)
        {
            if (styleBound.Width > maxBound.Width || styleBound.Height > maxBound.Height)
            {
                throw new ArgumentException("maxBoud lesser than styleBound");
            }

            IStyleSheetHelper  style   = _stylesheet.Helper;
            IStyleSheetContext context = StyleSheetContext.Current;
            var bordersList            = new List <float>();

            float parentW     = styleBound.Width;
            float parentH     = styleBound.Height;
            float paddingL    = style.PaddingLeft(_container, parentW);
            float paddingT    = style.PaddingTop(_container, parentH);
            float paddingR    = style.PaddingRight(_container, parentW);
            float paddingB    = style.PaddingBottom(_container, parentH);
            float borderWidth = style.BorderWidth(_container);

            float left   = paddingL + borderWidth;
            float top    = paddingT + borderWidth;
            float right  = parentW - (borderWidth + paddingR);
            float bottom = parentH - (borderWidth + paddingB);

            float resizedWidth  = parentW;
            float resizedHeight = parentH;

            bool sizeToContentWidth  = style.SizeToContentWidth(_container);
            bool sizeToContentHeight = style.SizeToContentHeight(_container);

            float freeW = sizeToContentWidth ? maxBound.Width - parentW : 0;
            float freeH = sizeToContentHeight ? maxBound.Height - parentH : 0;

            bordersList.Add(horizontal ? left : top);

            IList <ILayoutable> controlsList = controls as IList <ILayoutable> ?? controls.ToList();
            var dirtyFrames = new LayoutParams[controlsList.Count];

            for (int i = 0; i < controlsList.Count; i++)
            {
                ILayoutable control = controlsList[i];
                float       w       = style.Width(control, parentW);
                float       h       = style.Height(control, parentH);

                float marginL = style.MarginLeft(control, parentW);
                float marginT = style.MarginTop(control, parentH);
                float marginR = style.MarginRight(control, parentW);
                float marginB = style.MarginBottom(control, parentH);

                float maxW = right - left - (marginL + marginR);
                float maxH = bottom - top - (marginT + marginB);

                resizedWidth  += SizeTo(horizontal && extensible, ref w, ref maxW, ref freeW, ref right);
                resizedHeight += SizeTo(!horizontal && extensible, ref h, ref maxH, ref freeH, ref bottom);

                float  childMaxW = horizontal && extensible ? float.MaxValue : maxW + freeW;
                float  childMaxH = !horizontal && extensible ? float.MaxValue : maxH + freeH;
                IBound bound     = control.ApplyStyles(_stylesheet, context.CreateBound(w, h), context.CreateBound(childMaxW, childMaxH));
                w = bound.Width;
                h = bound.Height;

                resizedWidth  += SizeTo(horizontal && extensible, ref w, ref maxW, ref freeW, ref right);
                resizedHeight += SizeTo(!horizontal && extensible, ref h, ref maxH, ref freeH, ref bottom);

                dirtyFrames[i] = new LayoutParams(left, top, w, h, marginL, marginT, marginR, marginB); // new Rectangle(left + leftOffset, top + topOffset, w, h);

                if (horizontal)
                {
                    left += marginL + w + marginR;
                }
                else
                {
                    top += marginT + h + marginB;
                }

                bordersList.Add(horizontal ? left : top);
            }

            borders = bordersList.ToArray();

            for (int i = 0; i < controlsList.Count; i++)
            {
                ILayoutable  control      = controlsList[i];
                LayoutParams layoutParams = dirtyFrames[i];

                float topOffset  = layoutParams.MarginTop;
                float leftOffset = layoutParams.MarginLeft;
                if (horizontal)
                {
                    float maxH = bottom - top - (layoutParams.MarginTop + layoutParams.MarginBottom);
                    if (layoutParams.Height < maxH)
                    {
                        VerticalAlignValues align = style.VerticalAlign(control);
                        switch (align)
                        {
                        case VerticalAlignValues.Top:
                            break;

                        case VerticalAlignValues.Center:
                        case VerticalAlignValues.Central:
                            topOffset += (maxH - layoutParams.Height) / 2;
                            break;

                        case VerticalAlignValues.Bottom:
                            topOffset = (bottom - layoutParams.MarginBottom - layoutParams.Height) - top;
                            break;
                        }
                    }
                }
                else
                {
                    float maxW = right - left - (layoutParams.MarginLeft + layoutParams.MarginRight);
                    if (layoutParams.Width < maxW)
                    {
                        HorizontalAlignValues align = style.HorizontalAlign(control);
                        switch (align)
                        {
                        case HorizontalAlignValues.Left:
                            break;

                        case HorizontalAlignValues.Center:
                        case HorizontalAlignValues.Central:
                            leftOffset += (maxW - layoutParams.Width) / 2;
                            break;

                        case HorizontalAlignValues.Right:
                            leftOffset = (right - layoutParams.MarginRight - layoutParams.Width) - left;
                            break;
                        }
                    }
                }

                control.Frame = new Rectangle(layoutParams.Left + leftOffset, layoutParams.Top + topOffset
                                              , layoutParams.Width, layoutParams.Height);
            }

            float contentW = horizontal ? left + paddingR + borderWidth : resizedWidth;
            float contentH = !horizontal ? top + paddingB + borderWidth : resizedHeight;

            return(context.CreateBound(resizedWidth, resizedHeight, contentW, contentH));
        }