Пример #1
0
        public static Rectangle CalculateBounds(Size containerSize, ILayoutPreferences control)
        {
            var preferredSize       = control.PreferredSize;
            var horizontalAlignment = control.Alignment.Horizontal;
            var verticalAlignment   = control.Alignment.Vertical;

            var clientWidth   = containerSize.Width;
            var clientHeight  = containerSize.Height;
            var controlWidth  = (control.Stretch & StretchOptions.Horizontal) != 0 ? clientWidth : preferredSize.Width;
            var controlHeight = (control.Stretch & StretchOptions.Vertical) != 0 ? clientHeight : preferredSize.Height;
            int x             = clientWidth - controlWidth;
            int y             = clientHeight - controlHeight;

            if (x < 0 || horizontalAlignment == HorizontalAlignment.Left)
            {
                x = 0;
            }
            else if (horizontalAlignment == HorizontalAlignment.Center)
            {
                x /= 2;
            }

            if (y < 0 || verticalAlignment == VerticalAlignment.Top)
            {
                y = 0;
            }
            else if (verticalAlignment == VerticalAlignment.Center)
            {
                y /= 2;
            }

            return(new Rectangle(x, y, Math.Min(clientWidth, controlWidth), Math.Min(clientHeight, controlHeight)));
        }
Пример #2
0
 protected ControlView()
 {
     _preferredSize     = Properties.Create <Size>(e => RequestSizeRecalculation());
     ActualBounds       = Properties.Create <Rectangle>();
     Alignment          = Properties.Create <Alignment>(e => RequestLayout());
     Stretch            = Properties.Create <StretchOptions>(e => RequestLayout());
     Expansion          = Properties.Create <ExpansionOptions>(e => RequestLayout());
     _layoutPreferences = new LayoutPreferences(PreferredSize, Alignment, Stretch, Expansion);
 }
Пример #3
0
 public LinearContainerView()
 {
     Items                     = new ObservableCollection <IControl>();
     Orientation               = Properties.Create <Orientation>(e => RecalculateSize());
     Spacing                   = Properties.Create <Spacing>(e => RecalculateSize());
     ContentAlignment          = Properties.Create <Alignment>(e => LayoutChildren());
     ContentStretch            = Properties.Create <StretchOptions>(e => LayoutChildren(), StretchOptions.Both);
     Stretch.Value             = StretchOptions.Both;
     Items.CollectionChanged  += OnCollectionChange;
     ActualBounds.Changed     += e => LayoutChildren();
     _contentLayoutPreferences = new LayoutPreferences(PreferredSize, ContentAlignment, ContentStretch, Properties.Create(ExpansionOptions.Fixed));
 }
Пример #4
0
 public WindowView()
 {
     _form                     = new Form();
     _form.Resize             += (o, e) => LayoutChildren();
     Alignment                 = Properties.Create <Alignment>();
     Content                   = Properties.Create <IControl>(OnContentChange);
     ContentAlignment          = Properties.Create <Alignment>(e => LayoutChildren());
     ContentStretch            = Properties.Create <StretchOptions>(e => LayoutChildren());
     Stretch                   = Properties.Create <StretchOptions>();
     Expansion                 = Properties.Create <ExpansionOptions>();
     _preferredSize            = Properties.Create <Size>();
     _contentLayoutPreferences = new LayoutPreferences(_preferredSize, ContentAlignment, ContentStretch, Properties.Create(ExpansionOptions.Fixed));
 }
Пример #5
0
        private static IEnumerable <Rectangle> CalculateVerticalBounds(Size containerSize, ILayoutPreferences contentLayoutPreferences, IReadOnlyCollection <ILayoutPreferences> controls, int spacing)
        {
            var bounds = ControlLayout.CalculateBounds(containerSize, contentLayoutPreferences);
            var expansionEnumerator = CalculateVerticalExpansions(bounds.Height, contentLayoutPreferences.PreferredSize.Height, controls).GetEnumerator();
            int totalHeight         = bounds.Y + bounds.Height;
            int y = bounds.Y;

            foreach (var control in controls)
            {
                expansionEnumerator.MoveNext();
                var controlAllocatedSize = new Size(bounds.Width, Math.Min(totalHeight - y, control.PreferredSize.Height) + expansionEnumerator.Current);
                var controlBounds        = ControlLayout.CalculateBounds(controlAllocatedSize, control);
                controlBounds.X += bounds.X;
                controlBounds.Y += y;
                y += controlAllocatedSize.Height + spacing;
                yield return(controlBounds);
            }
        }
Пример #6
0
 public static IEnumerable <Rectangle> CalculateBounds(Orientation orientation, Size containerSize, ILayoutPreferences contentLayoutPreferences, IReadOnlyCollection <ILayoutPreferences> controls, int spacing)
 {
     return((orientation == Orientation.Horizontal)
         ? CalculateHorizontalBounds(containerSize, contentLayoutPreferences, controls, spacing)
         : CalculateVerticalBounds(containerSize, contentLayoutPreferences, controls, spacing));
 }