/// <summary> /// Sets default values of the view. /// </summary> public override void SetDefaultValues() { base.SetDefaultValues(); Width.DirectValue = ElementSize.FromPixels(160); Height.DirectValue = ElementSize.FromPixels(40); }
/// <summary> /// Sets default values of the view. /// </summary> public override void SetDefaultValues() { base.SetDefaultValues(); Alignment.DirectValue = MarkLight.ElementAlignment.Center; Width.DirectValue = new ElementSize(1.0f, ElementSizeUnit.Percents); Height.DirectValue = new ElementSize(1.0f, ElementSizeUnit.Percents); OverrideWidth.DirectValue = ElementSize.FromPixels(0); OverrideHeight.DirectValue = ElementSize.FromPixels(0); Margin.DirectValue = new ElementMargin(); Offset.DirectValue = new ElementMargin(); Alpha.DirectValue = 1; IsVisible.DirectValue = true; if (ImageComponent != null) { ImageComponent.color = Color.clear; ImageComponent.type = UnityEngine.UI.Image.Type.Simple; } IsActive.DirectValue = true; OffsetFromParent.DirectValue = new ElementMargin(); SortIndex.DirectValue = 0; UpdateRectTransform.DirectValue = true; UpdateBackground.DirectValue = true; }
// TODO is there a way to run a callback when a field changes? public void SetItems(ObservableList <ItemInstance> items) { SetValue("Items", items); int NumInColumn = (int)Math.Ceiling((float)items.Count() / NumInRow); Height.Value = ElementSize.FromPixels(NumInColumn * Template.Height.Value.Pixels + ContainerNameLabel.Height.Value.Pixels); }
public void MarginRight(bool toggle) { LayoutRegion.Margin.Value = new ElementMargin( LayoutRegion.Margin.Value.Left, LayoutRegion.Margin.Value.Top, toggle ? ElementSize.FromPixels(100) : new ElementSize(), LayoutRegion.Margin.Value.Bottom ); }
public void OffsetBottom(bool toggle) { LayoutRegion.Offset.Value = new ElementMargin( LayoutRegion.Offset.Value.Left, LayoutRegion.Offset.Value.Top, LayoutRegion.Offset.Value.Right, toggle ? ElementSize.FromPixels(100) : new ElementSize() ); }
public override void Initialize() { base.Initialize(); float rowSpacing = Container.Spacing.Value.Pixels; float rowWidth = NumInRow * Template.Width.Value.Pixels + (NumInRow + 1) * rowSpacing; Container.Width.Value = ElementSize.FromPixels(rowWidth); }
/// <summary> /// Updates the layout of the view. /// </summary> public override void LayoutChanged() { // set content margins based on tab list size and its orientation var contentMargin = new ElementMargin(); var tabAlignment = ElementAlignment.Center; if (TabHeaderList.Orientation == ElementOrientation.Horizontal) { if (TabHeaderList.Alignment.Value.HasFlag(ElementAlignment.Bottom)) { contentMargin.Bottom = ElementSize.FromPixels(TabHeaderList.Height.Value.Pixels); tabAlignment = ElementAlignment.Top; } else { contentMargin.Top = ElementSize.FromPixels(TabHeaderList.Height.Value.Pixels); tabAlignment = ElementAlignment.Bottom; } } else { if (TabHeaderList.Alignment.Value.HasFlag(ElementAlignment.Right)) { contentMargin.Right = ElementSize.FromPixels(TabHeaderList.Width.Value.Pixels); tabAlignment = ElementAlignment.Left; } else { contentMargin.Left = ElementSize.FromPixels(TabHeaderList.Width.Value.Pixels); tabAlignment = ElementAlignment.Right; } } if (AutoAdjustContentMargin) { TabContent.Margin.Value = contentMargin; } if (AutoAdjustTabListContentAlignment) { TabHeaderList.ContentAlignment.Value = tabAlignment; } base.LayoutChanged(); }
public override void Initialize() { base.Initialize(); this.ForEachChild <View>(x => x.Deactivate(), false); if (!Application.isPlaying) { return; } // TODO: Hardcoded values Height.DirectValue = ElementSize.FromPixels(480f); Width.DirectValue = ElementSize.FromPixels(800f); LayoutChanged(); var height = (int)ActualHeight; var width = (int)ActualWidth; var plane = GameObject.CreatePrimitive(PrimitiveType.Plane); //plane.transform.position = new Vector3(0f, -0.005f, -0.01f); plane.transform.rotation = Quaternion.Euler(90, 180, 0); plane.transform.localScale = new Vector3(width * 0.0001f, 1f, height * 0.0001f); plane.transform.parent = transform; plane.transform.localPosition = new Vector3(0f, 0f, -0.01f); //plane.GetComponent<MeshCollider>().convex = true; var planeRigidbody = plane.AddComponent <Rigidbody>(); planeRigidbody.useGravity = false; planeRigidbody.isKinematic = true; // VRActor needed for mouse / flystick interactions plane.AddComponent <VRActor>().Grabable = false; _vrWebView = plane.AddComponent <VRWebView>(); _vrWebView.Width = (int)(width * 1.5); _vrWebView.Height = (int)(height * 1.5); _vrWebView.MouseInteractionsIn3D = true; }
/// <summary> /// Value converter for ElementSize type. /// </summary> public override ConversionResult Convert(object value, ValueConverterContext context) { if (value == null) { return(base.Convert(value, context)); } Type valueType = value.GetType(); if (valueType == _type) { return(base.Convert(value, context)); } else if (valueType == _stringType) { var stringValue = (string)value; try { var convertedValue = ElementSize.Parse(stringValue, context.UnitSize); return(new ConversionResult(convertedValue)); } catch (Exception e) { return(ConversionFailed(value, e)); } } else if (valueType == _intType) { return(new ConversionResult(ElementSize.FromPixels((float)value))); } else if (valueType == _floatType) { return(new ConversionResult(ElementSize.FromPixels((float)value))); } return(ConversionFailed(value)); }
/// <summary> /// Called when the layout of the view has changed. /// </summary> public override void LayoutChanged() { if (ParentDataGrid == null) { return; } // arrange columns according to the settings in the parent datagrid var columns = this.GetChildren <Column>(false); var columnHeaders = ParentDataGrid.RowHeader != null?ParentDataGrid.RowHeader.GetChildren <ColumnHeader>(false) : new List <ColumnHeader>(); if (columnHeaders.Count > 0 && columns.Count > columnHeaders.Count) { Utils.LogWarning("[MarkLight] {0}: Row contains more columns ({1}) than there are column headers ({2}).", name, columns.Count, columnHeaders.Count); // remove columns outside the bounds columns = new List <Column>(columns.Take(columnHeaders.Count)); } // if no headers exist arrange columns to fit row with equal widths if (columnHeaders.Count <= 0) { // adjust columns to row width float columnWidth = (ActualWidth - ((columns.Count - 1) * ParentDataGrid.ColumnSpacing.Value.Pixels)) / columns.Count; foreach (var column in columns) { column.Width.DirectValue = ElementSize.FromPixels(columnWidth); } } else { // adjust width of columns based on headers float columnSpacing = ((columns.Count - 1) * ParentDataGrid.ColumnSpacing.Value.Pixels) / columns.Count; List <Column> columnsToFill = new List <Column>(); float totalWidth = 0; for (int i = 0; i < columns.Count; ++i) { var defWidth = columnHeaders[i].Width.Value; if (!columnHeaders[i].Width.IsSet || defWidth.Fill == true) { columnsToFill.Add(columns[i]); continue; } else if (defWidth.Unit == ElementSizeUnit.Percents) { columns[i].Width.DirectValue = new ElementSize((defWidth.Percent * ActualWidth) - columnSpacing, ElementSizeUnit.Pixels); } else { columns[i].Width.DirectValue = new ElementSize(defWidth.Pixels - columnSpacing, ElementSizeUnit.Pixels); } totalWidth += columns[i].Width.Value.Pixels; } // adjust width of fill columns if (columnsToFill.Count > 0) { float columnWidth = Math.Max(columnSpacing, (ActualWidth - totalWidth) / columnsToFill.Count); foreach (var column in columnsToFill) { column.Width.DirectValue = new ElementSize(columnWidth - columnSpacing, ElementSizeUnit.Pixels); } } } // adjust column offsets and settings float offset = 0; foreach (var column in columns) { if (!column.TextAlignment.IsSet) { column.TextAlignment.Value = ParentDataGrid.ColumnTextAlignment.Value; } if (!column.TextMargin.IsSet) { column.TextMargin.Value = ParentDataGrid.ColumnTextMargin.Value; } column.OffsetFromParent.DirectValue = new ElementMargin(offset, 0, 0, 0); offset += (column.Width.Value.Pixels + ParentDataGrid.ColumnSpacing.Value.Pixels); column.QueueChangeHandler("LayoutChanged"); } base.LayoutChanged(); }