Ejemplo n.º 1
0
        public SizeF Measure(AbstractLayout layout, SizeF available)
        {
            var index         = 0;
            var width         = 0f;
            var height        = 0f;
            var spacerCount   = 0;
            var lastWasSpacer = false;

            foreach (var view in layout)
            {
                var isSpacer = false;

                if (view is Spacer)
                {
                    spacerCount++;
                    isSpacer = true;

                    if (!view.MeasurementValid)
                    {
                        view.MeasuredSize     = new SizeF(-1, -1);
                        view.MeasurementValid = true;
                    }
                }
                else
                {
                    var size = view.MeasuredSize;
                    if (!view.MeasurementValid)
                    {
                        view.MeasuredSize = size = view.Measure(available);
                        Console.WriteLine($"{view.GetType().Name}: {size}");
                        view.MeasurementValid = true;
                    }

                    var finalHeight = size.Height;
                    var finalWidth  = size.Width;

                    var padding = view.Padding;
                    finalHeight += padding.VerticalThickness;
                    finalWidth  += padding.HorizontalThickness;

                    width   = Math.Max(finalWidth, width);
                    height += finalHeight;
                }

                if (index > 0 && !lastWasSpacer && !isSpacer)
                {
                    height += _spacing;
                }

                lastWasSpacer = isSpacer;
                index++;
            }

            if (spacerCount > 0)
            {
                height = available.Height;
            }

            return(new SizeF(width, height));
        }
Ejemplo n.º 2
0
 public void Layout(AbstractLayout layout, RectangleF rect)
 {
     foreach (var v in layout)
     {
         v.Frame = rect;
     }
 }
Ejemplo n.º 3
0
 private void ChangeLayout(AbstractLayout newLayout, AbstractHeatMap heatmap)
 {
     Layout  = newLayout;
     HeatMap = heatmap;
     Renderlayout();
     ResetCamera(null, null);
 }
        public void TableLayoutTest()
        {
            AbstractLayout l = LayoutFactory.CreateGenerator(GlobalEnums.ReportLayout.TableLayout,
                                                             ReportModel.Create(),
                                                             new ReportItemCollection());

            Assert.IsAssignableFrom <TableLayout>(l, "Should be 'TableLayout'");
        }
Ejemplo n.º 5
0
        public void Remove(View view)
        {
            _formsLayout.Children.Clear();

            if (view != null)
            {
                _view.ChildrenChanged -= HandleChildrenChanged;
                _view.ChildrenAdded   -= HandleChildrenAdded;
                _view.ChildrenRemoved -= ViewOnChildrenRemoved;
                _view = null;
            }
        }
Ejemplo n.º 6
0
        void UpdateLayoutView(ApplicationSettings settings)
        {
            var nextLayout = CreateLayout(settings.DisplayLayoutHorizontal);

            if (currentLayout != null)
            {
                Controls.Remove(currentLayout);
                currentLayout.Dispose();
                currentLayout = null;
            }
            Controls.Add(nextLayout);
            currentLayout = nextLayout;
        }
Ejemplo n.º 7
0
        public void SetView(View view)
        {
            _view = view as AbstractLayout;
            if (_view != null)
            {
                _view.ChildrenChanged += HandleChildrenChanged;
                _view.ChildrenAdded   += HandleChildrenAdded;
                _view.ChildrenRemoved += ViewOnChildrenRemoved;

                foreach (var subView in _view)
                {
                    var nativeView = subView.ToForms() ?? new Xamarin.Forms.ContentView();
                    _formsLayout.Children.Add(nativeView);
                }
            }
        }
