void UpdateAsNullText(IColumnState column) { UpdateAsText("<color=#88444499>NULL</color>", false); SetInputAvailable(!column.CurrentlyReadOnly && IsStringInputType(column.Info.ValueType)); }
/// <summary> /// Expecting value to be non-null /// </summary> void UpdateViews(object value, IColumnState column) { bool?textInputAvailable = null; try { bool canChangeValue = !column.CurrentlyReadOnly; bool updatedSuccessfully; switch (column.Info.ValueType) { case TableValueType.RAW: UpdateAsText("<color=#22552266>" + value.GetType().Name + "</color> " + value.ToString(), false); textInputAvailable = false; break; case TableValueType.STRING: updatedSuccessfully = UpdateAsText((string)value, canChangeValue); textInputAvailable = canChangeValue && updatedSuccessfully; break; case TableValueType.INT: UpdateIntOrLong(((int)value).ToString(), canChangeValue); break; case TableValueType.LONG_INT: UpdateIntOrLong(((long)value).ToString(), canChangeValue); break; case TableValueType.FLOAT: float fl = (float)value; UpdateFloatOrDouble(fl.ToString(OSAConst.FLOAT_TO_STRING_CONVERSION_SPECIFIER_PRESERVE_PRECISION), canChangeValue); break; case TableValueType.DOUBLE: double db = (double)value; //string text = val.ToString(); // Spent like 2 hours to find out C# double doesn't always convert successfully to string by default without losing precision, smh. // https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#RFormatString // Furthermore, they have a useless R specifier that is more annoying because it doesn't always work. Probably there for historical reasons. // The odd "G17" should be used for making sure a string that doesn't lose precision is output UpdateFloatOrDouble(db.ToString(OSAConst.DOUBLE_TO_STRING_CONVERSION_SPECIFIER_PRESERVE_PRECISION), canChangeValue); break; case TableValueType.ENUMERATION: string textToSet = null; if (column.Info.EnumValueType != null && column.Info.EnumValueType.IsEnum) { try { textToSet = Enum.GetName(column.Info.EnumValueType, value); } catch { } } bool validEnum = !string.IsNullOrEmpty(textToSet); if (!validEnum) { textToSet = value.ToString(); } updatedSuccessfully = UpdateAsText(textToSet, false /*enum text is changed by other means, not direct text editing*/); textInputAvailable = false; break; case TableValueType.BOOL: updatedSuccessfully = UpdateAsCheckbox((bool)value, canChangeValue); break; case TableValueType.TEXTURE: UpdateAsImage((Texture)value); break; } if (textInputAvailable != null) { SetInputAvailable(textInputAvailable.Value); } } catch (Exception e) { Debug.LogError("Exception pre-details: " + column.Info.ValueType + ", value " + (value == null ? "NULL" : value)); throw e; } }