public static void ApplyFloatOrKeyword(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <FloatOrKeyword> property) { var handle = handles[0]; FloatOrKeyword fk; if (handle.valueType == StyleValueType.Keyword) { fk = new FloatOrKeyword((StyleValueKeyword)handle.valueIndex); } else { fk = new FloatOrKeyword(sheet.ReadFloat(handle)); } Apply(fk, specificity, ref property); }
public static bool CompileFlexShorthand(StyleSheet sheet, StyleValueHandle[] handles, out float grow, out float shrink, out FloatOrKeyword basis) { grow = 0f; shrink = 0f; basis = new FloatOrKeyword(StyleValueKeyword.Auto); bool valid = false; if (handles.Length == 1 && handles[0].valueType == StyleValueType.Keyword && handles[0].valueIndex == (int)StyleValueKeyword.Unset) { valid = true; grow = 0f; shrink = 1f; basis = new FloatOrKeyword(StyleValueKeyword.Auto); } else if (handles.Length == 1 && handles[0].valueType == StyleValueType.Keyword && handles[0].valueIndex == (int)StyleValueKeyword.None) { valid = true; grow = 0f; shrink = 0f; basis = new FloatOrKeyword(StyleValueKeyword.Auto); } else if (handles.Length <= 3 && handles[0].valueType == StyleValueType.Keyword && handles[0].valueIndex == (int)StyleValueKeyword.Auto) { valid = true; basis = new FloatOrKeyword(StyleValueKeyword.Auto); grow = 1f; shrink = 1f; if (handles.Length > 1) { grow = sheet.ReadFloat(handles[1]); if (handles.Length > 2) { shrink = sheet.ReadFloat(handles[2]); } } } else if (handles.Length <= 3 && handles[0].valueType == StyleValueType.Float) { valid = true; // TODO: when support for units is implemented, basis must have units, grow and shrink are unitless. // This will remove ambiguities. For now we assume (when all values are number) // // flex: grow (could be flex: basis) // flex: grow shrink (could be flex: basis grow; or flex: grow basis) // flex: grow shrink basis (could be flex: basis grow shrink) grow = sheet.ReadFloat(handles[0]); shrink = 1f; basis = new FloatOrKeyword(0f); if (handles.Length > 1) { if (handles[1].valueType == StyleValueType.Float) { shrink = sheet.ReadFloat(handles[1]); if (handles.Length > 2) { if (handles[2].valueType == StyleValueType.Keyword && handles[2].valueIndex == (int)StyleValueKeyword.Auto) { basis = new FloatOrKeyword(StyleValueKeyword.Auto); } else if (handles[2].valueType == StyleValueType.Float) { basis = new FloatOrKeyword(sheet.ReadFloat(handles[2])); } } } else if (handles[1].valueType == StyleValueType.Keyword && handles[1].valueIndex == (int)StyleValueKeyword.Auto) { basis = new FloatOrKeyword(StyleValueKeyword.Auto); } } } return(valid); }