Ejemplo n.º 8
0
        public SizeF Measure(AbstractLayout layout, SizeF available)
        {
            if (_constraints.Count == 0)
            {
                var maxRow    = 0;
                var maxColumn = 0;

                for (var index = 0; index < layout.Count; index++)
                {
                    var view       = layout[index];
                    var constraint = view.LayoutConstraints as GridConstraints ?? GridConstraints.Default;
                    _constraints.Add(constraint);

                    maxRow    = Math.Max(maxRow, constraint.Row + constraint.RowSpan - 1);
                    maxColumn = Math.Max(maxColumn, constraint.Column + constraint.ColumnSpan - 1);
                }

                while (maxRow >= _definedRows.Count)
                {
                    _definedRows.Add(DefaultRowHeight);
                }

                while (maxColumn >= _definedColumns.Count)
                {
                    _definedColumns.Add(DefaultColumnWidth);
                }
            }

            if (_gridX == null || !_lastSize.Equals(available))
            {
                ComputeGrid(available.Width, available.Height);
                _lastSize = available;
            }

            for (var index = 0; index < _constraints.Count; index++)
            {
                var view = layout[index];

                if (!view.MeasurementValid)
                {
                    view.MeasuredSize     = view.Measure(available);
                    view.MeasurementValid = true;
                }
            }

            return(new SizeF(_width, _height));
        }
Ejemplo n.º 9
0
        void ApplyConfig(ApplicationConfig config)
        {
            // nothing to do if correct layout already
            if (layout is HorizontalLayout && config.DisplayLayoutHorizontal)
            {
                return;
            }

            // remove old layout
            if (layout != null)
            {
                Controls.Remove(layout);
                layout.Dispose();
                layout = null;
            }

            // create new layout
            var nextLayout = config.DisplayLayoutHorizontal
                ? new HorizontalLayout(di) as AbstractLayout
                : new VerticalLayout(di);

            Controls.Add(nextLayout);
            layout = nextLayout;
        }
