using System; using System.Linq.Expressions; namespace RosettaUI { public static partial class UI { public static Element Field(Expression> targetExpression, in FieldOption? option = null) { return Field(ExpressionUtility.CreateLabelString(targetExpression), targetExpression, option); } public static Element Field(LabelElement label, Expression> targetExpression, in FieldOption? option = null) { var binder = UIInternalUtility.CreateBinder(targetExpression); return Field(label, binder, option); } public static Element Field(Expression> targetExpression, Action writeValue, in FieldOption? option = null) => Field(ExpressionUtility.CreateLabelString(targetExpression), targetExpression.Compile(), writeValue, option); public static Element Field(LabelElement label, Func readValue, Action writeValue, in FieldOption? option = null) => Field(label, Binder.Create(readValue, writeValue), option); public static Element Field(LabelElement label, IBinder binder, in FieldOption? option = null) { var element = BinderToElement.CreateFieldElement(label, binder, option ?? FieldOption.Default); if (element != null) UIInternalUtility.SetInteractableWithBinder(element, binder); return element; } public static Element FieldReadOnly(Expression> targetExpression) => FieldReadOnly( ExpressionUtility.CreateLabelString(targetExpression), ExpressionUtility.CreateReadFunc(targetExpression )); public static Element FieldReadOnly(LabelElement label, Func readValue) => Field(label, readValue, null); } }