Beispiel #1
0
        public Range(IBound <T> lowerBound, IBound <T> upperBound)
        {
            Range <T> .AssertBounds(lowerBound, upperBound);

            this._lowerBound = lowerBound;
            this._upperBound = upperBound;
        }
Beispiel #2
0
        public virtual Range <T> Intersect(Range <T> range)
        {
            Range <T> empty = Range <T> .Empty;

            if (range != null && !object.ReferenceEquals(range, Range <T> .Empty))
            {
                if (this._lowerBound.Touches(range._upperBound))
                {
                    empty = Range.Degenerate <T>(this.LowerBound);
                }
                else if (this._upperBound.Touches(range._lowerBound))
                {
                    empty = Range.Degenerate <T>(this.UpperBound);
                }
                else if (this.LowerBound.IsLessThan <T>(range.UpperBound) && this.UpperBound.IsMoreThan <T>(range.LowerBound))
                {
                    IBound <T> bound = Range <T> .max(this._lowerBound, range._lowerBound, new Func <IBound <T>, IBound <T>, IBound <T> >(Range <T> .Restrictive.More));

                    IBound <T> bound1 = Range <T> .min(this._upperBound, range._upperBound, new Func <IBound <T>, IBound <T>, IBound <T> >(Range <T> .Restrictive.More));

                    empty = new Range <T>(bound, bound1);
                }
            }
            return(empty);
        }
Beispiel #3
0
 public static void AssertBounds(IBound <T> lowerBound, IBound <T> upperBound)
 {
     if (!Range <T> .CheckBounds(lowerBound, upperBound))
     {
         throw Range <T> .exception(lowerBound.Value, upperBound.Value);
     }
 }
Beispiel #4
0
        protected override IBound ReApply(IDictionary <Type, IStyle> styles, IBound styleBound, IBound maxBound)
        {
            IStyleHelper helper = StyleSheetContext.Current.CreateHelper(styles, CurrentStyleSheet, this);

            // background image
            _backgroundImage = FromSource() ?? helper.Get <IBackgroundImage>().GetImage();

            if (_backgroundImage != null)
            {
                _view.Image = _backgroundImage;

                // selected-color
                ISelectedColor selectedColor;
                if (helper.TryGet(out selectedColor))
                {
                    UIColor color = selectedColor.ToNullableColor();
                    if (color != null)
                    {
                        _selectedImage = GetFilteredImage(_backgroundImage, selectedColor.ToNullableColor());
                    }
                }
            }

            // size to content by background
            return(GetBoundByImage(styleBound, maxBound, _backgroundImage));
        }
        public IBound StrechBoundInProportion(IBound styleBound, IBound maxBound, float widthProportion, float heightProportion)
        {
            float proportion = widthProportion / heightProportion;
            float w = styleBound.Width;
            float h = styleBound.Height;

            // ReSharper disable CompareOfFloatsByEqualityOperator
            if (w == 0 && h != 0)
            {
                w = Convert.ToSingle(Math.Round(h * proportion));
                if (w > maxBound.Width)
                {
                    w = maxBound.Width;
                    h = Convert.ToSingle(Math.Round(w / proportion));
                }
            }
            else if (h == 0 && w != 0)
            {
                h = Convert.ToSingle(Math.Round(w / proportion));
                if (h > maxBound.Height)
                {
                    h = maxBound.Height;
                    w = Convert.ToSingle(Math.Round(h * proportion));
                }
            }
            else
                return styleBound;
            // ReSharper restore CompareOfFloatsByEqualityOperator

            return CreateBound(w, h, styleBound.ContentWidth, styleBound.Height);
        }
