private LayoutViewResult LayoutView(PointF layoutOrigin, ref LayoutParams layoutParams) { var freeSpaceSize = new SizeF(Math.Max(0, _layoutSpaceBounds.Right - layoutOrigin.X), Math.Max(0, _layoutSpaceBounds.Bottom - layoutOrigin.Y)); //Free space available a view in layout coordinates var freeSpace = new RectangleF(layoutOrigin, freeSpaceSize); //Free space available for a view in view coordinates var viewFreeSpace = _layoutToView.Transform(freeSpace); //Area which view wants to occupy in view coordinates var viewBox = _layoutBuilder.View(layoutParams.View, viewFreeSpace); _views.Add(viewBox); layoutParams.Layout(viewBox); //Area which view wants to occupy in layout coordinates var layoutFrame = _viewToLayout.Transform(viewBox.Frame()); //Space required for view starting from layout origin in layout coordinates var viewFrame = new RectangleF(layoutOrigin, new SizeF(layoutFrame.Right - layoutOrigin.X, layoutFrame.Bottom - layoutOrigin.Y)); var newLayoutOrigin = new PointF(viewFrame.Right + LayoutStep, viewFrame.Top); return(new LayoutViewResult() { ViewLayoutBox = viewBox, NewLayoutOrigin = newLayoutOrigin, LayoutViewFrame = viewFrame }); }
private LayoutViewResult LayoutView(PointF layoutOrigin, ref LayoutParams layoutParams) { var freeSpaceSize = new SizeF(_layoutBounds.Right - layoutOrigin.X, _layoutBounds.Bottom - layoutOrigin.Y); //Free space available a view in layout coordinates var freeSpace = new RectangleF(layoutOrigin, freeSpaceSize); //Free space available for a view in view coordinates var viewFreeSpace = _layoutToView.Transform(freeSpace); //Postion which view wants to occupy in view coordinates var viewBox = layoutParams.LayoutView(viewFreeSpace); //Postion which view wants to occupy in layout coordinates var layoutFrame = _viewToLayout.Transform(viewBox.LayoutBounds); //Space required for view starting from layout origin in layout coordinates var viewFrame = new RectangleF(layoutOrigin, new SizeF(layoutFrame.Right - layoutOrigin.X, layoutFrame.Bottom - layoutOrigin.Y)); var newLayoutOrigin = new PointF(viewFrame.Right, viewFrame.Top); return(new LayoutViewResult() { ViewLayoutBox = viewBox, NewLayoutOrigin = newLayoutOrigin, LayoutViewFrame = viewFrame }); }
public IViewLayoutBox Add(LayoutParams layoutParams) { Assert.State(_layoutBuilder).NotNull("Layout is not started. Did you call StartLayout?"); var layoutResult = LayoutView(_layoutOrigin, ref layoutParams); var newLayoutOrigin = layoutResult.NewLayoutOrigin; if (Flow && newLayoutOrigin.X - LayoutStep > _layoutSpaceBounds.Right) { var nextLine = new PointF(_layoutSpaceBounds.X, _layoutOrigin.Y + _maxSize + FlowStep); layoutResult = LayoutView(nextLine, ref layoutParams); newLayoutOrigin = layoutResult.NewLayoutOrigin; if (newLayoutOrigin.X > _layoutSpaceBounds.Right) { newLayoutOrigin.X = _layoutSpaceBounds.X; newLayoutOrigin.Y = _layoutOrigin.Y + layoutResult.LayoutViewFrame.Height + FlowStep; } } _layoutBounds = RectangleF.Union(_layoutBounds, layoutResult.ViewLayoutBox.Frame()); _maxSize = Math.Max(_maxSize, layoutResult.LayoutViewFrame.Height); _layoutOrigin = newLayoutOrigin; return(layoutResult.ViewLayoutBox); }
public LinearLayoutBuilder Add(LayoutParams layoutParams) { Assert.State(_views).NotNull("Layout is not started. Did you call StartLayout?"); var layoutResult = LayoutView(_layoutOrigin, ref layoutParams); var newLayoutOrigin = layoutResult.NewLayoutOrigin; if (Flow && newLayoutOrigin.X > _layoutBounds.Right) { var nextLine = new PointF(_layoutBounds.X, _layoutOrigin.Y + _maxSize); layoutResult = LayoutView(nextLine, ref layoutParams); newLayoutOrigin = layoutResult.NewLayoutOrigin; if (newLayoutOrigin.X > _layoutBounds.Right) { newLayoutOrigin.X = _layoutBounds.X; newLayoutOrigin.Y = _layoutOrigin.Y + layoutResult.LayoutViewFrame.Height; } } _maxSize = Math.Max(_maxSize, layoutResult.LayoutViewFrame.Height); _layoutOrigin = newLayoutOrigin; _views.Add(layoutResult.ViewLayoutBox); return(this); }
protected virtual void CreateView() { Builder = new ViewHierarchyBuilder(Context); hierarchy = new ViewHierarchy(this, Builder); LayoutParameters = new LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent); }