/// <summary> /// Writes the attached property Dock to the given element. /// </summary> /// <param name="element">UIElement to which to write the attached property.</param> /// <param name="dock">The property value to set</param> /// <seealso cref="SizingProperty" /> public static void SetWidthSizing(UIElement element, Sizing dock) { if (element == null) { throw new ArgumentNullException("element"); } element.SetValue(WidthSizingProperty, dock); }
public MsqcTags() { Durability = new Durability(); Sizing = new Sizing(); Comfort = new Comfort(); Durability.TotalEntries = 0; Comfort.TotalEntries = 0; Sizing.TotalEntries = 0; }
public void UpdateSizeHints(IList <GameObject> objects) { if (objects.Count == 0) { return; } double maxWidth = 0; double heightOfExpandingObjects = 0; double heightOfFixedSizeObjects = 0; Sizing horizontalSizing = Sizing.FixedSize; Sizing verticalSizing = Sizing.FixedSize; foreach (var o in objects) { if (o.PreferredSize.X > maxWidth) { maxWidth = o.PreferredSize.X; } if (o.VerticalSizing != Sizing.FixedSize) { verticalSizing = Sizing.Expanding; heightOfExpandingObjects += o.PreferredSize.Y; } else if (o.VerticalSizing == Sizing.FixedSize) { heightOfFixedSizeObjects += o.PreferredSize.Y; } if (o.HorizontalSizing != Sizing.FixedSize) { horizontalSizing = Sizing.Expanding; } } double preferredHeight = TopPadding + heightOfExpandingObjects + heightOfFixedSizeObjects + ((objects.Count - 1) * Spacing) + BottomPadding; double preferredWidth = LeftPadding + maxWidth + RightPadding; _horizontalSizing = horizontalSizing; _verticalSizing = verticalSizing; _heightRequestedByExpandingObjects = heightOfExpandingObjects; _heightRequestedByFixedSizeObjects = heightOfFixedSizeObjects; _preferredSize = new Vector(preferredWidth, preferredHeight); }
public Vector GetIndividualSize(CircleRegion region, Sizing sizingHeight, Sizing sizingWidth) { //var h = sizingHeight == Sizing.FromParent; //var w = sizingWidth == Sizing.FromParent; return(region switch { CircleRegion.TopLeft => new Vector(leftRequiredWidth, topRequiredHeight), CircleRegion.TopRight => new Vector(rightRequiredWidth, topRequiredHeight), CircleRegion.BottomRight => new Vector(rightRequiredWidth, bottomRequiredHeight), CircleRegion.BottomLeft => new Vector(leftRequiredWidth, bottomRequiredHeight), CircleRegion.Top => new Vector(centerRequiredWidth, topRequiredHeight), CircleRegion.Bottom => new Vector(centerRequiredWidth, bottomRequiredHeight), CircleRegion.Right => new Vector(rightRequiredWidth, middleRequiredHeight), CircleRegion.Left => new Vector(leftRequiredWidth, middleRequiredHeight), CircleRegion.Middle => new Vector(centerRequiredWidth, middleRequiredHeight), _ => throw new NotImplementedException(), });
private void SetImage() { CGSize labelSize = Sizing.GetStringSize(_dashboardButton.Text, (float)_dashboardButton.FontSize, 0f, 0f, UIFontWeight.Semibold); UIImage image = new UIImage(_dashboardButton.ButtonImage); _button.SetTitle(_dashboardButton.Text, UIControlState.Normal); image = ImageHelper.ResizeImage(image, ImageSize, ImageSize); _button.SetImage(image, UIControlState.Normal); _button.TintColor = UIColor.Gray; var imageAllottedSpaceCenterY = (Control.Frame.Size.Height - _button.TitleLabel.Frame.Size.Height) / 2; var imageInsetTopBottom = imageAllottedSpaceCenterY - ImageSize / 2; var imageInsetLeftRight = Control.Frame.Size.Width / 2 - ImageSize / 2; var labelInsetBottom = (Control.Frame.Size.Height - ImageSize) / 2 - _button.Frame.Height / 2; var labelInsetLeftRight = _button.Frame.Width / 2 - labelSize.Width / 2; _button.ImageEdgeInsets = new UIEdgeInsets(imageInsetTopBottom, imageInsetLeftRight, imageInsetTopBottom, imageInsetLeftRight); var labelInsetRight = Device.Idiom != TargetIdiom.Phone ? labelInsetLeftRight + GetLabelLeftOffset(_dashboardButton.Text) : labelInsetLeftRight; _button.TitleEdgeInsets = new UIEdgeInsets(labelInsetBottom + imageInsetTopBottom + 30 , labelInsetLeftRight - labelSize.Width / 2 + GetLabelLeftOffset(_dashboardButton.Text) , labelInsetBottom, labelInsetRight); AddBadgeToButton(_dashboardButton.BadgeCount); _button.TintColor = AgvanceColors.TintColor.ToUIColor(); }
protected override void ReadRDL(XmlReader reader) { //--- Source if (reader.Name == Rdl.SOURCE) { _source = (Source)Enum.Parse(typeof(Source), reader.ReadString()); } //--- Value if (reader.Name == Rdl.VALUE) { if (_value == null) { _value = new Expression(); } _value.Value = reader.ReadString(); } //--- MIMEType if (reader.Name == Rdl.MIMETYPE) { if (_MIMEType == null) { _MIMEType = new Expression(); } _MIMEType.Value = reader.ReadString(); } //--- Sizing if (reader.Name == Rdl.SIZING) { _sizing = (Sizing)Enum.Parse(typeof(Sizing), reader.ReadString()); } }
public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; if (Visible != null) { hashCode = hashCode * 59 + Visible.GetHashCode(); } if (Source != null) { hashCode = hashCode * 59 + Source.GetHashCode(); } if (Layer != null) { hashCode = hashCode * 59 + Layer.GetHashCode(); } if (SizeX != null) { hashCode = hashCode * 59 + SizeX.GetHashCode(); } if (SizeY != null) { hashCode = hashCode * 59 + SizeY.GetHashCode(); } if (Sizing != null) { hashCode = hashCode * 59 + Sizing.GetHashCode(); } if (Opacity != null) { hashCode = hashCode * 59 + Opacity.GetHashCode(); } if (X != null) { hashCode = hashCode * 59 + X.GetHashCode(); } if (Y != null) { hashCode = hashCode * 59 + Y.GetHashCode(); } if (XAnchor != null) { hashCode = hashCode * 59 + XAnchor.GetHashCode(); } if (YAnchor != null) { hashCode = hashCode * 59 + YAnchor.GetHashCode(); } if (XRef != null) { hashCode = hashCode * 59 + XRef.GetHashCode(); } if (YRef != null) { hashCode = hashCode * 59 + YRef.GetHashCode(); } if (Name != null) { hashCode = hashCode * 59 + Name.GetHashCode(); } if (TemplateItemName != null) { hashCode = hashCode * 59 + TemplateItemName.GetHashCode(); } return(hashCode); } }
public bool Equals([AllowNull] Image other) { if (other == null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return((Visible == other.Visible && Visible != null && other.Visible != null && Visible.Equals(other.Visible)) && (Source == other.Source && Source != null && other.Source != null && Source.Equals(other.Source)) && (Layer == other.Layer && Layer != null && other.Layer != null && Layer.Equals(other.Layer)) && (SizeX == other.SizeX && SizeX != null && other.SizeX != null && SizeX.Equals(other.SizeX)) && (SizeY == other.SizeY && SizeY != null && other.SizeY != null && SizeY.Equals(other.SizeY)) && (Sizing == other.Sizing && Sizing != null && other.Sizing != null && Sizing.Equals(other.Sizing)) && (Opacity == other.Opacity && Opacity != null && other.Opacity != null && Opacity.Equals(other.Opacity)) && (X == other.X && X != null && other.X != null && X.Equals(other.X)) && (Y == other.Y && Y != null && other.Y != null && Y.Equals(other.Y)) && (XAnchor == other.XAnchor && XAnchor != null && other.XAnchor != null && XAnchor.Equals(other.XAnchor)) && (YAnchor == other.YAnchor && YAnchor != null && other.YAnchor != null && YAnchor.Equals(other.YAnchor)) && (XRef == other.XRef && XRef != null && other.XRef != null && XRef.Equals(other.XRef)) && (YRef == other.YRef && YRef != null && other.YRef != null && YRef.Equals(other.YRef)) && (Name == other.Name && Name != null && other.Name != null && Name.Equals(other.Name)) && (TemplateItemName == other.TemplateItemName && TemplateItemName != null && other.TemplateItemName != null && TemplateItemName.Equals(other.TemplateItemName))); }
public override void CalculateLayoutInputHorizontal() { //base.CalculateLayoutInputHorizontal(); float parentWidth = rectTransform.rect.width; float parentHeight = rectTransform.rect.height; //-- Get children -- #region GetChildren rectChildrenNew.Clear(); toIgnoreList.Clear(); for (int i = 0; i < rectTransform.childCount; i++) { var rect = rectTransform.GetChild(i) as RectTransform; if (rect == null) { continue; } if (ignoreInactiveChildren && !rect.gameObject.activeInHierarchy) { continue; } rect.GetComponents(typeof(ILayoutIgnorer), toIgnoreList); if (toIgnoreList.Count == 0) { rectChildrenNew.Add(rect); continue; } foreach (Component component in toIgnoreList) { var ignorer = (ILayoutIgnorer)component; if (!ignorer.ignoreLayout) { rectChildrenNew.Add(rect); break; } } } #endregion //-- -- childrenSizesX.Clear(); childrenSizesY.Clear(); //-- fixed AspectRatio requires X and Y to be set to AspectRatio -- #region FixedAspectRatio //- User chose FixedAspectRatio if ((sizingX == Sizing.FixedAspectRatio && sizingXPreviousValue != Sizing.FixedAspectRatio) || (sizingY == Sizing.FixedAspectRatio && sizingYPreviousValue != Sizing.FixedAspectRatio)) { if (sizingX != Sizing.FixedAspectRatio) { sizingXcached = sizingX; //cache sizingX } if (sizingY != Sizing.FixedAspectRatio) { sizingYcached = sizingY; //cache sizingY } sizingX = Sizing.FixedAspectRatio; sizingY = Sizing.FixedAspectRatio; } //- - //- User chose other mode than FixedAspectRatio - if ((sizingX != Sizing.FixedAspectRatio && sizingXPreviousValue == Sizing.FixedAspectRatio) || (sizingY != Sizing.FixedAspectRatio && sizingYPreviousValue == Sizing.FixedAspectRatio)) { sizingX = sizingXcached; //restore cacheX sizingY = sizingYcached; //restore cacheY } //- - sizingXPreviousValue = sizingX; sizingYPreviousValue = sizingY; #endregion //-- -- //foreach (var rectTransform in rectChildrenNew) //{ // var preferredWidth = LayoutUtility.GetPreferredWidth(rectTransform); // Debug.Log(preferredWidth); //} #region Calculation if (fitType == FitType.Width || fitType == FitType.Height || fitType == FitType.Uniform) { float sqrRt = Mathf.Sqrt(rectChildrenNew.Count); rows = Mathf.CeilToInt(sqrRt); columns = Mathf.CeilToInt(sqrRt); } if (fitType == FitType.Width || fitType == FitType.FixedColumns) { rows = Mathf.CeilToInt(rectChildrenNew.Count / (float)columns); } else if (fitType == FitType.Height || fitType == FitType.FixedRows) { columns = Mathf.CeilToInt(rectChildrenNew.Count / (float)rows); } float gridCellWidth = (parentWidth / (float)columns) - (spacing.x * (float)(columns - 1) / (float)columns) - (padding.left / (float)columns) - (padding.right / (float)columns); float gridCellHeight = (parentHeight / (float)rows) - (spacing.y * (float)(rows - 1) / (float)rows) - (padding.top / (float)rows) - (padding.bottom / (float)rows); //-- CellSize -- for (int i = 0; i < rectChildrenNew.Count; i++) { if (sizingX == Sizing.KeepChildSize) { childrenSizesX.Add(rectChildrenNew[i].rect.width); } else if (sizingX == Sizing.Fit) { childrenSizesX.Add(gridCellWidth); } else if (sizingX == Sizing.FixedSize) { childrenSizesX.Add(fixedCellSize.x); } if (sizingY == Sizing.KeepChildSize) { childrenSizesY.Add(rectChildrenNew[i].rect.height); } else if (sizingY == Sizing.Fit) { childrenSizesY.Add(gridCellHeight); } else if (sizingY == Sizing.FixedSize) { childrenSizesY.Add(fixedCellSize.y); } if (sizingX == Sizing.FixedAspectRatio && sizingX == Sizing.FixedAspectRatio) { float childAspectRatio = cellAspectRatio.x / cellAspectRatio.y; float gridAspectRatio = gridCellWidth / gridCellHeight; gridCellWidth = (gridAspectRatio <= childAspectRatio) ? gridCellWidth : (gridCellHeight * childAspectRatio); gridCellHeight = (gridAspectRatio >= childAspectRatio) ? gridCellHeight : (gridCellWidth / childAspectRatio); childrenSizesX.Add(gridCellWidth); childrenSizesY.Add(gridCellHeight); } } //-- -- //-- CellPosition -- //-- Get grid Height and Width -- float[] columnWidths = new float[columns]; float[] rowHeights = new float[rows]; if (sizingX != Sizing.KeepChildSize && sizingX != Sizing.FixedSize) { rowHeights.Populate(gridCellHeight); columnWidths.Populate(gridCellWidth); } for (int i = 0; i < rectChildrenNew.Count; i++) { (int rowCount, int columnCount) = CalculateRowAndColumnCount(i); columnWidths[columnCount] = Mathf.Max(columnWidths[columnCount], childrenSizesX[i]); rowHeights[rowCount] = Mathf.Max(rowHeights[rowCount], childrenSizesY[i]); } //-- -- //- ChildForceExpand & fitToContentSize- float totalCellWidthOfOneRow = columnWidths.Sum(); float totalRowWidth = totalCellWidthOfOneRow + (spacing.x * (float)(columns - 1)) + padding.left + padding.right; float totalCellHeightOfOneColumn = rowHeights.Sum(); float totalColumnHeight = totalCellHeightOfOneColumn + (spacing.y * (float)(rows - 1)) + padding.bottom + padding.top; float excessParentWidth = 0f; float excessParentHeight = 0f; if (fitContentSizeX) //fitContentSize { rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, totalRowWidth); } else //ChildForceExpand { excessParentWidth = parentWidth - totalRowWidth; if (excessParentWidth < 0f) { excessParentWidth = 0f; } excessParentWidth = childForceExpandX ? excessParentWidth : 0f; } if (fitContentSizeY) //fitContentSize { rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, totalColumnHeight); } else //ChildForceExpand { excessParentHeight = parentHeight - totalColumnHeight; if (excessParentHeight < 0f) { excessParentHeight = 0f; } excessParentHeight = childForceExpandY ? excessParentHeight : 0f; } //- - for (int i = 0; i < rectChildrenNew.Count; i++) { (int rowCount, int columnCount) = CalculateRowAndColumnCount(i); var item = rectChildrenNew[i]; float cellWidth = columnWidths[columnCount]; float cellHeight = rowHeights[rowCount]; //-- ChildAlignment -- #region ChildAlignment float alignmentOffsetX = 0f; float alignmentOffsetY = 0f; if (childAlignment == TextAnchor.LowerCenter || childAlignment == TextAnchor.MiddleCenter || childAlignment == TextAnchor.UpperCenter) { alignmentOffsetX = (columnWidths[columnCount] / 2f) - (childrenSizesX[i] / 2f); } if (childAlignment == TextAnchor.LowerRight || childAlignment == TextAnchor.MiddleRight || childAlignment == TextAnchor.UpperRight) { alignmentOffsetX = columnWidths[columnCount] - childrenSizesX[i]; } if (childAlignment == TextAnchor.MiddleLeft || childAlignment == TextAnchor.MiddleCenter || childAlignment == TextAnchor.MiddleRight) { alignmentOffsetY = (rowHeights[rowCount] / 2f) - (childrenSizesY[i] / 2f); } if (childAlignment == TextAnchor.LowerLeft || childAlignment == TextAnchor.LowerCenter || childAlignment == TextAnchor.LowerRight) { alignmentOffsetY = rowHeights[rowCount] - childrenSizesY[i]; } #endregion //-- -- float xPos = columnWidths.Take(columnCount).Sum(); float yPos = rowHeights.Take(rowCount).Sum(); xPos += (spacing.x * columnCount) + padding.left + ((excessParentWidth / Mathf.Max((columns - 1f), 1f)) * columnCount) + alignmentOffsetX; yPos += (spacing.y * rowCount) + padding.top + ((excessParentHeight / Mathf.Max((rows - 1f), 1f)) * rowCount) + alignmentOffsetY; if (sizingX != Sizing.KeepChildSize) { SetChildAlongAxis(item, 0, xPos, cellWidth); } else { SetChildAlongAxis(item, 0, xPos); } if (sizingY != Sizing.KeepChildSize) { SetChildAlongAxis(item, 1, yPos, cellHeight); } else { SetChildAlongAxis(item, 1, yPos); } } #endregion }
protected virtual Task SetSizingDefaults(Sizing sizing) { return(Task.FromResult(default(object))); }
private void OnWindowSizing() { WindowSizingEventArgs windowSizingEventArgs = new(this); Sizing.Invoke(this, windowSizingEventArgs); }
public static Sizing GetVerticalSizing(this View view, Sizing defaultSizing = Sizing.Fit) { var sizing = view.GetEnvironment <Sizing?>(view, EnvironmentKeys.Layout.VerticalSizing); return(sizing ?? defaultSizing); }
private void OnSizing(IntPtr handledWindow, IntPtr firstParameter, IntPtr secondParameter) { Sizing?.Invoke(handledWindow, firstParameter, secondParameter); }
public static Sizing GetVerticalSizing(this View view, ContainerView container, Sizing defaultSizing = Sizing.Fit) { var sizing = view.GetEnvironment <Sizing?>(view, EnvironmentKeys.Layout.VerticalSizing); if (sizing != null) { return((Sizing)sizing); } if (container != null) { sizing = view.GetEnvironment <Sizing?>(view, $"{container.GetType().Name}.{EnvironmentKeys.Layout.VerticalSizing}"); } return(sizing ?? defaultSizing); }
public static UIComponent Sizing(this UIComponent component, Sizing sizing) { component.DefaultAttributes.Sizing = sizing; return(component); }