Beispiel #6
0
        private IBound SizeToContent(IBound styleBound, IBound maxBound, IStyleSheetHelper style)
        {
            IBound bound = GetBoundByBackgroud(styleBound, maxBound);

            bool sizeByWith   = style.SizeToContentWidth(this);
            bool sizeByHeight = style.SizeToContentHeight(this);

            if (sizeByWith || sizeByHeight)
            {
                float measureWidth  = sizeByWith ? maxBound.Width : styleBound.Width;
                float measureHeight = sizeByHeight ? maxBound.Height : styleBound.Height;

                // RedundantNameQualifier to fix compile error
                // ReSharper disable RedundantNameQualifier
                int wspec = Android.Views.View.MeasureSpec.MakeMeasureSpec(Java.Lang.Math.Round(measureWidth), MeasureSpecMode.AtMost);
                int hspec = Android.Views.View.MeasureSpec.MakeMeasureSpec(Java.Lang.Math.Round(measureHeight), MeasureSpecMode.AtMost);
                // ReSharper restore RedundantNameQualifier

                _view.Measure(wspec, hspec);
                float w = sizeByWith ? _view.MeasuredWidth : styleBound.Width;
                float h = sizeByHeight ? _view.MeasuredHeight : styleBound.Height;

                // choose max bound: from image resizing or from size to content by text
                bool safeProportion = !bound.Equals(styleBound) && sizeByWith && sizeByHeight;
                bound = StyleSheetContext.Current.MergeBound(bound, w, h, maxBound, safeProportion);
            }
            return(bound);
        }
Beispiel #7
0
        protected override IBound ReApply(IDictionary <Type, IStyle> styles, IBound styleBound, IBound maxBound)
        {
            IStyleHelper helper = StyleSheetContext.Current.CreateHelper(styles, CurrentStyleSheet, this);

            if (styles.Count > 0)
            {
                // background color, background image, borders
                _backgroundImage = helper.SetBackgroundSettings(this);
                if (_backgroundImage == null)
                {
                    _backgroundColor = _view.BackgroundColor;
                }
                else
                {
                    DrawBackgroundImage(_backgroundImage);
                }
                // selected-color
                _selectedColor = helper.Get <ISelectedColor>().ToNullableColor();
                if (_selectedColor != null && _backgroundImage != null)
                {
                    _selectedImage = GetFilteredImage(_backgroundImage, _selectedColor);
                }
            }
            // size to content by background
            IBound bound = GetBoundByImage(styleBound, maxBound, _backgroundImage);

            return(LayoutChildren(CurrentStyleSheet, bound, maxBound));
        }
Beispiel #8
0
        protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            IStyleSheetHelper style = stylesheet.Helper;

            // background color, background image, borders
            _backgroundImage = stylesheet.SetBackgroundSettings(this);
            if (_backgroundImage == null)
            {
                _backgroundColor = _view.BackgroundColor;
            }

            // selected-color
            _selectedColor = style.SelectedColor(this).ToNullableColor();
            if (_selectedColor != null && _backgroundImage != null)
            {
                _selectedImage = GetFilteredImage(_backgroundImage, _selectedColor);
            }

            // size to content by background
            IBound bound = GetBoundByImage(styleBound, maxBound, _backgroundImage);

            return(LayoutChildren(stylesheet, bound, maxBound));
        }
Beispiel #9
0
 protected static IBound GetBoundByImage(IBound styleBound, IBound maxBound, UIImage image)
 {
     return(image != null
         ? StyleSheetContext.Current.StrechBoundInProportion(styleBound, maxBound, image.Size.Width,
                                                             image.Size.Height)
         : styleBound);
 }
Beispiel #10
0
        protected override IBound ReApply(IDictionary <Type, IStyle> styles, IBound styleBound, IBound maxBound)
        {
            IStyleHelper helper = StyleSheetContext.Current.CreateHelper(styles, CurrentStyleSheet, this);

            if (styles.Count > 0)
            {
                // background color
                IBackgroundColor backgroundColor;
                if (helper.TryGet(out backgroundColor))
                {
                    _view.SetBackgroundColor(backgroundColor.ToColorOrTransparent());
                }
            }

            foreach (Control control in _containerBehaviour.Childrens)
            {
                if (control.View != null)
                {
                    ApplyChild(control, styleBound);
                }
            }

            _view.InvalidateViews();
            _view.Invalidate();

            return(styleBound);
        }
Beispiel #11
0
        public Range(T lowerBound, T upperBound)
        {
            AssertBounds(lowerBound, upperBound);

            _lowerBound = new Closed <T>(lowerBound);
            _upperBound = new Closed <T>(upperBound);
        }
Beispiel #12
0
        public Range(IBound <T> lowerBound, IBound <T> upperBound)
        {
            AssertBounds(lowerBound, upperBound);

            _lowerBound = lowerBound;
            _upperBound = upperBound;
        }
