protected override MeasuredLayout calculateMeasuredLayout(Bounds perantBounds) { MeasuredLayout calculatedRootItem = base.calculateMeasuredLayout(perantBounds); calculatedRootItem.type = "CustomPlacementLayout"; calculatedRootItem.drawable = this; calculatedRootItem.reactiveView = this; Bounds resultBounds = calculatedRootItem.getBounds().clone(); double largestX = 0; double largestY = 0; foreach (ILayoutItem layoutItem in childLayoutItems) { MeasuredLayout nextChild = layoutItem.getMeasuredLayout(resultBounds); nextChild.reactiveView = (ReactiveView)layoutItem; double width = nextChild.getBounds().rect.Width; double height = nextChild.getBounds().rect.Height; if (width > largestX) { largestX = width; } if (height > largestY) { largestY = height; } calculatedRootItem.addCalculatedChild(nextChild); } if (sizeParams.Width == WRAP_CONTENTS) { calculatedRootItem.getBounds().rect.Width = largestX; foreach (MeasuredLayout layoutItem in calculatedRootItem.getCalculatedChildren()) { layoutItem.getBounds().rect.Location = new Point(layoutItem.getBounds().rect.Location.X + largestX / 2, layoutItem.getBounds().rect.Location.Y); } } if (sizeParams.Width == WRAP_CONTENTS) { calculatedRootItem.getBounds().rect.Height = largestY; foreach (MeasuredLayout layoutItem in calculatedRootItem.getCalculatedChildren()) { layoutItem.getBounds().rect.Location = new Point(layoutItem.getBounds().rect.Location.X, layoutItem.getBounds().rect.Location.Y + largestY / 2); } } return(calculatedRootItem); }
private void drawTree(MeasuredLayout item, DrawCanvas canvas) { foreach (MeasuredLayout child in item.getCalculatedChildren()) { DrawCanvas canvasClone = canvas.Clone(); canvasClone.setTopLeft(item.getBounds().rect.Left, item.getBounds().rect.Top); child.drawable.draw(canvasClone, child.getBounds().rect); drawTree(child, canvasClone); } }
private bool handleItem(MeasuredLayout item, MouseEvent motionEvent) { if (isPointInBounds(motionEvent.coordinates, item.getBounds().rect))// Give a chance to handle and alter the motion event before passing on to children { if (item.reactiveView != null && item.reactiveView != latchedView) { currentMouseOverViews.Add(item.reactiveView); if (item.reactiveView.handleMouseEvent != null) { MouseHandleResult motionResult = item.reactiveView.handleMouseEvent(motionEvent); if (motionResult.shouldLatch == true) { latchedView = item.reactiveView; } if (motionResult.shouldLatch == false) { if (latchedView == item.reactiveView) { latchedView = null; } } if (motionResult.handled == HandledStatus.HANDLED) { return(true); } } } } else { return(false); } MouseEvent motionEventClone = motionEvent.clone(); motionEventClone.coordinates.X -= item.getBounds().rect.Left; motionEventClone.coordinates.Y -= item.getBounds().rect.Top; foreach (MeasuredLayout childItem in item.getCalculatedChildren()) { bool thisHandledIt = handleItem(childItem, motionEventClone); if (thisHandledIt == true) { return(true); } } return(false); }
private void inverseBounds(MeasuredLayout item, bool xAxis, bool yAxis) { foreach (MeasuredLayout childItem in item.getCalculatedChildren()) { if (xAxis) { childItem.getBounds().rect.Offset(item.getBounds().rect.Width - childItem.getBounds().rect.Right - childItem.getBounds().rect.Left, 0); } if (yAxis) { childItem.getBounds().rect.Offset(0, item.getBounds().rect.Height - childItem.getBounds().rect.Top - childItem.getBounds().rect.Bottom); } } }
private bool handleLatchedLayout(MeasuredLayout item, MouseEvent motionEvent) { if (item.reactiveView == latchedView) { MouseHandleResult res = item.reactiveView.handleMouseEvent(motionEvent); return(res.handled == HandledStatus.HANDLED); } MouseEvent motionEventClone = motionEvent.clone(); motionEventClone.coordinates.X -= item.getBounds().rect.Left; motionEventClone.coordinates.Y -= item.getBounds().rect.Top; bool childHandledIt = false; foreach (MeasuredLayout childItem in item.getCalculatedChildren()) { if (handleLatchedLayout(childItem, motionEventClone)) { childHandledIt = true; } } return(childHandledIt); }