Ejemplo n.º 10
0
        public void Layout(AbstractLayout layout, SizeF measured)
        {
            var width = 0f;

            var index           = 0;
            var nonSpacerHeight = 0f;
            var spacerCount     = 0;
            var sizes           = new List <SizeF>();
            var lastWasSpacer   = false;

            foreach (var view in layout)
            {
                var isSpacer = false;

                if (view is Spacer)
                {
                    spacerCount++;
                    isSpacer = true;
                    sizes.Add(new SizeF());
                }
                else
                {
                    var size = view.MeasuredSize;

                    if (view.FrameConstraints?.Width != null)
                    {
                        size.Width = Math.Min((float)view.FrameConstraints.Width, measured.Width);
                    }

                    if (view.FrameConstraints?.Height != null)
                    {
                        size.Height = Math.Min((float)view.FrameConstraints.Height, measured.Height);
                    }

                    sizes.Add(size);
                    width            = Math.Max(size.Width, width);
                    nonSpacerHeight += size.Height + view.Padding.VerticalThickness;
                }

                if (index > 0 && !lastWasSpacer && !isSpacer)
                {
                    nonSpacerHeight += _spacing;
                }

                lastWasSpacer = isSpacer;
                index++;
            }

            nonSpacerHeight = Math.Min(nonSpacerHeight, measured.Height);

            var spacerHeight = 0f;

            if (spacerCount > 0)
            {
                var availableHeight = measured.Height - nonSpacerHeight;
                spacerHeight = availableHeight / spacerCount;
            }

            var x = 0f;
            var y = 0f;

            index = 0;
            foreach (var view in layout)
            {
                var isSpacer = false;

                SizeF size;
                if (view is Spacer)
                {
                    isSpacer = true;
                    size     = new SizeF(width, spacerHeight);
                }
                else
                {
                    size = sizes[index];
                }

                var alignment = view.FrameConstraints?.Alignment?.Horizontal ?? _defaultAlignment;
                var alignedX  = x;

                var padding = view.GetPadding();

                switch (alignment)
                {
                case HorizontalAlignment.Center:
                    alignedX += (measured.Width - size.Width - padding.Left + padding.Right) / 2;
                    break;

                case HorizontalAlignment.Trailing:
                    alignedX += measured.Width - size.Width - padding.Right;
                    break;

                case HorizontalAlignment.Leading:
                    alignedX = padding.Left;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (index > 0 && !lastWasSpacer && !isSpacer)
                {
                    y += _spacing;
                }

                y += padding.Top;

                view.Frame = new RectangleF(alignedX, y, size.Width, size.Height);

                y += size.Height;
                y += padding.Bottom;

                index++;
            }
        }
Ejemplo n.º 11
0
 public void Layout(AbstractLayout layout, SizeF measured)
 {
 }
Ejemplo n.º 12
0
        public SizeF Measure(AbstractLayout layout, SizeF available)
        {
            if (_constraints.Count == 0)
            {
                var maxRow    = 0;
                var maxColumn = 0;

                for (var index = 0; index < layout.Count; index++)
                {
                    var view       = layout[index];
                    var constraint = view.GetLayoutConstraints() as GridConstraints ?? GridConstraints.Default;
                    _constraints.Add(constraint);

                    maxRow    = Math.Max(maxRow, constraint.Row + constraint.RowSpan - 1);
                    maxColumn = Math.Max(maxColumn, constraint.Column + constraint.ColumnSpan - 1);
                }

                while (maxRow >= _definedRows.Count)
                {
                    _definedRows.Add(DefaultRowHeight);
                }

                while (maxColumn >= _definedColumns.Count)
                {
                    _definedColumns.Add(DefaultColumnWidth);
                }
            }

            if (_gridX == null || !_lastSize.Equals(available))
            {
                ComputeGrid(available.Width, available.Height);
                _lastSize = available;
            }

            for (var index = 0; index < _constraints.Count; index++)
            {
                var position = _constraints[index];
                var view     = layout[index];

                var x = _gridX[position.Column];
                var y = _gridY[position.Row];

                var w = 0f;
                for (var i = 0; i < position.ColumnSpan; i++)
                {
                    w += GetColumnWidth(position.Column + i);
                }

                var h = 0f;
                for (var i = 0; i < position.RowSpan; i++)
                {
                    h += GetRowHeight(position.Row + i);
                }

                if (position.WeightX < 1 || position.WeightY < 1)
                {
                    var viewSize = view.MeasuredSize;

                    if (!view.MeasurementValid)
                    {
                        viewSize = view.Measure(available);
                    }

                    var cellWidth  = w;
                    var cellHeight = h;

                    if (position.WeightX <= 0)
                    {
                        w = viewSize.Width;
                    }
                    else
                    {
                        w *= position.WeightX;
                    }

                    if (position.WeightY <= 0)
                    {
                        h = viewSize.Height;
                    }
                    else
                    {
                        h *= position.WeightY;
                    }

                    if (position.PositionX > 0)
                    {
                        var availWidth = cellWidth - w;
                        x += (float)Math.Round(availWidth * position.PositionX);
                    }

                    if (position.PositionY > 0)
                    {
                        var availHeight = cellHeight - h;
                        y += (float)Math.Round(availHeight * position.PositionY);
                    }

                    view.MeasuredSize     = new SizeF(w, h);
                    view.MeasurementValid = true;
                }

                view.Frame = new RectangleF(x, y, w, h);
            }

            return(new SizeF(_width, _height));
        }
Ejemplo n.º 13
0
        public void Layout(AbstractLayout layout, RectangleF bounds)
        {
            var measured = bounds.Size;
            var size     = bounds.Size;

            if (_gridX == null || !_lastSize.Equals(size))
            {
                ComputeGrid(size.Width, size.Height);
                _lastSize = size;
            }

            for (var index = 0; index < _constraints.Count; index++)
            {
                var position = _constraints[index];
                var view     = layout[index];

                var viewSize = view.MeasuredSize;
                if (!view.MeasurementValid)
                {
                    view.MeasuredSize     = viewSize = view.Measure(measured);
                    view.MeasurementValid = true;
                }

                var x = _gridX[position.Column];
                var y = _gridY[position.Row];

                var w = 0f;
                for (var i = 0; i < position.ColumnSpan; i++)
                {
                    w += GetColumnWidth(position.Column + i);
                }

                var h = 0f;
                for (var i = 0; i < position.RowSpan; i++)
                {
                    h += GetRowHeight(position.Row + i);
                }

                if (position.WeightX < 1 || position.WeightY < 1)
                {
                    var cellWidth  = w;
                    var cellHeight = h;

                    if (position.WeightX <= 0)
                    {
                        w = viewSize.Width;
                    }
                    else
                    {
                        w *= position.WeightX;
                    }

                    if (position.WeightY <= 0)
                    {
                        h = viewSize.Height;
                    }
                    else
                    {
                        h *= position.WeightY;
                    }

                    if (position.PositionX > 0)
                    {
                        var availWidth = cellWidth - w;
                        x += (float)Math.Round(availWidth * position.PositionX);
                    }

                    if (position.PositionY > 0)
                    {
                        var availHeight = cellHeight - h;
                        y += (float)Math.Round(availHeight * position.PositionY);
                    }
                }

                var padding = view.GetPadding();
                if (!padding.IsEmpty)
                {
                    x += padding.Left;
                    y += padding.Top;
                    w -= padding.HorizontalThickness;
                    h -= padding.VerticalThickness;
                }

                view.Frame = new RectangleF(x, y, w, h);
            }
        }
Ejemplo n.º 14
0
 public void Layout(AbstractLayout layout, RectangleF bounds)
 {
 }
Ejemplo n.º 15
0
        public SizeF Measure(AbstractLayout layout, SizeF available)
        {
            var index         = 0;
            var width         = 0f;
            var height        = 0f;
            var spacerCount   = 0;
            var lastWasSpacer = false;


            foreach (var view in layout)
            {
                var isSpacer = false;

                if (view is Spacer)
                {
                    spacerCount++;
                    isSpacer = true;

                    if (!view.MeasurementValid)
                    {
                        view.MeasuredSize     = new SizeF(-1, -1);
                        view.MeasurementValid = true;
                    }
                }
                else
                {
                    var size = view.MeasuredSize;
                    if (!view.MeasurementValid)
                    {
                        view.MeasuredSize     = size = view.Measure(available);
                        view.MeasurementValid = true;
                    }

                    var finalHeight = size.Height;
                    var finalWidth  = size.Width;

                    var padding = view.GetPadding();
                    finalHeight += padding.VerticalThickness;
                    finalWidth  += padding.HorizontalThickness;

                    var verticalSizing = view.GetVerticalSizing();
                    if (verticalSizing == Sizing.Fill)
                    {
                        height = available.Height;
                    }

                    height = Math.Max(finalHeight, height);
                    width += finalWidth;
                }

                if (index > 0 && !lastWasSpacer && !isSpacer)
                {
                    width += _spacing;
                }

                lastWasSpacer = isSpacer;
                index++;
            }

            if (spacerCount > 0)
            {
                width = available.Width;
            }

            var layoutPadding = layout.GetPadding();

            var layoutVerticalSizing = layout.GetVerticalSizing();

            if (layoutVerticalSizing == Sizing.Fill)
            {
                height = available.Height;
            }

            var layoutHorizontalSizing = layout.GetHorizontalSizing();

            if (layoutHorizontalSizing == Sizing.Fill)
            {
                width = available.Width - layoutPadding.HorizontalThickness;
            }

            return(new SizeF(width, height));
        }
Ejemplo n.º 16
0
 public SizeF Measure(AbstractLayout layout, SizeF available)
 {
     return(available);
 }
Ejemplo n.º 17
0
        public void Layout(AbstractLayout layout, SizeF measured)
        {
            var size = measured;

            if (_gridX == null || !_lastSize.Equals(size))
            {
                ComputeGrid(size.Width, size.Height);
                _lastSize = size;
            }

            for (var index = 0; index < _constraints.Count; index++)
            {
                var position = _constraints[index];
                var view     = layout[index];

                var x = _gridX[position.Column];
                var y = _gridY[position.Row];

                var w = 0f;
                for (var i = 0; i < position.ColumnSpan; i++)
                {
                    w += GetColumnWidth(position.Column + i);
                }

                var h = 0f;
                for (var i = 0; i < position.RowSpan; i++)
                {
                    h += GetRowHeight(position.Row + i);
                }

                if (position.WeightX < 1 || position.WeightY < 1)
                {
                    var viewSize   = view.MeasuredSize;
                    var cellWidth  = w;
                    var cellHeight = h;

                    if (position.WeightX <= 0)
                    {
                        w = viewSize.Width;
                    }
                    else
                    {
                        w *= position.WeightX;
                    }

                    if (position.WeightY <= 0)
                    {
                        h = viewSize.Height;
                    }
                    else
                    {
                        h *= position.WeightY;
                    }

                    if (position.PositionX > 0)
                    {
                        var availWidth = cellWidth - w;
                        x += (float)Math.Round(availWidth * position.PositionX);
                    }

                    if (position.PositionY > 0)
                    {
                        var availHeight = cellHeight - h;
                        y += (float)Math.Round(availHeight * position.PositionY);
                    }
                }

                view.Frame = new RectangleF(x, y, w, h);
            }
        }
Ejemplo n.º 18
0
        public void Layout(AbstractLayout layout, SizeF measured)
        {
            var height = 0f;

            var index          = 0;
            var nonSpacerWidth = 0f;
            var spacerCount    = 0;
            var sizes          = new List <SizeF>();
            var lastWasSpacer  = false;

            foreach (var view in layout)
            {
                var isSpacer = false;

                if (view is Spacer)
                {
                    spacerCount++;
                    isSpacer = true;
                    sizes.Add(new SizeF());
                }
                else
                {
                    var size = view.MeasuredSize;
                    sizes.Add(size);
                    height          = Math.Max(size.Height, height);
                    nonSpacerWidth += size.Width + view.Padding.HorizontalThickness;
                }

                if (index > 0 && !lastWasSpacer && !isSpacer)
                {
                    nonSpacerWidth += _spacing;
                }

                lastWasSpacer = isSpacer;
                index++;
            }

            nonSpacerWidth = Math.Min(nonSpacerWidth, measured.Width);

            var spacerWidth = 0f;

            if (spacerCount > 0)
            {
                var availableWidth = measured.Width - nonSpacerWidth;
                spacerWidth = availableWidth / spacerCount;
            }

            var x = 0f;
            var y = 0f;

            index = 0;
            foreach (var view in layout)
            {
                var isSpacer = false;

                SizeF size;
                if (view is Spacer)
                {
                    isSpacer = true;
                    size     = new SizeF(spacerWidth, height);
                }
                else
                {
                    size = sizes[index];
                }

                var alignment = view.FrameConstraints?.Alignment?.Vertical ?? _defaultAlignment;
                var alignedY  = y;

                var padding = view.GetPadding();

                switch (alignment)
                {
                case VerticalAlignment.Center:
                    alignedY += (measured.Height - size.Height - padding.Bottom + padding.Top) / 2;
                    break;

                case VerticalAlignment.Bottom:
                    alignedY += measured.Height - size.Height - padding.Bottom;
                    break;

                case VerticalAlignment.Top:
                    alignedY = padding.Top;
                    break;

                case VerticalAlignment.FirstTextBaseline:
                    throw new NotSupportedException(VerticalAlignment.FirstTextBaseline.ToString());

                case VerticalAlignment.LastTextBaseline:
                    throw new NotSupportedException(VerticalAlignment.LastTextBaseline.ToString());

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (index > 0 && !lastWasSpacer && !isSpacer)
                {
                    x += _spacing;
                }

                x += padding.Left;

                view.Frame = new RectangleF(x, alignedY, size.Width, size.Height);

                x += size.Width;
                x += padding.Right;

                lastWasSpacer = isSpacer;
                index++;
            }
        }
Ejemplo n.º 19
0
        public void Layout(AbstractLayout layout, RectangleF rect)
        {
            var measured = rect.Size;
            var height   = 0f;

            var index          = 0;
            var nonSpacerWidth = 0f;
            var spacerCount    = 0;
            var sizes          = new List <SizeF>();
            var lastWasSpacer  = false;

            foreach (var view in layout)
            {
                var isSpacer = false;

                if (view is Spacer)
                {
                    spacerCount++;
                    isSpacer = true;
                    sizes.Add(new SizeF());
                }
                else
                {
                    var size        = view.MeasuredSize;
                    var constraints = view.GetFrameConstraints();
                    var margin      = view.GetMargin();
                    var sizing      = view.GetVerticalSizing(layout);

                    // todo: this should never be needed.  Need to investigate this.
                    if (!view.MeasurementValid)
                    {
                        view.MeasuredSize     = size = view.Measure(measured);
                        view.MeasurementValid = true;
                    }

                    if (constraints?.Width != null)
                    {
                        size.Width = Math.Min((float)constraints.Width, measured.Width);
                    }

                    if (constraints?.Height != null)
                    {
                        size.Height = Math.Min((float)constraints.Height, measured.Height);
                    }

                    if (sizing == Sizing.Fill && constraints?.Height == null)
                    {
                        size.Height = measured.Height - margin.VerticalThickness;
                    }

                    sizes.Add(size);
                    height          = Math.Max(size.Height, height);
                    nonSpacerWidth += size.Width + margin.HorizontalThickness;
                }

                if (index > 0 && !lastWasSpacer && !isSpacer)
                {
                    nonSpacerWidth += _spacing;
                }

                lastWasSpacer = isSpacer;
                index++;
            }

            nonSpacerWidth = Math.Min(nonSpacerWidth, measured.Width);

            var spacerWidth = 0f;

            if (spacerCount > 0)
            {
                var availableWidth = measured.Width - nonSpacerWidth;
                spacerWidth = availableWidth / spacerCount;
            }

            var x = rect.X;
            var y = rect.Y;

            index = 0;
            foreach (var view in layout)
            {
                var isSpacer = false;

                SizeF size;
                if (view is Spacer)
                {
                    isSpacer = true;
                    size     = new SizeF(spacerWidth, height);
                }
                else
                {
                    size = sizes[index];
                }

                var constraints = view.GetFrameConstraints();
                var alignment   = constraints?.Alignment?.Vertical ?? _defaultAlignment;
                var alignedY    = y;

                var margin = view.GetMargin();

                switch (alignment)
                {
                case VerticalAlignment.Center:
                    alignedY += (measured.Height - size.Height - margin.Bottom + margin.Top) / 2;
                    break;

                case VerticalAlignment.Bottom:
                    alignedY += measured.Height - size.Height - margin.Bottom;
                    break;

                case VerticalAlignment.Top:
                    alignedY = margin.Top;
                    break;

                case VerticalAlignment.FirstTextBaseline:
                    throw new NotSupportedException(VerticalAlignment.FirstTextBaseline.ToString());

                case VerticalAlignment.LastTextBaseline:
                    throw new NotSupportedException(VerticalAlignment.LastTextBaseline.ToString());

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (index > 0 && !lastWasSpacer && !isSpacer)
                {
                    x += _spacing;
                }

                x += margin.Left;

                var sizing = view.GetVerticalSizing(layout);
                if (sizing == Sizing.Fill && constraints?.Height == null)
                {
                    alignedY    = margin.Top;
                    size.Height = measured.Height - margin.VerticalThickness;
                }

                view.Frame = new RectangleF(x, alignedY, size.Width, size.Height);

                x += size.Width;
                x += margin.Right;

                lastWasSpacer = isSpacer;
                index++;
            }
        }