Beispiel #13
0
        protected override IBound ReApply(IDictionary <Type, IStyle> styles, IBound styleBound, IBound maxBound)
        {
            IStyleHelper helper = StyleSheetContext.Current.CreateHelper(styles, CurrentStyleSheet, this);

            if (styles.Count > 0)
            {
                // background color
                IBackgroundColor backgroundColor;
                if (helper.TryGet(out backgroundColor))
                {
                    _view.BackgroundColor = backgroundColor.ToColorOrClear();
                }
            }

            foreach (Control control in _containerBehaviour.Childrens)
            {
                if (control.View != null)
                {
                    ApplyChild(control, styleBound);
                }
            }

            Index = ScrollIndex;
            _view.ReloadData();

            return(styleBound);
        }
Beispiel #14
0
        public IBound StrechBoundInProportion(IBound styleBound, IBound maxBound, float widthProportion, float heightProportion)
        {
            float proportion = widthProportion / heightProportion;
            float w          = styleBound.Width;
            float h          = styleBound.Height;

            // ReSharper disable CompareOfFloatsByEqualityOperator
            if (w == 0 && h != 0)
            {
                w = Convert.ToSingle(Math.Round(h * proportion));
                if (w > maxBound.Width)
                {
                    w = maxBound.Width;
                    h = Convert.ToSingle(Math.Round(w / proportion));
                }
            }
            else if (h == 0 && w != 0)
            {
                h = Convert.ToSingle(Math.Round(w / proportion));
                if (h > maxBound.Height)
                {
                    h = maxBound.Height;
                    w = Convert.ToSingle(Math.Round(h * proportion));
                }
            }
            else
            {
                return(styleBound);
            }
            // ReSharper restore CompareOfFloatsByEqualityOperator

            return(CreateBound(w, h, styleBound.ContentWidth, styleBound.Height));
        }
Beispiel #15
0
        protected override IBound ReApply(IDictionary <Type, IStyle> styles, IBound styleBound, IBound maxBound)
        {
            IStyleHelper helper = StyleSheetContext.Current.CreateHelper(styles, CurrentStyleSheet, this);

            if (styles.Count > 0)
            {
                // background color, background image, borders
                Drawable background;
                if (helper.BackgroundChanged(CurrentStyleSheet, Frame.Bound, out background))
                {
                    using (background)
                        SetBackground(background);
                }

                // selected color
                ISelectedColor selectedColor;
                if (helper.TryGet(out selectedColor))
                {
                    _selectionBehaviour.SelectedColor = selectedColor.ToNullableColor();
                }
            }

            IBound bound = GetBoundByBackgroud(styleBound, maxBound);

            return(LayoutChildren(CurrentStyleSheet, bound, maxBound));
        }
Beispiel #16
0
 public BindU32(IBound bound, int delta, uint val)
 {
     this.obj   = bound;
     this.delta = delta;
     this.val   = val;
     this.old   = RamDisk.GetU32(obj.GetPos() + delta);
 }
Beispiel #17
0
        public Range(T lowerBound, T upperBound)
        {
            Range <T> .AssertBounds(lowerBound, upperBound);

            this._lowerBound = new Closed <T>(lowerBound);
            this._upperBound = new Closed <T>(upperBound);
        }
Beispiel #18
0
 public BindS16(IBound bound, int delta, short val)
 {
     this.obj   = bound;
     this.delta = delta;
     this.val   = val;
     this.old   = RamDisk.GetS16(obj.GetPos() + delta);
 }
Beispiel #19
0
 public BindS8(IBound bound, int delta, sbyte val)
 {
     this.obj   = bound;
     this.delta = delta;
     this.val   = val;
     this.old   = RamDisk.GetS8(obj.GetPos() + delta);
 }
Beispiel #20
0
 public BindString(IBound bound, int delta, int len, string val)
 {
     this.obj   = bound;
     this.delta = delta;
     this.len   = len;
     this.val   = val;
     this.old   = RamDisk.GetString(obj.GetPos() + delta, len);
 }
Beispiel #21
0
 public bool Touches(IBound <T> bound)
 {
     if (!bound.IsClosed)
     {
         return(false);
     }
     return(this.Value.IsEqualTo <T>(bound.Value));
 }
