private GUILayoutOption CreateRawOption(GUILayoutOptionType type, int index) { var option = CreateRawOption(type); rawOptionIndices[GUILayoutOptionTypeEnum.IndexOfBit(type)] = index; return(option); }
private static GUILayoutOption CreateRawOption(GUILayoutOptionType type, float value = default(float)) { switch (type) { case GUILayoutOptionType.FixedWidth: return(GUILayout.Width(value)); case GUILayoutOptionType.FixedHeight: return(GUILayout.Height(value)); case GUILayoutOptionType.MinWidth: return(GUILayout.MinWidth(value)); case GUILayoutOptionType.MaxWidth: return(GUILayout.MaxWidth(value)); case GUILayoutOptionType.MinHeight: return(GUILayout.MinHeight(value)); case GUILayoutOptionType.MaxHeight: return(GUILayout.MaxHeight(value)); case GUILayoutOptionType.StretchWidth: return(GUILayout.ExpandWidth(value > 0)); case GUILayoutOptionType.StretchHeight: return(GUILayout.ExpandHeight(value > 0)); default: throw new ArgumentOutOfRangeException("type", type, null); } }
public Instance(GUILayoutOptionType types) { Types = types; var typeValues = GUILayoutOptionTypeEnum.ValuesOf(Types); rawOptionIndices = new int[typeValues.Select(GUILayoutOptionTypeEnum.IndexOfBit).Max() + 1]; rawOptions = typeValues.Select(CreateRawOption).ToArray(); }
public static int IndexOfBit(GUILayoutOptionType type) { var typeValue = (int)type; if (typeValue == 0 || IsMixed(type)) { throw new ArgumentException("Bit value of type expected", "type"); } return(Mathf.RoundToInt(Mathf.Log(typeValue, 2))); }
/// <summary> /// Get cached an array of <see cref="GUILayoutOption" /> that represents specified option types. /// </summary> /// <remarks> /// Each time you get the array from certain set of option types is same instance. /// Parameters with different order but same contents result in same array instance. /// </remarks> public static Instance Get(GUILayoutOptionType types) { var instance = instances[(int)types]; if (instance == null) { instance = new Instance(types); instances[(int)types] = instance; } return(instance); }
private int GetRawOptionIndex(GUILayoutOptionType type) { int typeIndex = GUILayoutOptionTypeEnum.IndexOfBit(type); int rawIndex = rawOptionIndices[typeIndex]; if (rawIndex == Index.Invalid) { throw new ArgumentException("The current instance do not contains specified option type", "type"); } return(rawIndex); }
public static IEnumerable <GUILayoutOptionType> ValuesOf(GUILayoutOptionType types, bool includeMixed = false) { for (int i = 0; i < ValueCount; ++i) { var value = values[i]; if ((types & value) != value) { continue; } if (includeMixed) { yield return(value); } else if (!IsMixed(value)) { yield return(value); } } }
public Instance SetValue(GUILayoutOptionType type, float value) { GetRawOption(type).SetValue(value); return(this); }
private GUILayoutOption GetRawOption(GUILayoutOptionType type) { return(rawOptions[GetRawOptionIndex(type)]); }
internal void SetValue(GUILayoutOptionType type, bool value) { this.GUILayoutOptionType = type; this.value = value ? 1 : 0; }
internal void SetValue(GUILayoutOptionType type, float value) { this.GUILayoutOptionType = type; this.value = value; }
public virtual void ApplyOptions(GUILayoutOption[] options) { if (options != null) { for (int i = 0; i < options.Length; i++) { GUILayoutOption gUILayoutOption = options[i]; GUILayoutOptionType type = GUILayoutOptionHelper.GetType(gUILayoutOption); switch (type) { case GUILayoutOptionType.fixedWidth: minWidth = (maxWidth = GUILayoutOptionHelper.GetValue(gUILayoutOption)); stretchWidth = 0; break; case GUILayoutOptionType.fixedHeight: minHeight = (maxHeight = GUILayoutOptionHelper.GetValue(gUILayoutOption)); stretchHeight = 0; break; case GUILayoutOptionType.minWidth: minWidth = GUILayoutOptionHelper.GetValue(gUILayoutOption); if (maxWidth < minWidth) { maxWidth = minWidth; } break; case GUILayoutOptionType.maxWidth: maxWidth = GUILayoutOptionHelper.GetValue(gUILayoutOption); if (minWidth > maxWidth) { minWidth = maxWidth; } stretchWidth = 0; break; case GUILayoutOptionType.minHeight: minHeight = GUILayoutOptionHelper.GetValue(gUILayoutOption); if (maxHeight < minHeight) { maxHeight = minHeight; } break; case GUILayoutOptionType.maxHeight: maxHeight = GUILayoutOptionHelper.GetValue(gUILayoutOption); if (minHeight > maxHeight) { minHeight = maxHeight; } stretchHeight = 0; break; case GUILayoutOptionType.stretchWidth: stretchWidth = (int)GUILayoutOptionHelper.GetValue(gUILayoutOption); break; case GUILayoutOptionType.stretchHeight: stretchHeight = (int)GUILayoutOptionHelper.GetValue(gUILayoutOption); break; } } if (maxWidth != 0f && maxWidth < minWidth) { maxWidth = minWidth; } if (maxHeight != 0f && maxHeight < minHeight) { maxHeight = minHeight; } } }
public static int CountOf(GUILayoutOptionType type, bool includeMixed = false) { return(ValuesOf(type, includeMixed).Count()); }
public static bool IsMixed(GUILayoutOptionType type) { return(!MathEx.IsPowerOfTwo((int)type)); }