/* this function returns the largest dimensions of the children whose dimensions are not dependant on its perant */ private Point getMaxFixedChildDimensions(Bounds perantDimensions) { double largestX = 0; double largestY = 0; foreach (ILayoutItem layoutItem in childLayoutItems) { MeasuredLayout nextChild = layoutItem.getMeasuredLayout(perantDimensions); if (!isHeightDependantOnParent(((BaseLayout)layoutItem).sizeParams))//if the height is dependant on the perants height, we dont know it yet as its calculated here { if (nextChild.getBounds().rect.Height > largestY) { largestY = nextChild.getBounds().rect.Height; } } if (!isWidthDependantOnParent(((BaseLayout)layoutItem).sizeParams)) //if the width is dependant on the perants width, we dont know it yet as its calculated here { if (nextChild.getBounds().rect.Width > largestX) { largestX = nextChild.getBounds().rect.Width; } } } return(new Point(largestX, largestY)); }
public void drawTree(MeasuredLayout item) { canvas.clear(); canvas.resetTopLeft(); ((IDrawable)item).draw(canvas, item.getBounds().rect); drawTree(item, canvas); }
protected override MeasuredLayout calculateMeasuredLayout(Bounds perantBounds) { MeasuredLayout calculatedItem = base.calculateMeasuredLayout(perantBounds); calculatedItem.drawable = this; calculatedItem.reactiveView = this; return(calculatedItem); }
protected virtual MeasuredLayout calculateMeasuredLayout(Bounds perantRect) { MeasuredLayout calculatedRootItem = new MeasuredLayout(); calculatedRootItem.drawable = this; calculatedRootItem.reactiveView = this; calculatedRootItem.type = "base measure"; calculatedRootItem.setBounds(calculateBounds(perantRect.rect, new Rect())); return(calculatedRootItem); }
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); } }
public void handleMouseEvent(MeasuredLayout calculatedTree, MouseEvent motionEvent) { currentMouseOverViews = new List <ReactiveView>(); bool latchedLayoutHandledTheEvent = handleLatchedLayout(calculatedTree, motionEvent); // let the latched layout have first try //if (!latchedLayoutHandledTheEvent) handleItem(calculatedTree, motionEvent); notifyMouseOverListenterItems(); previousMouseOverViews = currentMouseOverViews; }
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 MeasuredLayout GetLayout(BoxConstraint constraint) { var layout = new MeasuredLayout(); layout.Elements = Children.Select(c => new LayoutElement() { Child = (c is FlexibleElement) ? (FlexibleElement)c : new FlexibleElement(c), }).ToList(); MeasureItems(layout.Elements, MainAxis, constraint); LayoutLine(layout, ItemSpacing, MainAxis, constraint); return(layout); }
protected override MeasuredLayout calculateMeasuredLayout(Bounds perantBounds) { MeasuredLayout calculatedItem = new MeasuredLayout(); calculatedItem.drawable = this; calculatedItem.reactiveView = this; textMeasurer.setTextSize(textSize); Rect textDimensions = textMeasurer.measureText(text); calculatedItem.setBounds(calculateBounds(perantBounds.rect, new Rect(new Size(textDimensions.Width, textDimensions.Height)))); return(calculatedItem); }
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); } } }
protected override MeasuredLayout calculateMeasuredLayout(Bounds perantBounds) { MeasuredLayout calculatedRootItem = new MeasuredLayout(); calculatedRootItem.type = "Fragment"; calculatedRootItem.drawable = this; calculatedRootItem.reactiveView = this; calculatedRootItem.setBounds(perantBounds.clone()); double largestX = 0; double largestY = 0; foreach (ILayoutItem layoutItem in childLayoutItems) { MeasuredLayout nextChild = layoutItem.getMeasuredLayout(perantBounds.clone()); nextChild.reactiveView = (ReactiveView)layoutItem; nextChild.getBounds().rect.Location = new Point(0, 0); 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; } if (sizeParams.Width == WRAP_CONTENTS) { calculatedRootItem.getBounds().rect.Height = largestY; } return(calculatedRootItem); }
protected override MeasuredLayout calculateMeasuredLayout(Bounds perantBounds) { MeasuredLayout calculatedItem = base.calculateMeasuredLayout(perantBounds); calculatedItem.type = "ScrollLayout"; calculatedItem.drawable = this; calculatedItem.reactiveView = this; if (childLayoutItems.Count > 0) { MeasuredLayout child = childLayoutItems[0].getMeasuredLayout(perantBounds); Bounds childBounds = child.getBounds(); childBounds.rect.Offset(new Vector(offset.X, offset.Y)); calculatedItem.addCalculatedChild(child); } return(calculatedItem); }
public MeasuredLayout getMeasuredLayout(Bounds perantRect) { if (perantRect.rect.Width == 0 || perantRect.rect.Height == 0 || perantRect.rect.IsEmpty) { MeasuredLayout calculatedRootItem = new MeasuredLayout(); calculatedRootItem.drawable = this; calculatedRootItem.reactiveView = this; calculatedRootItem.type = "Empty layout beacause the perant had no dimensions"; calculatedRootItem.setBounds(new Bounds() { rect = new Rect(perantRect.rect.Location, new Size(0, 0)) }); // dont try calculating the child if no size return(calculatedRootItem); } else { return(calculateMeasuredLayout(perantRect)); } }
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); }
protected override MeasuredLayout calculateMeasuredLayout(Bounds perantBounds) { MeasuredLayout calculatedItem; if (contents == null) { calculatedItem = base.calculateMeasuredLayout(perantBounds); calculatedItem.type = "ColoredLayout"; calculatedItem.drawable = this; calculatedItem.reactiveView = this; } else { calculatedItem = new MeasuredLayout(); calculatedItem.drawable = this; calculatedItem.reactiveView = this; contentsMeasuredLayout = contents.getMeasuredLayout(perantBounds); Rect contentRect = contentsMeasuredLayout.getBounds().rect; contentRect.Width += 2 * contentPaddingHorizontal; contentRect.Height += 2 * contentPaddingVertical; calculatedItem.setBounds(calculateBounds(perantBounds.rect, contentRect)); } return(calculatedItem); }
public void run() { LayoutFramework.CanvasItemFactory.setFactory(new BasicWindow.CanvasItemFactory()); canvas = new CanvasCreator().createCanvas(width, height, "{DIFF}"); layoutRenderer = new LayoutRenderer(canvas); rootLayout = new LayoutLoader().loadLayout(); canvas.subscribeToKeyPress((LayoutFramework.Keys.Key keyPressed) => { lock (lockObj) { KeyboardEvent keyEvent = new KeyboardEvent(); keyEvent.keyPressed = keyPressed; Keyboard.notifyKeyPressed(keyPressed); if (calculatedTree != null) { reactiveLayout.handleKeyboardInput(keyEvent); } } }); canvas.subscribeToKeyRelease((LayoutFramework.Keys.Key keyPressed) => { lock (lockObj) { Keyboard.notifyKeyUp(keyPressed); } }); canvas.subscribeToMouseClicks((int x, int y) => { lock (lockObj) { MouseEvent motionEvent = new MouseEvent(); motionEvent.eventType = MotionType.DOWN; motionEvent.coordinates = new Point(x, y); if (calculatedTree != null) { reactiveLayout.handleMouseEvent(calculatedTree, motionEvent); } } }); canvas.subscribeToMouseUp((int x, int y) => { lock (this) { MouseEvent motionEvent = new MouseEvent(); motionEvent.eventType = MotionType.UP; motionEvent.coordinates = new Point(x, y); if (calculatedTree != null) { reactiveLayout.handleMouseEvent(calculatedTree, motionEvent); } } }); canvas.subscribeToMouseMove((int x, int y) => { lock (this) { MouseEvent motionEvent = new MouseEvent(); motionEvent.eventType = MotionType.MOVE; motionEvent.coordinates = new Point(x, y); if (calculatedTree != null) { reactiveLayout.handleMouseEvent(calculatedTree, motionEvent); } } }); canvas.subscribeToFrameUpdates(() => { lock (this) { TaskRunner.RunTasks(); MeasuredLayout result = rootLayout.getMeasuredLayout(getWindowBounds()); layoutRenderer.drawTree(result); calculatedTree = result; } }); canvas.Run(); }
protected override MeasuredLayout calculateMeasuredLayout(Bounds perantBounds) { Bounds resultBounds = perantBounds.clone(); MeasuredLayout calculatedRootItem = new MeasuredLayout(); calculatedRootItem.type = "StackLayout"; calculatedRootItem.drawable = this; calculatedRootItem.reactiveView = this; Bounds itemBounds = calculateBounds(resultBounds.rect, new Rect()); if (sizeParams.Width == WRAP_CONTENTS) // This gives the child a chance to match to this items perants dimension if this item is wrapping { itemBounds.rect.Width = perantBounds.rect.Width; } if (sizeParams.Height == WRAP_CONTENTS) { itemBounds.rect.Height = perantBounds.rect.Height; } calculatedRootItem.setBounds(itemBounds); Point maxChildDimensions = getMaxFixedChildDimensions(calculatedRootItem.getBounds()); double largestX = maxChildDimensions.X; double largestY = maxChildDimensions.Y; double yOffset = 0; double xOffset = 0; foreach (ILayoutItem layoutItem in childLayoutItems) { Bounds boundsOffsetFromStart = calculatedRootItem.getBounds().clone(); if (!vertical_orientation && sizeParams.Height == WRAP_CONTENTS) { boundsOffsetFromStart.rect.Height = largestY; } if (vertical_orientation && sizeParams.Width == WRAP_CONTENTS) { boundsOffsetFromStart.rect.Width = largestX; } // The new bounds for each child must take into account the space that has allready been used UNLESS ... if (vertical_orientation) { boundsOffsetFromStart.rect = new Rect(new Point(0, yOffset), new Size(boundsOffsetFromStart.rect.Width, Math.Max(boundsOffsetFromStart.rect.Height - yOffset, 0))); } else if (!vertical_orientation) { boundsOffsetFromStart.rect = new Rect(new Point(xOffset, 0), new Size(Math.Max(boundsOffsetFromStart.rect.Width - xOffset, 0), boundsOffsetFromStart.rect.Height)); } // .. unless if the child uses a pecentage of the perants dimension, in which case pass the original width // Use the original perants width if the child is using a percentage of the perants width (in this case the space currently used is ignored) if (((BaseLayout)layoutItem).sizeParams.WidthPercent > 0) { boundsOffsetFromStart.rect.Width = perantBounds.rect.Width; boundsOffsetFromStart.rect.X = perantBounds.rect.X; } // Use the original perants height if the child is using a percentage of the perants height if (((BaseLayout)layoutItem).sizeParams.HeightPercent > 0) { boundsOffsetFromStart.rect.Height = perantBounds.rect.Height; boundsOffsetFromStart.rect.Y = perantBounds.rect.Y; } MeasuredLayout nextChild = layoutItem.getMeasuredLayout(boundsOffsetFromStart); nextChild.setBounds(offsetBounds(yOffset, xOffset, nextChild.getBounds())); calculatedRootItem.addCalculatedChild(nextChild); yOffset += nextChild.getBounds().rect.Height; xOffset += nextChild.getBounds().rect.Width; } // if the bounds were set to the perants (if the param was wrap) then change to the calcualted dimension if (vertical_orientation) { if (sizeParams.Width == WRAP_CONTENTS) { calculatedRootItem.getBounds().rect.Width = largestX; } if (sizeParams.Height == WRAP_CONTENTS) { calculatedRootItem.getBounds().rect.Height = yOffset; } } else { if (sizeParams.Width == WRAP_CONTENTS) { calculatedRootItem.getBounds().rect.Width = xOffset; } if (sizeParams.Height == WRAP_CONTENTS) { calculatedRootItem.getBounds().rect.Height = largestY; } } if (invertDirection) { inverseBounds(calculatedRootItem, !vertical_orientation, vertical_orientation); } return(calculatedRootItem); }
public void addCalculatedChild(MeasuredLayout calculatedLayoutItem) { calculatedChildren.Add(calculatedLayoutItem); }
private static void LayoutLine(MeasuredLayout layout, FlexSpacing spacing, Axis axis, BoxConstraint constraint) { int total = 0; try { total = layout .Elements .Select(l => l.Size.GetAxis(axis)) .Sum(); } catch (ArithmeticException ex) { throw; } // if !isbounded, it's just a total + maxsize on offset // if isbounded, then calc the flex spacing // add it all together for the size var lineSpacing = constraint.IsBounded(axis) ? CalculateLineSpacing(spacing, constraint.GetMaxSize().GetAxis(axis) - total, layout.Elements.Count) : new FlexSpacingMeasurement() { Between = 0, End = 0, Start = 0 }; var used = lineSpacing.Start; var crossMax = 0; for (var x = 0; x < layout.Elements.Count; x++) { var item = layout.Elements[x]; item.Offset = used; used += item.Size.GetAxis(axis); if (x != layout.Elements.Count - 1) { // add between for every item that's not 'last' used += lineSpacing.Between; } var cross = item.Size.GetAxis(axis.CrossAxis()); if (cross < int.MaxValue && cross > crossMax) { crossMax = cross; } } used += lineSpacing.End; foreach (var i in layout.Elements) { i.Constraint = i.Constraint.Set(axis.CrossAxis(), crossMax); } layout.Size = axis == Axis.Horizontal ? new Size(used, crossMax) : new Size(crossMax, used); }