Beispiel #22
0
 public static bool Publish(IBound obj)
 {
     if (obj != null)
     {
         Publish(obj.GetUrl(), obj);
     }
     return(true);
 }
Beispiel #23
0
 public static bool Register(IBound obj)
 {
     if (obj != null)
     {
         Register(obj.GetUrl(), obj);
     }
     return(true);
 }
Beispiel #24
0
 public bool Equals(IBound <T> other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     return(other is Closed <T> closed && equals(closed));
 }
Beispiel #25
0
 public bool Equals(IBound <T> other)
 {
     if (!(other is Open <T>))
     {
         return(false);
     }
     return(EqualityComparer <T> .Default.Equals(this.Value, other.Value));
 }
Beispiel #26
0
 protected override IBound LayoutChildren(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
 {
     if (ContainerBehaviour.Childrens.Count == 1)
     {
         return(ControlsContext.Current.CreateLayoutBehaviour(stylesheet, this).Screen(ContainerBehaviour.Childrens[0], maxBound));
     }
     return(styleBound);
 }
Beispiel #27
0
 public bool Equals(IBound <T> other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     return(other is Open <T> open && equals(open));
 }
Beispiel #28
0
 public static bool Subscribe(IBound obj, ISubscriber sub)
 {
     if ((obj != null) && (sub != null))
     {
         Subscribe(obj.GetUrl(), sub);
     }
     return(true);
 }
Beispiel #29
0
 public static bool Unregister(IBound obj)
 {
     if (obj != null)
     {
         Unregister(obj.GetUrl());
     }
     return(true);
 }
Beispiel #30
0
        protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            // background color
            _view.BackgroundColor = stylesheet.Helper.BackgroundColor(this).ToColorOrClear();

            return(styleBound);
        }
Beispiel #31
0
        public Rectangle(float left, float top, IBound bound)
            : this()
        {
            Left = left;
            Top = top;
            Bound = bound;

            _valid = true;
        }
