private Rect EstimateExtent(Size availableSize, string layoutId) { ILayoutable firstRealizedElement = null; Rect firstBounds = new Rect(); ILayoutable lastRealizedElement = null; Rect lastBounds = new Rect(); int firstDataIndex = -1; int lastDataIndex = -1; if (_elementManager.GetRealizedElementCount() > 0) { firstRealizedElement = _elementManager.GetAt(0); firstBounds = _elementManager.GetLayoutBoundsForRealizedIndex(0); firstDataIndex = _elementManager.GetDataIndexFromRealizedRangeIndex(0);; int last = _elementManager.GetRealizedElementCount() - 1; lastRealizedElement = _elementManager.GetAt(last); lastDataIndex = _elementManager.GetDataIndexFromRealizedRangeIndex(last); lastBounds = _elementManager.GetLayoutBoundsForRealizedIndex(last); } Rect extent = _algorithmCallbacks.Algorithm_GetExtent( availableSize, _context, firstRealizedElement, firstDataIndex, firstBounds, lastRealizedElement, lastDataIndex, lastBounds); Logger.TryGet(LogEventLevel.Verbose, "Repeater")?.Log(this, "{LayoutId} Extent: ({Bounds})", layoutId, extent); return(extent); }
public static Size MeasureDecorator( ILayoutable decorator, ILayoutable content, Size availableSize, Thickness padding) { double width = 0; double height = 0; if (content != null) { content.Measure(availableSize.Deflate(padding)); Size s = content.DesiredSize.Value.Inflate(padding); width = s.Width; height = s.Height; } if (decorator.Width > 0) { width = decorator.Width; } if (decorator.Height > 0) { height = decorator.Height; } return(new Size(width, height)); }
public override void Layout(ILayoutable layoutable) { Vector2 size = PerformLayout(layoutable); if (AutoSize) { if (NewLine) { if (HorizontalFill) { layoutable.Size = new SlimDX.Vector2(layoutable.Size.X, size.Y + layoutable.Padding.Vertical); } else { layoutable.Size = new SlimDX.Vector2(size.X + layoutable.Padding.Horizontal, layoutable.Size.Y); } } else { layoutable.Size = new Vector2(size.X + layoutable.Padding.Vertical, size.Y + layoutable.Padding.Horizontal); } if (Origin != FlowOrigin.TopLeft) { PerformLayout(layoutable); } } }
/// <inheritdoc/> void ILayoutable.ChildDesiredSizeChanged(ILayoutable control) { if (!_measuring) { InvalidateMeasure(); } }
public virtual void InvalidateArrange(ILayoutable control) { control = control ?? throw new ArgumentNullException(nameof(control)); Dispatcher.UIThread.VerifyAccess(); if (_disposed) { return; } if (!control.IsAttachedToVisualTree) { #if DEBUG throw new AvaloniaInternalException( "LayoutManager.InvalidateArrange called on a control that is detached from the visual tree."); #else return; #endif } if (control.VisualRoot != _owner) { throw new ArgumentException("Attempt to call InvalidateArrange on wrong LayoutManager."); } _toArrange.Enqueue(control); QueueLayoutPass(); }
private void ApplyStyles(string screenName, ILayoutable scr, object cache) { string cssFile = null; var sheet = scr as ICustomStyleSheet; if (sheet != null) { if (!string.IsNullOrEmpty(sheet.StyleSheet)) { cssFile = sheet.StyleSheet; } } TimeStamp.Start("Init styles"); IStyleSheet styleSheet = InitStyles(screenName, cssFile); styleSheet.SetCache((IDisposable)cache); TimeStamp.Log("Init styles"); TimeStamp.Start("Assign styles"); styleSheet.Assign(scr); TimeStamp.Log("Assign styles"); TimeStamp.Start("Apply styles"); scr.ApplyStyles(styleSheet, StyleSheetContext.Current.EmptyBound, StyleSheetContext.Current.EmptyBound); TimeStamp.Log("Apply styles"); }
public override void onMouseMove(object sender, MouseMoveEventArgs e) { base.onMouseMove(sender, e); Widget oldHW = HoverWidget; Rectangle scr = this.ScreenCoordinates(this.getSlot()); ProcessMouseMove(e.X - scr.X, e.Y - scr.Y); Widget newHW = HoverWidget; if (newHW == null) { return; } if (draggedObj != null) { if (draggedObj.Parent == null) { if (tryAddObjectTo(newHW, draggedObj)) { RegisterForRedraw(); return; } } else if (newHW != draggedObj) { //lock (imlVE.UpdateMutex) { ILayoutable possibleParent = getPossibleParent(newHW, draggedObj); if (possibleParent == null) { Group g = newHW.Parent as Group; if (g != null && g != draggedObj) { removeObject(draggedObj); g.InsertChild(g.Children.IndexOf(newHW), draggedObj); RegisterForRedraw(); return; } } else if (possibleParent != draggedObj.Parent) { removeObject(draggedObj); if (tryAddObjectTo(possibleParent, draggedObj)) { RegisterForRedraw(); return; } } //} } } if (oldHW == newHW) { return; } //RegisterForRedraw (); }
public void AddItem(ILayoutable item, HorizontalPosition horizontalPosition, VerticalPosition verticalPosition, LayoutOrigin layoutFrom = LayoutOrigin.Center) { if (item == null) { throw new ArgumentNullException("item"); } var position = new OverallPosition { HorizontalPosition = horizontalPosition, VerticalPosition = verticalPosition, LayoutOrigin = layoutFrom }; _items.Add(item, position); item.Alpha = _alpha; item.AttachTo(_backgroundSprite, true); item.RelativeZ = 0.1f; item.ParentLayout = this; if (item.OnAddedToLayout != null) { item.OnAddedToLayout(this); } PositionItem(item, horizontalPosition, verticalPosition, layoutFrom); // When the size changes, make sure to reposition the item so it's still in the same spot item.OnSizeChangeHandler = new LayoutableEvent(delegate(ILayoutable sender) { PositionItem(item, horizontalPosition, verticalPosition, layoutFrom); }); }
private void Arrange(ILayoutable control) { if (control.VisualParent is ILayoutable parent) { Arrange(parent); } if (!control.IsArrangeValid && control.IsAttachedToVisualTree) { if (control is IEmbeddedLayoutRoot embeddedRoot) { control.Arrange(new Rect(embeddedRoot.AllocatedSize)); } else if (control is ILayoutRoot root) { control.Arrange(new Rect(root.DesiredSize)); } else if (control.PreviousArrange != null) { // Has been observed that PreviousArrange sometimes is null, probably a bug somewhere else. // Condition observed: control.VisualParent is Scrollbar, control is Border. control.Arrange(control.PreviousArrange.Value); } } }
private void Measure(ILayoutable control) { // Controls closest to the visual root need to be arranged first. We don't try to store // ordered invalidation lists, instead we traverse the tree upwards, measuring the // controls closest to the root first. This has been shown by benchmarks to be the // fastest and most memory-efficient algorithm. if (control.VisualParent is ILayoutable parent) { Measure(parent); } // If the control being measured has IsMeasureValid == true here then its measure was // handed by an ancestor and can be ignored. The measure may have also caused the // control to be removed. if (!control.IsMeasureValid && control.IsAttachedToVisualTree) { if (control is ILayoutRoot root) { root.Measure(Size.Infinity); } else if (control.PreviousMeasure.HasValue) { control.Measure(control.PreviousMeasure.Value); } } }
private Rect EstimateExtent(Size availableSize, string layoutId) { ILayoutable firstRealizedElement = null; Rect firstBounds = new Rect(); ILayoutable lastRealizedElement = null; Rect lastBounds = new Rect(); int firstDataIndex = -1; int lastDataIndex = -1; if (_elementManager.GetRealizedElementCount() > 0) { firstRealizedElement = _elementManager.GetAt(0); firstBounds = _elementManager.GetLayoutBoundsForRealizedIndex(0); firstDataIndex = _elementManager.GetDataIndexFromRealizedRangeIndex(0);; int last = _elementManager.GetRealizedElementCount() - 1; lastRealizedElement = _elementManager.GetAt(last); lastDataIndex = _elementManager.GetDataIndexFromRealizedRangeIndex(last); lastBounds = _elementManager.GetLayoutBoundsForRealizedIndex(last); } Rect extent = _algorithmCallbacks.Algorithm_GetExtent( availableSize, _context, firstRealizedElement, firstDataIndex, firstBounds, lastRealizedElement, lastDataIndex, lastBounds); return(extent); }
private void PositionItem(ILayoutable item, ILayoutable lastItem = null) { var position = _items[item]; var lastPosition = (lastItem != null ? _items[lastItem] : (CircularPosition)null); float startingRadians = MathHelper.ToRadians(StartingDegrees); float absoluteRadians; switch (CurrentArrangementMode) { case ArrangementMode.Clockwise: absoluteRadians = CalculateClockwisePosition(position, lastPosition, startingRadians); break; case ArrangementMode.CounterClockwise: absoluteRadians = CalculateClockwisePosition(position, lastPosition, startingRadians, true); break; case ArrangementMode.EvenlySpaced: absoluteRadians = CalculateEvenlySpacedPosition(position, lastPosition, startingRadians); break; case ArrangementMode.Manual: default: absoluteRadians = startingRadians + position.RadianOffset; break; } position.AbsoluteRadians = absoluteRadians; float xCoord = (float)Math.Cos(absoluteRadians) * (Radius + position.RadiusOffset); float yCoord = (float)Math.Sin(absoluteRadians) * (Radius + position.RadiusOffset); item.RelativeX = xCoord; item.RelativeY = yCoord; }
public void AddItem(ILayoutable item, float radiusOffset = 0, float degreeOffset = 0) { if (item == null) { throw new ArgumentNullException("item"); } if (!_items.ContainsKey(item)) { // Add the item to the list _items.Add(item, new CircularPosition()); item.AttachTo(_backgroundSprite, true); item.RelativeZ = 0.1f; item.Alpha = _alpha; item.ParentLayout = this; if (item.OnAddedToLayout != null) { item.OnAddedToLayout(this); } } // Calculate the item's position _items[item].RadiusOffset = radiusOffset; _items[item].RadianOffset = MathHelper.ToRadians(degreeOffset); // Trigger a recalulation of the layout _recalculateLayout = true; // Set the size to realculate when a control changes item.OnSizeChangeHandler = sender => _recalculateLayout = true; }
public void RemoveItem(ILayoutable item) { int index = 0; bool found = false; for (int x = 0; x < _items.Count; x++) { index = x; found = _items[x].Key == item; if (found) { break; } } if (!found) { return; // Nothing to remove } _items.RemoveAt(index); // Only detach it if the item is still attached to this if (item.Parent == _backgroundSprite) { item.Detach(); item.OnSizeChangeHandler = null; } }
public static SizeF PreferredSize(ILayoutable view, SizeF bounds) { var layout = new LayoutBuilder(new RectangleF(PointF.Empty, bounds)); view.OnLayout(layout); return(layout.PreferredSize); }
private void ApplyStyles(string screenName, ILayoutable scr, object cache) { string cssFile = null; var sheet = scr as ICustomStyleSheet; if (sheet != null) { if (!string.IsNullOrEmpty(sheet.StyleSheet)) cssFile = sheet.StyleSheet; } TimeStamp.Start("Init styles"); IStyleSheet styleSheet = InitStyles(screenName, cssFile); styleSheet.SetCache((IDisposable)cache); TimeStamp.Log("Init styles"); TimeStamp.Start("Assign styles"); styleSheet.Assign(scr); TimeStamp.Log("Assign styles"); TimeStamp.Start("Apply styles"); scr.ApplyStyles(styleSheet, StyleSheetContext.Current.EmptyBound, StyleSheetContext.Current.EmptyBound); TimeStamp.Log("Apply styles"); }
public override void Layout(ILayoutable layoutable) { Vector2 contentPosition = ContentPosition(layoutable); Vector2 contentArea = ContentArea(layoutable); Vector2 dockPosition = contentPosition; Vector2 dockSize = contentArea; foreach (var v in layoutable.LayoutChildren) { if (v.Dock != System.Windows.Forms.DockStyle.None) { Vector2 size = Vector2.Zero; Vector2 outerSize = Vector2.Zero; Vector2 pos = Vector2.Zero; if (v.Dock == System.Windows.Forms.DockStyle.Fill) { outerSize = dockSize; size = outerSize - MarginSize(v); pos = dockPosition + MarginPosition(v); } else if (v.Dock == System.Windows.Forms.DockStyle.Bottom) { outerSize = new Vector2(dockSize.X, v.Size.Y + v.Margin.Vertical); size = outerSize - MarginSize(v); pos = dockPosition + dockSize - outerSize + MarginPosition(v); dockSize = new Vector2(dockSize.X, dockSize.Y - outerSize.Y); } else if (v.Dock == System.Windows.Forms.DockStyle.Left) { outerSize = new Vector2(v.Size.X + v.Margin.Horizontal, dockSize.Y); size = outerSize - MarginSize(v); pos = dockPosition + MarginPosition(v); dockPosition = new Vector2(dockPosition.X + outerSize.X, dockPosition.Y); dockSize = new Vector2(dockSize.X - outerSize.X, dockSize.Y); } else if (v.Dock == System.Windows.Forms.DockStyle.Right) { outerSize = new Vector2(v.Size.X + v.Margin.Horizontal, dockSize.Y); size = outerSize - MarginSize(v); pos = dockPosition + dockSize - outerSize + MarginPosition(v); dockSize = new Vector2(dockSize.X - outerSize.X, dockSize.Y); } else if (v.Dock == System.Windows.Forms.DockStyle.Top) { outerSize = new Vector2(dockSize.X, v.Size.Y + v.Margin.Vertical); size = outerSize - MarginSize(v); pos = dockPosition + MarginPosition(v); dockPosition = new Vector2(dockPosition.X, dockPosition.Y + outerSize.Y); dockSize = new Vector2(dockSize.X, dockSize.Y - outerSize.Y); } v.Size = size; v.Location = pos; } else { v.Location = contentPosition + OrientationUtil.Position(v.Anchor, contentArea, v.Position, v.Size); } } }
void ILayoutManager.RegisterEffectiveViewportListener(ILayoutable control) { _effectiveViewportChangedListeners ??= new List <EffectiveViewportChangedListener>(); _effectiveViewportChangedListeners.Add(new EffectiveViewportChangedListener( control, CalculateEffectiveViewport(control))); }
public void AddItem(ILayoutable item, Alignment alignment = Alignment.Default) { foreach (var pair in _items) { if (pair.Key == item) { return; // already part of this layout } } _items.Add(new KeyValuePair <ILayoutable, Alignment>(item, alignment)); item.AttachTo(_backgroundSprite, true); item.RelativeZ = 0.1f; item.Alpha = _alpha; item.ParentLayout = this; _recalculateLayout = true; if (item.OnAddedToLayout != null) { item.OnAddedToLayout(this); } PerformLayout(); item.OnSizeChangeHandler = sender => { _recalculateLayout = true; // If a recalculation already happened this frame, manually trigger a new one if (Math.Abs(_lastLayoutFrame - TimeManager.CurrentTime) > double.Epsilon) { ForceUpdateDependencies(); } }; }
public void EnqueueAfterThisAndParentSizing(LayoutingType _lt, ILayoutable _object) { LayoutingQueueItem lqi = new LayoutingQueueItem(_lt, _object); LayoutingType sizing = LayoutingType.Width; if (_lt == LayoutingType.Y) { sizing = LayoutingType.Height; } LinkedListNode <LayoutingQueueItem> parentLqi = searchLqi(_object.Parent, sizing); LinkedListNode <LayoutingQueueItem> thisLqi = searchLqi(_object, sizing); if (parentLqi == null) { if (thisLqi != null) { _object.RegisteredLQINodes.Add(this.AddAfter(thisLqi, lqi)); } else { _object.RegisteredLQINodes.Add(this.AddLast(lqi)); } } else { if (thisLqi == null) { _object.RegisteredLQINodes.Add(this.AddAfter(parentLqi, lqi)); } else { switch (sizing) { case LayoutingType.Width: if (_object.Parent.getBounds().Width < 0) { _object.RegisteredLQINodes.Add(this.AddAfter(parentLqi, lqi)); } else { _object.RegisteredLQINodes.Add(this.AddAfter(thisLqi, lqi)); } break; case LayoutingType.Height: if (_object.Parent.getBounds().Height < 0) { _object.RegisteredLQINodes.Add(this.AddAfter(parentLqi, lqi)); } else { _object.RegisteredLQINodes.Add(this.AddAfter(thisLqi, lqi)); } break; } } } }
Vector2 PerformLayout(ILayoutable layoutable) { Vector2 contentPosition = ContentPosition(layoutable); Vector2 contentArea = ContentArea(layoutable); float x = 0, y = 0, rowMax = 0, sizeX = 0, sizeY = 0; foreach (ILayoutable v in layoutable.LayoutChildren) { if (v.IsVisible) { float outerSizeX = v.Size.X + v.Margin.Horizontal; float outerSizeY = v.Size.Y + v.Margin.Vertical; if (NewLine) { if (HorizontalFill) { if (x + outerSizeX > contentArea.X) { x = 0; y += rowMax; rowMax = 0; } } else { if (y + outerSizeY > contentArea.Y) { y = 0; x += rowMax; rowMax = 0; } } } var p = new SlimDX.Vector2(x, y); if (Origin == FlowOrigin.TopRight || Origin == FlowOrigin.BottomRight) { p.X = contentArea.X - x - outerSizeX; } if (Origin == FlowOrigin.BottomLeft || Origin == FlowOrigin.BottomRight) { p.Y = contentArea.Y - y - outerSizeY; } v.Location = contentPosition + new Vector2(v.Margin.Left, v.Margin.Top) + p; sizeX = Math.Max(sizeX, x + outerSizeX); sizeY = Math.Max(sizeY, y + outerSizeY); if (HorizontalFill) { x += outerSizeX; rowMax = Math.Max(rowMax, outerSizeY); } else { y += outerSizeY; rowMax = Math.Max(rowMax, outerSizeX); } } } return(new Vector2(sizeX, sizeY)); }
/// <inheritdoc/> public void InvalidateArrange(ILayoutable control) { Contract.Requires <ArgumentNullException>(control != null); Dispatcher.UIThread.VerifyAccess(); _toArrange.Enqueue(control); QueueLayoutPass(); }
/// <inheritdoc/> public void InvalidateArrange(ILayoutable control) { Contract.Requires<ArgumentNullException>(control != null); Dispatcher.UIThread.VerifyAccess(); _toArrange.Enqueue(control); QueueLayoutPass(); }
private static void ArrangeToFill(ILayoutable layoutable, Size containerSize, Margin margin) { var containerRect = new Rect(new Point(0, 0), containerSize); var marginsCutout = margin.AsThickness(); var withoutMargins = containerRect.Deflate(marginsCutout); layoutable.Arrange(withoutMargins); }
/// <summary> /// Calculates a control's size based on its <see cref="ILayoutable.Width"/>, /// <see cref="ILayoutable.Height"/>, <see cref="ILayoutable.MinWidth"/>, /// <see cref="ILayoutable.MaxWidth"/>, <see cref="ILayoutable.MinHeight"/> and /// <see cref="ILayoutable.MaxHeight"/>. /// </summary> /// <param name="control">The control.</param> /// <param name="constraints">The space available for the control.</param> /// <returns>The control's size.</returns> public static Size ApplyLayoutConstraints(ILayoutable control, Size constraints) { var minmax = new MinMax(control); return(new Size( MathUtilities.Clamp(constraints.Width, minmax.MinWidth, minmax.MaxWidth), MathUtilities.Clamp(constraints.Height, minmax.MinHeight, minmax.MaxHeight))); }
/// <summary> /// Calls <see cref="InvalidateArrange"/> on the control on which a property changed. /// </summary> /// <param name="e">The event args.</param> private static void AffectsArrangeInvalidate(PerspexPropertyChangedEventArgs e) { ILayoutable control = e.Sender as ILayoutable; if (control != null) { control.InvalidateArrange(); } }
public void InvalidateArrange(ILayoutable item) { if (!this.LayoutQueued) { IVisual visual = item as IVisual; this.layoutNeeded.OnNext(Unit.Default); this.LayoutQueued = true; } }
public void Add(ILayoutable element, int dataIndex) { if (_realizedElements.Count == 0) { _firstRealizedDataIndex = dataIndex; } _realizedElements.Add(element); _realizedElementLayoutBounds.Add(default);
public static Size ApplyLayoutConstraints(ILayoutable control, Size constraints) { double width = (control.Width > 0) ? control.Width : constraints.Width; double height = (control.Height > 0) ? control.Height : constraints.Height; width = Math.Min(width, control.MaxWidth); width = Math.Max(width, control.MinWidth); height = Math.Min(height, control.MaxHeight); height = Math.Max(height, control.MinHeight); return new Size(width, height); }
internal void EnsureFirstElementOwnership(VirtualizingLayoutContext context) { if (_cachedFirstElement != null && FlowAlgorithm.GetElementIfRealized(0) != null) { // We created the element, but then flowlayout algorithm took ownership, so we can clear it and // let flowlayout algorithm do its thing. context.RecycleElement(_cachedFirstElement); _cachedFirstElement = null; } }
public StyleKey(ILayoutable control) : this() { int hash; _parts = GetKey(control, out hash); _hash = hash; #if DEBUG _partsString = _parts.Select(val => val.ToString()).Aggregate((seq, next) => seq + "->" + next); #endif }
public bool TryAddElement0(ILayoutable element) { if (_elementManager.GetRealizedElementCount() == 0) { _elementManager.Add(element, 0); return(true); } return(false); }
public static Size MeasureChild(ILayoutable control, Size availableSize, Thickness padding) { if (control != null) { control.Measure(availableSize.Deflate(padding)); return(control.DesiredSize.Inflate(padding)); } return(new Size(padding.Left + padding.Right, padding.Bottom + padding.Top)); }
public void AddItem(ILayoutable item, int rowIndex, int columnIndex, HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left, VerticalAlignment verticalAlignment = VerticalAlignment.Top) { if (columnIndex < 0) { throw new InvalidOperationException("Item cannot be placed in a column index less than 0"); } if (rowIndex < 0) { throw new InvalidOperationException("Item cannot be placed in a row index less than 0"); } // Ignore null items if (item == null) { return; } // If this item is already tracked, remove it from the current position // and place the item in the new position if (_items.Contains(item)) { _items.Remove(item); } // Add the item to the grid collection if (_items[rowIndex, columnIndex] != null) { throw new InvalidOperationException( string.Format("An item already exists for this grid at row {0} column {1}", rowIndex, columnIndex)); } var alignment = new GridAlignment { HorizontalAlignment = horizontalAlignment, VerticalAlignment = verticalAlignment }; _items.Add(item, alignment, rowIndex, columnIndex); // Attach the item to the background sprite item.AttachTo(_backgroundSprite, true); item.RelativeZ = 0.1f; item.Alpha = _alpha; item.ParentLayout = this; if (item.OnAddedToLayout != null) { item.OnAddedToLayout(this); } _recalculateLayout = true; item.OnSizeChangeHandler = sender => _recalculateLayout = true; }
private void ButtonFocused(ILayoutable sender) { const float SPACING = 25; ArrowSprite.RelativeY = sender.RelativeY; ArrowSprite.Visible = true; //ArrowSprite.Z = sender.Z; if (sender != _optionsButton) { ArrowSprite.RelativeX = (sender.RelativeX - sender.ScaleX - SPACING); ArrowSprite.RelativeRotationZ = (float)(Math.PI * 0.5); } else { ArrowSprite.RelativeX = (sender.RelativeX + sender.ScaleX + SPACING); ArrowSprite.RelativeRotationZ = (float)(Math.PI * 1.5); } }
private static IStyleKeyPart[] GetKey(ILayoutable control, out int hash) { hash = control.Name.GetHashCode(); List<IStyleKeyPart> key; var parent = control.Parent as ILayoutable; if (parent != null) { int parentHash; IStyleKeyPart[] parentParts; if (parent.StyleKey != null) { IStyleKey parentKey = parent.StyleKey; parentParts = parentKey.Parts; parentHash = parentKey.GetHashCode(); } else parentParts = GetKey(parent, out parentHash); key = new List<IStyleKeyPart>(parentParts.Length + 1); key.AddRange(parentParts); hash ^= parentHash; } else key = new List<IStyleKeyPart>(1); string cssClass = control.CssClass; if (!string.IsNullOrEmpty(cssClass)) { cssClass = cssClass.ToLower(); hash ^= cssClass.GetHashCode(); } key.Add(!string.IsNullOrEmpty(cssClass) ? new Part(control.Name.ToLower(), cssClass) : new Part(control.Name.ToLower())); return key.ToArray(); }
public static Bound Screen(StyleSheet.StyleSheet stylesheet , ILayoutable parent , ILayoutable control , Bound screenBound) { IStyleSheetHelper style = stylesheet.Helper; float parentW = screenBound.Width; float parentH = screenBound.Height; float paddingL = style.Padding<PaddingLeft>(parent, parentW); float paddingT = style.Padding<PaddingTop>(parent, parentH); float paddingR = style.Padding<PaddingRight>(parent, parentW); float paddingB = style.Padding<PaddingBottom>(parent, parentH); float borderWidth = style.BorderWidth(parent); float w = style.Width(control, parentW); float h = style.Height(control, parentH); float marginL = style.Margin<MarginLeft>(control, parentW); float marginT = style.Margin<MarginTop>(control, parentH); float marginR = style.Margin<MarginRight>(control, parentW); float marginB = style.Margin<MarginBottom>(control, parentH); InitializeImageContainer(stylesheet, control, ref w, ref h); float maxW = parentW - (marginL + marginR) - (paddingL + paddingR) - 2 * borderWidth; if (parentW < paddingL + marginL + w + marginR + paddingR + 2 * borderWidth) w = maxW; float maxH = parentH - (marginT + marginB) - (paddingT + paddingB) - 2 * borderWidth; if (parentH < paddingT + marginT + h + marginB + paddingB + 2 * borderWidth) h = maxH; float l = borderWidth + paddingL + marginL; float t = borderWidth + paddingT + marginT; Bound bound = control.Apply(stylesheet, new Bound(w, h), new Bound(maxW, maxH)); w = bound.Width > maxW ? maxW : bound.Width; h = bound.Height > maxH ? maxH : bound.Height; control.Frame = new Rectangle(l, t, w, h); return screenBound; }
private void Measure(ILayoutable control) { var root = control as ILayoutRoot; var parent = control.VisualParent as ILayoutable; if (root != null) { root.Measure(root.MaxClientSize); } else if (parent != null) { Measure(parent); } if (!control.IsMeasureValid) { control.Measure(control.PreviousMeasure.Value); } _toMeasure.Remove(control); }
private void Arrange(ILayoutable control) { var root = control as ILayoutRoot; var parent = control.VisualParent as ILayoutable; if (root != null) { root.Arrange(new Rect(root.DesiredSize)); } else if (parent != null) { Arrange(parent); } if (control.PreviousArrange.HasValue) { control.Arrange(control.PreviousArrange.Value); } _toArrange.Remove(control); }
public static void InitializeImageContainer(StyleSheet.StyleSheet stylesheet , ILayoutable control , ref float w , ref float h) { var container = control as IImageContainer; if (container != null && container.InitializeImage(stylesheet)) { float proportion = ((float)container.ImageWidth) / container.ImageHeight; if (w == 0 && h != 0) w = (int)Math.Round(h * proportion); else if (h == 0 && w != 0) h = (int)Math.Round(w / proportion); } }
public void AttachTo(ILayoutable obj, bool changeRelative) { obj.AttachObject(_sprite, changeRelative); }
public override void Layout(ILayoutable layoutable) { Vector2 contentPosition = ContentPosition(layoutable); Vector2 contentArea = ContentArea(layoutable); int y = 0, x = 0; Action incY = () => { if ((Origin & System.Windows.Forms.AnchorStyles.Top) != System.Windows.Forms.AnchorStyles.None) y++; if ((Origin & System.Windows.Forms.AnchorStyles.Bottom) != System.Windows.Forms.AnchorStyles.None) y--; }; Action incX = () => { if ((Origin & System.Windows.Forms.AnchorStyles.Left) != System.Windows.Forms.AnchorStyles.None) x++; if ((Origin & System.Windows.Forms.AnchorStyles.Right) != System.Windows.Forms.AnchorStyles.None) x--; }; if ((Origin & System.Windows.Forms.AnchorStyles.Right) != System.Windows.Forms.AnchorStyles.None) x = NWidth - 1; if ((Origin & System.Windows.Forms.AnchorStyles.Bottom) != System.Windows.Forms.AnchorStyles.None) y = NHeight - 1; float dy = contentArea.Y / (float)NHeight, dx = contentArea.X / (float)NWidth; foreach (ILayoutable v in layoutable.LayoutChildren) { v.Location = contentPosition + new SlimDX.Vector2(x * dx, y * dy) + new Vector2(v.Margin.Left, v.Margin.Top); v.Size = new SlimDX.Vector2(dx, dy) - new Vector2(v.Margin.Horizontal, v.Margin.Vertical); if (HorizontalFill) { incX(); if (x >= NWidth) { x = 0; incY(); } if (x < 0) { x = NWidth - 1; incY(); } } else { incY(); if (y >= NHeight) { y = 0; incX(); } if (y < 0) { y = NHeight - 1; incX(); } } } }
Vector2 PerformLayout(ILayoutable layoutable) { Vector2 contentPosition = ContentPosition(layoutable); Vector2 contentArea = ContentArea(layoutable); float x = 0, y = 0, rowMax = 0, sizeX = 0, sizeY = 0; foreach (ILayoutable v in layoutable.LayoutChildren) if (v.IsVisible) { float outerSizeX = v.Size.X + v.Margin.Horizontal; float outerSizeY = v.Size.Y + v.Margin.Vertical; if (NewLine) { if (HorizontalFill) { if (x + outerSizeX > contentArea.X) { x = 0; y += rowMax; rowMax = 0; } } else { if (y + outerSizeY > contentArea.Y) { y = 0; x += rowMax; rowMax = 0; } } } var p = new SlimDX.Vector2(x, y); if (Origin == FlowOrigin.TopRight || Origin == FlowOrigin.BottomRight) p.X = contentArea.X - x - outerSizeX; if (Origin == FlowOrigin.BottomLeft || Origin == FlowOrigin.BottomRight) p.Y = contentArea.Y - y - outerSizeY; v.Location = contentPosition + new Vector2(v.Margin.Left, v.Margin.Top) + p; sizeX = Math.Max(sizeX, x + outerSizeX); sizeY = Math.Max(sizeY, y + outerSizeY); if (HorizontalFill) { x += outerSizeX; rowMax = Math.Max(rowMax, outerSizeY); } else { y += outerSizeY; rowMax = Math.Max(rowMax, outerSizeX); } } return new Vector2(sizeX, sizeY); }
private void AddLayoutable(Direction area, ILayoutable l) { switch(area) { case Direction.North: myNorth = l; break; case Direction.South: mySouth = l; break; case Direction.East: myEast = l; break; case Direction.West: myWest = l; break; case Direction.Center: myCenter = l; break; default: break; } }
public override void RemoveLayoutable(ILayoutable l) { if(l == myNorth) myNorth = null; else if(l == mySouth) mySouth = null; else if(l == myEast) myEast = null; else if(l == myWest) myWest = null; else if(l == myCenter) myCenter = null; }
private void ButtonLostFocused(ILayoutable sender) { ArrowSprite.Visible = false; }
protected Vector2 MarginPosition(ILayoutable layoutable) { return new Vector2(layoutable.Margin.Left, layoutable.Margin.Top); }
protected Vector2 ContentArea(ILayoutable layoutable) { return layoutable.Size - new Vector2(layoutable.Padding.Horizontal, layoutable.Padding.Vertical); }
public override void RemoveAll() { myNorth = myWest = myEast = mySouth = myCenter = null; }
public static Bound Dock(StyleSheet.StyleSheet stylesheet , ILayoutable parent , IEnumerable<ILayoutable> controls , Bound styleBound , Bound maxBound) { IStyleSheetHelper style = stylesheet.Helper; float parentW = styleBound.Width; float parentH = styleBound.Height; float paddingL = style.Padding<PaddingLeft>(parent, parentW); float paddingT = style.Padding<PaddingTop>(parent, parentH); float paddingR = style.Padding<PaddingRight>(parent, parentW); float paddingB = style.Padding<PaddingBottom>(parent, parentH); float borderWidth = style.BorderWidth(parent); float layoutL = borderWidth + paddingL; float layoutT = borderWidth + paddingT; float layoutW = parentW - (paddingL + paddingR) - 2 * borderWidth; float layoutH = parentH - (paddingT + paddingB) - 2 * borderWidth; foreach (ILayoutable control in controls) { float w = style.Width(control, parentW); float h = style.Height(control, parentH); float marginL = style.Margin<MarginLeft>(control, parentW); float marginT = style.Margin<MarginTop>(control, parentH); float marginR = style.Margin<MarginRight>(control, parentW); float marginB = style.Margin<MarginBottom>(control, parentH); float maxW = layoutW - (marginL + marginR); maxW = maxW > 0 ? maxW : 0; float maxH = layoutH - (marginT + marginB); maxH = maxH > 0 ? maxH : 0; if (layoutW < marginL + w + marginR) w = maxW; if (layoutH < marginT + h + marginB) h = maxH; Bound bound = control.Apply(stylesheet, new Bound(w, h), new Bound(maxW, maxH)); w = bound.Width; h = bound.Height; InitializeImageContainer(stylesheet, control, ref w, ref h); if (layoutW < marginL + w + marginR) w = maxW; if (layoutH < marginT + h + marginB) h = maxH; float offsetL = layoutL; float offsetT = layoutT; DockAlign.Align align = style.DockAlign(control); switch (align) { case DockAlign.Align.Left: offsetL += marginL; offsetT += marginT; layoutL = offsetL + w + marginR; layoutW -= marginL + w + marginR; break; case DockAlign.Align.Top: offsetL += marginL; offsetT += marginT; layoutT = offsetT + h + marginB; layoutH -= marginT + h + marginB; break; case DockAlign.Align.Right: offsetL += layoutW - (w + marginR); offsetT += marginT; layoutW -= marginL + w + marginR; break; case DockAlign.Align.Bottom: offsetL += marginL; offsetT += layoutH - (h + marginB); layoutH -= marginT + h + marginB; break; } control.Frame = new Rectangle(offsetL, offsetT, w, h); } return styleBound; }
public override void Layout(ILayoutable layoutable) { Vector2 size = PerformLayout(layoutable); if (AutoSize) { if (NewLine) { if (HorizontalFill) layoutable.Size = new SlimDX.Vector2(layoutable.Size.X, size.Y + layoutable.Padding.Vertical); else layoutable.Size = new SlimDX.Vector2(size.X + layoutable.Padding.Horizontal, layoutable.Size.Y); } else { layoutable.Size = new Vector2(size.X + layoutable.Padding.Vertical, size.Y + layoutable.Padding.Horizontal); } if (Origin != FlowOrigin.TopLeft) PerformLayout(layoutable); } }
public static Bound Vertical(StyleSheet.StyleSheet stylesheet , ILayoutable parent , IEnumerable<ILayoutable> controls , Bound styleBound , Bound maxBound , bool extensible = false) { IStyleSheetHelper style = stylesheet.Helper; float parentW = styleBound.Width; float parentH = styleBound.Height; float paddingL = style.Padding<PaddingLeft>(parent, parentW); float paddingT = style.Padding<PaddingTop>(parent, parentH); float paddingR = style.Padding<PaddingRight>(parent, parentW); float paddingB = style.Padding<PaddingBottom>(parent, parentH); float borderWidth = style.BorderWidth(parent); float off = paddingT + borderWidth; foreach (ILayoutable control in controls) { float w = style.Width(control, parentW); float h = style.Height(control, parentH); float marginL = style.Margin<MarginLeft>(control, parentW); float marginT = style.Margin<MarginTop>(control, parentH); float marginR = style.Margin<MarginRight>(control, parentW); float marginB = style.Margin<MarginBottom>(control, parentH); off += marginT; float left = borderWidth + paddingL + marginL; float top = off; float right = parentW - (paddingR + marginR) - borderWidth; float bottom = parentH - (paddingB + marginB) - borderWidth; float maxW = right - left; maxW = maxW > 0 ? maxW : 0; float maxH = extensible ? float.MaxValue : bottom - top; maxH = maxH > 0 ? maxH : 0; if (!extensible && maxH < h) h = maxH; w = w > maxW ? maxW : w; Bound bound = control.Apply(stylesheet, new Bound(w, h), new Bound(maxW, maxH)); w = bound.Width; h = bound.Height; InitializeImageContainer(stylesheet, control, ref w, ref h); if (!extensible && maxH < h) h = maxH; if (w < maxW) { HorizontalAlign.Align align = style.HorizontalAlign(control); switch (align) { case HorizontalAlign.Align.Left: break; case HorizontalAlign.Align.Central: float delta = (right - left - w) / 2; left += delta; break; case HorizontalAlign.Align.Right: left = right - w; break; } } control.Frame = new Rectangle(left, top, w, h); off += h + marginB; } return new Bound(styleBound.Width, styleBound.Height, parentW, off + paddingB + borderWidth); }
void UpdateLayoutHandler(DocumentHandler handler) { if (layoutHandler != null) layoutHandler.SelectionChanged -= new EventHandler(layoutHandler_SelectionChanged); layoutHandler = handler.LayoutHandler; if (handler.IsLayoutable) layoutHandler.SelectionChanged += new EventHandler(layoutHandler_SelectionChanged); UpdateLayoutButtons(); }
public abstract void Layout(ILayoutable layoutable);
/// <summary> /// When adding objects to the layout, one must specify the part of the layout as a member /// of the Direction enum. /// </summary> /// <param name="l">object to add </param> /// <param name="constraints">direction to add it at</param> public override void AddLayoutable(ILayoutable l, object constraints) { if(constraints == null) { AddLayoutable(Direction.Center, l); } if(constraints is Direction) { AddLayoutable((Direction)constraints, l); } }
protected Vector2 ContentPosition(ILayoutable layoutable) { return new Vector2(layoutable.Padding.Left, layoutable.Padding.Top); }
public override void RemoveLayoutable(ILayoutable c) { myMembers.Remove(c); }
protected Vector2 MarginSize(ILayoutable layoutable) { return new Vector2(layoutable.Margin.Horizontal, layoutable.Margin.Vertical); }
public override void AddLayoutable(ILayoutable c, object constraints) { myMembers.Add(c); }