public static void StyleMargin(this VisualElement ui, StyleLength left, StyleLength right, StyleLength top, StyleLength bottom) { ui.style.marginLeft = left; ui.style.marginRight = right; ui.style.marginTop = top; ui.style.marginBottom = bottom; }
public static void StyleBorderRadius(this VisualElement ui, StyleLength topLeft, StyleLength topRight, StyleLength bottomLeft, StyleLength bottomRight) { ui.style.borderTopLeftRadius = topLeft; ui.style.borderTopRightRadius = topRight; ui.style.borderBottomLeftRadius = bottomLeft; ui.style.borderBottomRightRadius = bottomRight; }
private static void CompileBoxAreaNoKeyword(StylePropertyReader reader, out StyleLength top, out StyleLength right, out StyleLength bottom, out StyleLength left) { ShorthandApplicator.CompileBoxArea(reader, out top, out right, out bottom, out left); bool flag = top.keyword > StyleKeyword.Undefined; if (flag) { top.value = 0f; } bool flag2 = right.keyword > StyleKeyword.Undefined; if (flag2) { right.value = 0f; } bool flag3 = bottom.keyword > StyleKeyword.Undefined; if (flag3) { bottom.value = 0f; } bool flag4 = left.keyword > StyleKeyword.Undefined; if (flag4) { left.value = 0f; } }
public VisualElementStylesData(bool isShared) { this.isShared = isShared; // Initialize non trivial properties left = StyleSheetCache.GetInitialValue(StylePropertyID.PositionLeft).ToStyleLength(); top = StyleSheetCache.GetInitialValue(StylePropertyID.PositionTop).ToStyleLength(); right = StyleSheetCache.GetInitialValue(StylePropertyID.PositionRight).ToStyleLength(); bottom = StyleSheetCache.GetInitialValue(StylePropertyID.PositionBottom).ToStyleLength(); width = StyleSheetCache.GetInitialValue(StylePropertyID.Width).ToStyleLength(); height = StyleSheetCache.GetInitialValue(StylePropertyID.Height).ToStyleLength(); minWidth = StyleSheetCache.GetInitialValue(StylePropertyID.MinWidth).ToStyleLength(); minHeight = StyleSheetCache.GetInitialValue(StylePropertyID.MinHeight).ToStyleLength(); maxWidth = StyleSheetCache.GetInitialValue(StylePropertyID.MaxWidth).ToStyleLength(); maxHeight = StyleSheetCache.GetInitialValue(StylePropertyID.MaxHeight).ToStyleLength(); alignSelf = (int)StyleSheetCache.GetInitialValue(StylePropertyID.AlignSelf).number; alignItems = (int)StyleSheetCache.GetInitialValue(StylePropertyID.AlignItems).number; alignContent = (int)StyleSheetCache.GetInitialValue(StylePropertyID.AlignContent).number; flexGrow = StyleSheetCache.GetInitialValue(StylePropertyID.FlexGrow).ToStyleFloat(); flexShrink = StyleSheetCache.GetInitialValue(StylePropertyID.FlexShrink).ToStyleFloat(); flexBasis = StyleSheetCache.GetInitialValue(StylePropertyID.FlexBasis).ToStyleLength(); color = StyleSheetCache.GetInitialValue(StylePropertyID.Color).color; borderLeftColor = StyleSheetCache.GetInitialValue(StylePropertyID.BorderLeftColor).color; borderTopColor = StyleSheetCache.GetInitialValue(StylePropertyID.BorderTopColor).color; borderRightColor = StyleSheetCache.GetInitialValue(StylePropertyID.BorderRightColor).color; borderBottomColor = StyleSheetCache.GetInitialValue(StylePropertyID.BorderBottomColor).color; opacity = StyleSheetCache.GetInitialValue(StylePropertyID.Opacity).number; unityBackgroundImageTintColor = StyleSheetCache.GetInitialValue(StylePropertyID.BackgroundImageTintColor).color; }
private static void CompileBoxArea(StylePropertyReader reader, out StyleLength top, out StyleLength right, out StyleLength bottom, out StyleLength left) { top = 0f; right = 0f; bottom = 0f; left = 0f; switch (reader.valueCount) { case 0: break; case 1: top = (right = (bottom = (left = reader.ReadStyleLength(0)))); break; case 2: top = (bottom = reader.ReadStyleLength(0)); left = (right = reader.ReadStyleLength(1)); break; case 3: top = reader.ReadStyleLength(0); left = (right = reader.ReadStyleLength(1)); bottom = reader.ReadStyleLength(2); break; default: top = reader.ReadStyleLength(0); right = reader.ReadStyleLength(1); bottom = reader.ReadStyleLength(2); left = reader.ReadStyleLength(3); break; } }
public static void StylePadding(this VisualElement ui, StyleLength left, StyleLength right, StyleLength top, StyleLength bottom) { ui.style.paddingLeft = left; ui.style.paddingRight = right; ui.style.paddingTop = top; ui.style.paddingBottom = bottom; }
public void TestLengthPercentParse() { StyleLength length = UIParser.ToStyleLength("100%"); Assert.AreEqual(length.keyword, StyleKeyword.Undefined); Assert.AreEqual(length.value.unit, LengthUnit.Percent); Assert.AreEqual(length.value.value, 100.0f); }
public static VisualElement SetWidth(this VisualElement self, StyleKeyword keyword) { StyleLength width = new StyleLength(keyword); self.style.width = width; return(self); }
public static VisualElement SetHeight(this VisualElement self, StyleKeyword keyword) { StyleLength height = new StyleLength(keyword); self.style.height = height; return(self); }
public CheckBox(string name) { this.name = name; isChecked = false; disabled = false; width = new StyleLength(100F, LengthUnits.Percentage); script = new ScriptProperty(); cssClass = string.Empty; }
public DateTimePicker(Core core, string name) { this.core = core; this.name = name; disabled = false; showTime = false; showSeconds = false; width = new StyleLength(100F, LengthUnits.Percentage); }
public Image(string name, string uri) { this.name = name; this.uri = uri; this.width = new StyleLength(); this.height = new StyleLength(); this.script = new ScriptProperty(); this.styleClass = string.Empty; }
/// <summary> /// Select box constructor. /// </summary> /// <param name="name">Select box name</param> public SelectBox(string name) { this.name = name; items = new List<SelectBoxItem>(); itemKeys = new Dictionary<string, SelectBoxItem>(); visible = true; width = new StyleLength(); script = new ScriptProperty(); }
private void ApplyUnsetStyleValue(StylePropertyReader reader, InheritedStylesData inheritedStylesData) { if (inheritedStylesData == null) { ApplyInitialStyleValue(reader); } var specificity = reader.specificity; switch (reader.propertyID) { case StylePropertyID.Color: color = inheritedStylesData.color; color.specificity = specificity; break; case StylePropertyID.Font: unityFont = inheritedStylesData.font; unityFont.specificity = specificity; break; case StylePropertyID.FontSize: fontSize = inheritedStylesData.fontSize; fontSize.specificity = specificity; break; case StylePropertyID.FontStyleAndWeight: unityFontStyleAndWeight = inheritedStylesData.unityFontStyle; unityFontStyleAndWeight.specificity = specificity; break; case StylePropertyID.UnityTextAlign: unityTextAlign = inheritedStylesData.unityTextAlign; unityTextAlign.specificity = specificity; break; case StylePropertyID.Visibility: visibility = inheritedStylesData.visibility; visibility.specificity = specificity; break; case StylePropertyID.WhiteSpace: whiteSpace = inheritedStylesData.whiteSpace; whiteSpace.specificity = specificity; break; case StylePropertyID.Custom: RemoveCustomStyleProperty(reader.property.name); break; default: ApplyInitialStyleValue(reader.propertyID, specificity); break; } }
public TextBox(string name) { this.name = name; disabled = false; visible = true; maxLength = -1; lines = 1; width = new StyleLength(100F, LengthUnits.Percentage); script = new ScriptProperty(); type = InputType.Text; }
public UserSelectBox(Core core, string name, List<long> userIds) { this.core = core; this.name = name; this.userIds = userIds; disabled = false; visible = true; width = new StyleLength(100F, LengthUnits.Percentage); script = new ScriptProperty(); }
public TagSelectBox(Core core, string name) { this.core = core; this.name = name; disabled = false; visible = true; tagIds = new List<long>(); width = new StyleLength(100F, LengthUnits.Percentage); script = new ScriptProperty(); }
public void CopyFrom(InheritedStylesData other) { if (other != null) { color = other.color; font = other.font; fontSize = other.fontSize; visibility = other.visibility; whiteSpace = other.whiteSpace; unityFontStyle = other.unityFontStyle; unityTextAlign = other.unityTextAlign; } }
public PermissionGroupSelectBox(Core core, string name, ItemKey permissibleItem, List<PrimitivePermissionGroup> itemKeys) { this.core = core; this.name = name; this.permissibleItem = permissibleItem; this.itemKeys = itemKeys; disabled = false; visible = true; width = new StyleLength(100F, LengthUnits.Percentage); script = new ScriptProperty(); }
private static void CompileBoxArea(StylePropertyReader reader, out StyleLength top, out StyleLength right, out StyleLength bottom, out StyleLength left) { top = 0f; right = 0f; bottom = 0f; left = 0f; var valueCount = reader.valueCount; switch (valueCount) { // apply to all four sides case 0: break; case 1: { top = right = bottom = left = reader.ReadStyleLength(0); break; } // vertical | horizontal case 2: { top = bottom = reader.ReadStyleLength(0); left = right = reader.ReadStyleLength(1); break; } // top | horizontal | bottom case 3: { top = reader.ReadStyleLength(0); left = right = reader.ReadStyleLength(1); bottom = reader.ReadStyleLength(2); break; } // top | right | bottom | left default: { top = reader.ReadStyleLength(0); right = reader.ReadStyleLength(1); bottom = reader.ReadStyleLength(2); left = reader.ReadStyleLength(3); break; } } }
public static StyleLength ReadStyleLength(this StyleSheet sheet, StyleValueHandle handle, int specificity) { var keyword = TryReadKeyword(handle); StyleLength styleLength = new StyleLength(keyword) { specificity = specificity }; if (keyword == StyleKeyword.Undefined) { var dimension = sheet.ReadDimension(handle); styleLength.value = dimension.ToLength(); } return(styleLength); }
public StyleLength ReadStyleLength(int index) { StylePropertyValue stylePropertyValue = this.m_Values[this.m_CurrentValueIndex + index]; bool flag = stylePropertyValue.handle.valueType == StyleValueType.Keyword; StyleLength result; if (flag) { StyleValueKeyword valueIndex = (StyleValueKeyword)stylePropertyValue.handle.valueIndex; result = new StyleLength(valueIndex.ToStyleKeyword()); } else { result = new StyleLength(stylePropertyValue.sheet.ReadDimension(stylePropertyValue.handle).ToLength()); } return(result); }
public StyleLength ReadStyleLength(int index) { var value = m_Values[index]; var keyword = TryReadKeyword(value.handle); StyleLength styleLength = new StyleLength(keyword) { specificity = specificity }; if (keyword == StyleKeyword.Undefined) { var dimension = value.sheet.ReadDimension(value.handle); styleLength.value = dimension.ToLength(); } return(styleLength); }
public static YogaValue StyleLengthToYogaValue(StyleLength value) { if (value.keyword == StyleKeyword.Auto) { return(YogaValue.Auto()); } if (value.keyword == StyleKeyword.Null || value.keyword == StyleKeyword.None || value.keyword == StyleKeyword.Initial) { return(YogaValue.Undefined()); } if (value.value.unit == LengthUnit.Percent) { return(YogaValue.Percent(value.value.value)); } if (value.value.unit == LengthUnit.Pixel) { return(YogaValue.Point(value.value.value)); } return(YogaValue.Undefined()); }
private static void CompileBoxAreaNoKeyword(StylePropertyReader reader, out StyleLength top, out StyleLength right, out StyleLength bottom, out StyleLength left) { CompileBoxArea(reader, out top, out right, out bottom, out left); if (top.keyword != StyleKeyword.Undefined) { top.value = 0f; } if (right.keyword != StyleKeyword.Undefined) { right.value = 0f; } if (bottom.keyword != StyleKeyword.Undefined) { bottom.value = 0f; } if (left.keyword != StyleKeyword.Undefined) { left.value = 0f; } }
public override void ApplyInputDeviceDelta(Vector3 delta, DeltaSpeed speed, StyleLength startValue) { if (startValue.keyword != StyleKeyword.Undefined) { startValue = new StyleLength(); } double sensitivity = NumericFieldDraggerUtility.CalculateIntDragSensitivity((long)startValue.value.value); float acceleration = NumericFieldDraggerUtility.Acceleration(speed == DeltaSpeed.Fast, speed == DeltaSpeed.Slow); long v = (long)StringToValue(text).value.value; v += (long)Math.Round(NumericFieldDraggerUtility.NiceDelta(delta, acceleration) * sensitivity); if (parentLengthField.isDelayed) { text = ValueToString(MathUtils.ClampToInt(v)); } else { Length l = new Length(MathUtils.ClampToInt(v), parentLengthField.value.value.unit); parentLengthField.value = new StyleLength(l); } }
public static StyleLength ReadStyleLength(this StyleSheet sheet, StyleValueHandle handle, int specificity) { var keyword = TryReadKeyword(handle); StyleLength styleLength = new StyleLength(keyword) { specificity = specificity }; if (keyword == StyleKeyword.Undefined) { if (handle.valueType == StyleValueType.Float) { styleLength.value = sheet.ReadFloat(handle); } else { Debug.LogError($"Unexpected Length value of type {handle.valueType.ToString()}"); } } return(styleLength); }
internal void ApplyStyleProperty(IStylePropertyReader reader) { switch (reader.propertyID) { case StylePropertyID.AlignContent: StyleSheetApplicator.ApplyAlign(reader, ref alignContent); break; case StylePropertyID.AlignItems: StyleSheetApplicator.ApplyAlign(reader, ref alignItems); break; case StylePropertyID.AlignSelf: StyleSheetApplicator.ApplyAlign(reader, ref alignSelf); break; case StylePropertyID.BackgroundImage: backgroundImage = reader.ReadStyleBackground(0); break; case StylePropertyID.FlexBasis: flexBasis = reader.ReadStyleLength(0); break; case StylePropertyID.FlexGrow: flexGrow = reader.ReadStyleFloat(0); break; case StylePropertyID.FlexShrink: flexShrink = reader.ReadStyleFloat(0); break; case StylePropertyID.Font: unityFont = reader.ReadStyleFont(0); break; case StylePropertyID.FontSize: fontSize = reader.ReadStyleLength(0); break; case StylePropertyID.FontStyleAndWeight: unityFontStyleAndWeight = reader.ReadStyleEnum <FontStyle>(0); break; case StylePropertyID.FlexDirection: flexDirection = reader.ReadStyleEnum <FlexDirection>(0); break; case StylePropertyID.FlexWrap: flexWrap = reader.ReadStyleEnum <Wrap>(0); break; case StylePropertyID.Height: height = reader.ReadStyleLength(0); break; case StylePropertyID.JustifyContent: justifyContent = reader.ReadStyleEnum <Justify>(0); break; case StylePropertyID.MarginLeft: marginLeft = reader.ReadStyleLength(0); break; case StylePropertyID.MarginTop: marginTop = reader.ReadStyleLength(0); break; case StylePropertyID.MarginRight: marginRight = reader.ReadStyleLength(0); break; case StylePropertyID.MarginBottom: marginBottom = reader.ReadStyleLength(0); break; case StylePropertyID.MaxHeight: maxHeight = reader.ReadStyleLength(0); break; case StylePropertyID.MaxWidth: maxWidth = reader.ReadStyleLength(0); break; case StylePropertyID.MinHeight: minHeight = reader.ReadStyleLength(0); break; case StylePropertyID.MinWidth: minWidth = reader.ReadStyleLength(0); break; case StylePropertyID.Overflow: overflow = reader.ReadStyleEnum <OverflowInternal>(0); break; case StylePropertyID.OverflowClipBox: unityOverflowClipBox = reader.ReadStyleEnum <OverflowClipBox>(0); break; case StylePropertyID.PaddingLeft: paddingLeft = reader.ReadStyleLength(0); break; case StylePropertyID.PaddingTop: paddingTop = reader.ReadStyleLength(0); break; case StylePropertyID.PaddingRight: paddingRight = reader.ReadStyleLength(0); break; case StylePropertyID.PaddingBottom: paddingBottom = reader.ReadStyleLength(0); break; case StylePropertyID.Position: position = reader.ReadStyleEnum <Position>(0); break; case StylePropertyID.PositionTop: top = reader.ReadStyleLength(0); break; case StylePropertyID.PositionBottom: bottom = reader.ReadStyleLength(0); break; case StylePropertyID.PositionLeft: left = reader.ReadStyleLength(0); break; case StylePropertyID.PositionRight: right = reader.ReadStyleLength(0); break; case StylePropertyID.UnityTextAlign: unityTextAlign = reader.ReadStyleEnum <TextAnchor>(0); break; case StylePropertyID.Color: color = reader.ReadStyleColor(0); break; case StylePropertyID.Width: width = reader.ReadStyleLength(0); break; case StylePropertyID.WhiteSpace: whiteSpace = reader.ReadStyleEnum <WhiteSpace>(0); break; case StylePropertyID.BackgroundColor: backgroundColor = reader.ReadStyleColor(0); break; case StylePropertyID.BackgroundScaleMode: unityBackgroundScaleMode = reader.ReadStyleEnum <ScaleMode>(0); break; case StylePropertyID.BackgroundImageTintColor: unityBackgroundImageTintColor = reader.ReadStyleColor(0); break; case StylePropertyID.BorderLeftColor: borderLeftColor = reader.ReadStyleColor(0); break; case StylePropertyID.BorderTopColor: borderTopColor = reader.ReadStyleColor(0); break; case StylePropertyID.BorderRightColor: borderRightColor = reader.ReadStyleColor(0); break; case StylePropertyID.BorderBottomColor: borderBottomColor = reader.ReadStyleColor(0); break; case StylePropertyID.BorderLeftWidth: borderLeftWidth = reader.ReadStyleFloat(0); break; case StylePropertyID.BorderTopWidth: borderTopWidth = reader.ReadStyleFloat(0); break; case StylePropertyID.BorderRightWidth: borderRightWidth = reader.ReadStyleFloat(0); break; case StylePropertyID.BorderBottomWidth: borderBottomWidth = reader.ReadStyleFloat(0); break; case StylePropertyID.BorderTopLeftRadius: borderTopLeftRadius = reader.ReadStyleLength(0); break; case StylePropertyID.BorderTopRightRadius: borderTopRightRadius = reader.ReadStyleLength(0); break; case StylePropertyID.BorderBottomRightRadius: borderBottomRightRadius = reader.ReadStyleLength(0); break; case StylePropertyID.BorderBottomLeftRadius: borderBottomLeftRadius = reader.ReadStyleLength(0); break; case StylePropertyID.Cursor: cursor = reader.ReadStyleCursor(0); break; case StylePropertyID.SliceLeft: unitySliceLeft = reader.ReadStyleInt(0); break; case StylePropertyID.SliceTop: unitySliceTop = reader.ReadStyleInt(0); break; case StylePropertyID.SliceRight: unitySliceRight = reader.ReadStyleInt(0); break; case StylePropertyID.SliceBottom: unitySliceBottom = reader.ReadStyleInt(0); break; case StylePropertyID.Opacity: opacity = reader.ReadStyleFloat(0); break; case StylePropertyID.Visibility: visibility = reader.ReadStyleEnum <Visibility>(0); break; case StylePropertyID.Display: StyleSheetApplicator.ApplyDisplay(reader, ref display); break; default: throw new ArgumentException(string.Format("Non exhaustive switch statement (value={0})", reader.propertyID)); } }
/// <summary> /// UI Element Browser Bar /// </summary> void BrowserBar(VisualElement root) { #region Browser Bar //Browser Bar Toolbar toolbar = new Toolbar(); toolbar.style.justifyContent = Justify.SpaceBetween; root.Add(toolbar); // Back Button backButton = AddToolbarButton(EditorGUIUtility.isProSkin ? GetTexture("Back") : GetTexture("Back_Alt"), Back, 5); backButton.tooltip = "Back"; backButton.SetEnabled(false); toolbar.Add(backButton); // Forward Button forwardButton = AddToolbarButton(EditorGUIUtility.isProSkin ? GetTexture("Forward") : GetTexture("Forward_Alt"), Forward, 0); forwardButton.tooltip = "Forward"; forwardButton.SetEnabled(false); toolbar.Add(forwardButton); homeButton = AddToolbarButton(EditorGUIUtility.isProSkin ? GetTexture("Home") : GetTexture("Home_Alt"), Home, 2); homeButton.tooltip = "Home"; toolbar.Add(homeButton); ToolbarButton AddToolbarButton(Texture texture, Action action, float marginLeft) { ToolbarButton toolbarButton = new ToolbarButton(action) { style = { marginLeft = marginLeft, width = 20, borderLeftWidth = marginLeft == 0 ? 0 : 1, borderColor = new Color(0.57f, 0.57f, 0.57f), borderTopLeftRadius = 2, alignItems = Align.Center, paddingBottom = 0, paddingLeft = 0, paddingRight = 0, } }; toolbarButton.Add(new Image { image = texture, style = { marginTop = 4, height = 10, width = 10 } }); return(toolbarButton); } // Search Bar ToolbarSearchField toolbarSearchField = new ToolbarSearchField(); toolbarSearchField.SetValueWithoutNotify(searchString); //ToolbarSearchField's buttons have broken hover and action pseudo-states so we have to fix that StyleSheet fixSheet = LoadAssetOfType <StyleSheet>("InbuiltFixStyles", SearchFilter.Packages); toolbarSearchField.styleSheets.Add(fixSheet); toolbarSearchField.style.flexGrow = 1; toolbarSearchField.RegisterCallback <ChangeEvent <string> >(evt => { searchString = evt.newValue; DoSearch(); }); TextField textField = toolbarSearchField.Q <TextField>(); textField.RegisterCallback <FocusEvent>(evt => { if (searchRoot.visible || string.IsNullOrEmpty(searchString)) { return; } //If there's a search string and we're in the search box we should enable the search container. searchRoot.visible = true; //If there isn't any search (ie. the previously cached search was never built, perform the search) if (searchStringsCache.Count == 0) { DoSearch(); } }); //The internal text field has a fixed width so we have to remove that StyleLength width = textField.style.width; width.keyword = StyleKeyword.Auto; textField.style.width = width; //The cancel button is improperly aligned so we have to fix that Button cancelButton = toolbarSearchField.Q <Button>("unity-cancel"); cancelButton.style.width = 15; //The search button doesn't expand automatically, so we have to fix that Button searchButton = toolbarSearchField.Q <Button>("unity-search"); searchButton.style.flexGrow = 1; //Set the Search Field to be 1/2 width toolbar.RegisterCallback <GeometryChangedEvent>(evt => toolbarSearchField.style.marginLeft = evt.newRect.width / 2f - 70); toolbar.Add(toolbarSearchField); #endregion }
public static void StyleMarginBottom(this VisualElement ui, StyleLength value) => ui.style.marginBottom = value;
public static void StyleBorderRadius(this VisualElement ui, StyleLength radius) => ui.StyleBorderRadius(radius, radius, radius, radius);
public static void StylePaddingBottom(this VisualElement ui, StyleLength value) => ui.style.paddingBottom = value;
public static void StylePaddingRight(this VisualElement ui, StyleLength value) => ui.style.paddingRight = value;
public static void StylePadding(this VisualElement ui, StyleLength value) => ui.StylePadding(value, value, value, value);
bool IsComputedStyleNoneOrAuto(StyleLength styleLength) { return(styleLength == StyleKeyword.None || styleLength == StyleKeyword.Auto); }
public static void StyleFlexBasisAsPercent(this VisualElement ui, StyleLength basis) => ui.style.flexBasis = basis;
public static void StyleMarginRight(this VisualElement ui, StyleLength value) => ui.style.marginRight = value;
public static void StyleMargin(this VisualElement ui, StyleLength value) => ui.StyleMargin(value, value, value, value);