Beispiel #32
0
        public Rectangle(float left, float top, IBound bound)
            : this()
        {
            Left  = left;
            Top   = top;
            Bound = bound;

            _valid = true;
        }
 public static void ReloadBackgroundImage(this IStyleHelper helper, IStyleSheet styleSheet, IBound bound, Control control)
 {
     IBackgroundImage image;
     if (helper.TryGet(out image) && !string.IsNullOrWhiteSpace(image.Path))
     {
         var imageCache = styleSheet.GetCache<ImageCache>();
         using (BitmapDrawable background = imageCache.GetImage(image.Path, bound.Width, bound.Height))
             control.SetBackground(background);
     }
 }
        protected override IBound LayoutChildren(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
        {
            float[] borders;
            IBound bound = ControlsContext.Current.CreateLayoutBehaviour(stylesheet, this)
                .Vertical(ContainerBehaviour.Childrens, styleBound, maxBound, out borders, true);

            if (ContainerBehaviour.Childrens.Count > 0)
                Behavour.SetBorders(borders);

            Behavour.ScrollingArea = bound.Height;
            return bound;
        }
        public static Drawable Background(this IStyleSheet styleSheet, IStyledObject control, IBound bound, bool whithoutImage = false)
        {
            Drawable background = null;
            if (!whithoutImage)
            {
                string path = styleSheet.Helper.BackgroundImage(control);
                if (path != null)
                    background = styleSheet.GetCache<ImageCache>().GetImage(path, bound.Width, bound.Height);
            }

            return background ??
                ColorWithBorders(styleSheet, control, ToColorOrTransparent(styleSheet.Helper.BackgroundColor(control)));
        }
        protected override void SetupAlignOffset(IBound bound)
        {
            float top;
            float bottom;
            AlignOffset(out top, out bottom);
            _alignOffset = top;

            _view.ContentSize = new SizeF(bound.ContentWidth, bound.ContentHeight + top + bottom);

            foreach (Control control in ContainerBehaviour.Childrens)
            {
                IRectangle r = control.Frame;
                control.Frame = ControlsContext.Current.CreateRectangle(r.Left, r.Top + top, r.Width, r.Height);
            }
        }
        public static bool BackgroundChanged(this IStyleHelper helper
            , IStyleSheet styleSheet, IBound bound, out Drawable background, bool whithoutImage = false)
        {
            if (!whithoutImage)
            {
                IBackgroundImage image;
                if (helper.TryGet(out image) && !string.IsNullOrWhiteSpace(image.Path))
                {
                    background = styleSheet.GetCache<ImageCache>().GetImage(image.Path, bound.Width, bound.Height);
                    return true;
                }

                // if control has background image, we have to ignore background color
                if (!string.IsNullOrWhiteSpace(image.Path))
                {
                    background = null;
                    return false;
                }
            }

            IBackgroundColor backgroundColor;
            IBorderStyle borderStyle;
            IBorderWidth borderWidth;
            IBorderColor borderColor;
            IBorderRadius borderRadius;
            if (helper.TryGet(out backgroundColor) | helper.TryGet(out borderStyle) | helper.TryGet(out borderWidth)
                | helper.TryGet(out borderColor) | helper.TryGet(out borderRadius))
            {
                if (borderStyle.Style == BorderStyleValues.Solid)
                {
                    var shape = new GradientDrawable();
                    var width = (int)Math.Round(borderWidth.Value);
                    Color color = borderColor.ToColorOrTransparent();

                    shape.SetShape(ShapeType.Rectangle);
                    shape.SetColor(backgroundColor.ToColorOrTransparent());
                    shape.SetCornerRadius(borderRadius.Radius);
                    shape.SetStroke(width, color);
                    background = shape;
                }
                else
                    background = new ColorDrawable(backgroundColor.ToColorOrTransparent());
                return true;
            }

            background = null;
            return false;
        }
Beispiel #38
0
        public IBound MergeBound(IBound bound, float width, float height, IBound maxBound, bool safeProportion)
        {
            float w = Math.Max(width, bound.Width);
            float h = Math.Max(height, bound.Height);

            if (safeProportion)
            {
                float proportion = bound.Width / bound.Height;
                float newHeight = Convert.ToSingle(Math.Round(w / proportion));
                if (newHeight >= h)
                    h = newHeight;
                else
                    w = Convert.ToSingle(Math.Round(h * proportion));
            }

            return CreateBound(Math.Min(w, maxBound.Width), Math.Min(h, maxBound.Height));
        }
Beispiel #39
0
        protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
        {
            var bound = StyleSheetContext.Current.CreateBound(BitBrowserApp.Current.Width, BitBrowserApp.Current.Height);
            base.Apply(stylesheet, bound, bound);

            //background color
            _view.SetBackgroundColor(Android.Graphics.Color.White);

            if (OnLoad != null)
                OnLoad.Execute();

            Frame = ControlsContext.Current.CreateRectangle(0, 0, bound);

            return bound;
        }
Beispiel #40
0
 protected override IBound LayoutChildren(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
 {
     if (ContainerBehaviour.Childrens.Count == 1)
         return ControlsContext.Current.CreateLayoutBehaviour(stylesheet, this).Screen(ContainerBehaviour.Childrens[0], maxBound);
     return styleBound;
 }
Beispiel #41
0
        protected override IBound ReApply(IDictionary<Type, IStyle> styles, IBound styleBound, IBound maxBound)
        {
            var bound = StyleSheetContext.Current.CreateBound(BitBrowserApp.Current.Width, BitBrowserApp.Current.Height);
            base.ReApply(styles, bound, bound);

            IStyleHelper helper = StyleSheetContext.Current.CreateHelper(styles, CurrentStyleSheet, this);
            if (styles.Count > 0)
            {
                // background color
                IBackgroundColor backgroundColor;
                if (helper.TryGet(out backgroundColor))
                    _view.SetBackgroundColor(backgroundColor.ToColorOrTransparent());
            }

            return bound;
        }
Beispiel #42
0
 protected override IBound LayoutChildren(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
 {
     float[] borders;
     return ControlsContext.Current.CreateLayoutBehaviour(stylesheet, this)
         .Vertical(ContainerBehaviour.Childrens, styleBound, maxBound, out borders);
 }
Beispiel #43
0
 protected override IBound LayoutChildren(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
 {
     return ControlsContext.Current.CreateLayoutBehaviour(stylesheet, this)
         .Dock(ContainerBehaviour.Childrens, styleBound, maxBound);
 }
Beispiel #44
0
 public IBound Vertical(IEnumerable<ILayoutable> controls, IBound styleBound, IBound maxBound, out float[] borders, bool extensible = false)
 {
     return Queue(controls, styleBound, maxBound, out borders, false, extensible);
 }
Beispiel #45
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);
        }
Beispiel #46
0
        public IBound Screen(ILayoutable control, IBound screenBound)
        {
            IStyleSheetHelper style = _stylesheet.Helper;
            IStyleSheetContext context = StyleSheetContext.Current;

            float parentW = screenBound.Width;
            float parentH = screenBound.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 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 = parentW - (marginL + marginR) - (paddingL + paddingR) - 2 * borderWidth;
            if (parentW < paddingL + marginL + w + marginR + paddingR + 2 * borderWidth)
                w = maxW;

            float maxH = parentH - (marginT + marginB) - (paddingT + paddingB) - 2 * borderWidth;
            if (parentH < paddingT + marginT + h + marginB + paddingB + 2 * borderWidth)
                h = maxH;

            float l = borderWidth + paddingL + marginL;
            float t = borderWidth + paddingT + marginT;

            IBound bound = control.ApplyStyles(_stylesheet, context.CreateBound(w, h), context.CreateBound(maxW, maxH));
            w = bound.Width > maxW ? maxW : bound.Width;
            h = bound.Height > maxH ? maxH : bound.Height;

            control.Frame = new Rectangle(l, t, w, h);

            return screenBound;
        }
Beispiel #47
0
        public IBound Dock(IEnumerable<ILayoutable> controls, IBound styleBound, IBound maxBound)
        {
            IStyleSheetHelper style = _stylesheet.Helper;
            IStyleSheetContext context = StyleSheetContext.Current;

            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 = borderWidth + paddingL;
            float top = borderWidth + paddingT;
            float right = parentW - (paddingR + borderWidth);
            float bottom = parentH - (paddingB + borderWidth);

            float resizedWidth = parentW;
            float resizedHeight = parentH;

            float freeW = style.SizeToContentWidth(_container) ? maxBound.Width - parentW : 0;
            float freeH = style.SizeToContentHeight(_container) ? maxBound.Height - parentH : 0;

            IList<ILayoutable> controlsList = controls as IList<ILayoutable> ?? controls.ToList();
            var frames = new Rectangle[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(false, ref w, ref maxW, ref freeW, ref right);
                resizedHeight += SizeTo(false, ref h, ref maxH, ref freeH, ref bottom);

                IBound bound = control.ApplyStyles(_stylesheet, context.CreateBound(w, h)
                    , context.CreateBound(maxW + freeW, maxH + freeH));
                w = bound.Width;
                h = bound.Height;

                resizedWidth += SizeTo(false, ref w, ref maxW, ref freeW, ref right);
                resizedHeight += SizeTo(false, ref h, ref maxH, ref freeH, ref bottom);

                float x = left + marginL;
                float y = top + marginT;

                DockAlignValues align = style.DockAlign(control);
                switch (align)
                {
                    case DockAlignValues.Left:
                        left += marginL + w + marginR;
                        break;
                    case DockAlignValues.Top:
                        top += marginT + h + marginB;
                        break;
                    case DockAlignValues.Right:
                        x = right - (marginR + w);
                        right -= marginL + w + marginR;

                        // reverse reference system, for size to content
                        x = -(resizedWidth - x);

                        break;
                    case DockAlignValues.Bottom:
                        y = bottom - (marginB + h);
                        bottom -= marginT + h + marginB;

                        // reverse reference system, for size to content
                        y = -(resizedHeight - y);

                        break;
                    default:
                        throw new Exception("Unknown align: " + align);
                }

                frames[i] = new Rectangle(x, y, w, h);
            }

            // restore reference system
            for (int i = 0; i < controlsList.Count; i++)
            {
                Rectangle f = frames[i];
                float x = f.Left >= 0 ? f.Left : resizedWidth + f.Left;
                float y = f.Top >= 0 ? f.Top : resizedHeight + f.Top;
                controlsList[i].Frame = new Rectangle(x, y, f.Width, f.Height);
            }

            return context.CreateBound(resizedWidth, resizedHeight);
        }