UTKProperyWIndow 수정 중
This commit is contained in:
@@ -10,7 +10,7 @@ namespace UVC.UIToolkit
|
||||
public class UTKStringPropertyItem : UTKPropertyItemBase<string>
|
||||
{
|
||||
#region Fields
|
||||
private TextField? _textField;
|
||||
private UTKInputField? _inputField;
|
||||
private bool _isMultiline;
|
||||
private int _maxLength;
|
||||
#endregion
|
||||
@@ -25,9 +25,9 @@ namespace UVC.UIToolkit
|
||||
set
|
||||
{
|
||||
_isMultiline = value;
|
||||
if (_textField != null)
|
||||
if (_inputField != null)
|
||||
{
|
||||
_textField.multiline = value;
|
||||
_inputField.multiline = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,9 +39,9 @@ namespace UVC.UIToolkit
|
||||
set
|
||||
{
|
||||
_maxLength = value;
|
||||
if (_textField != null)
|
||||
if (_inputField != null)
|
||||
{
|
||||
_textField.maxLength = value;
|
||||
_inputField.maxLength = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,28 @@ namespace UVC.UIToolkit
|
||||
|
||||
#region Override Methods
|
||||
public override VisualElement CreateUI()
|
||||
{
|
||||
var container = CreateUIFromUxml("UTKStringPropertyItem");
|
||||
if (container == null)
|
||||
{
|
||||
return CreateUIFallback();
|
||||
}
|
||||
|
||||
_inputField = container.Q<UTKInputField>("value-field");
|
||||
if (_inputField != null)
|
||||
{
|
||||
_inputField.Value = Value;
|
||||
_inputField.multiline = _isMultiline;
|
||||
if (_maxLength > 0)
|
||||
{
|
||||
_inputField.maxLength = _maxLength;
|
||||
}
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
private VisualElement CreateUIFallback()
|
||||
{
|
||||
var container = CreateContainer();
|
||||
|
||||
@@ -65,16 +87,16 @@ namespace UVC.UIToolkit
|
||||
var valueContainer = new VisualElement();
|
||||
valueContainer.AddToClassList("utk-property-item__value");
|
||||
|
||||
_textField = new TextField();
|
||||
_textField.name = "value-field";
|
||||
_textField.value = Value;
|
||||
_textField.multiline = _isMultiline;
|
||||
_inputField = new UTKInputField();
|
||||
_inputField.name = "value-field";
|
||||
_inputField.Value = Value;
|
||||
_inputField.multiline = _isMultiline;
|
||||
if (_maxLength > 0)
|
||||
{
|
||||
_textField.maxLength = _maxLength;
|
||||
_inputField.maxLength = _maxLength;
|
||||
}
|
||||
|
||||
valueContainer.Add(_textField);
|
||||
valueContainer.Add(_inputField);
|
||||
container.Add(valueContainer);
|
||||
|
||||
return container;
|
||||
@@ -84,21 +106,21 @@ namespace UVC.UIToolkit
|
||||
{
|
||||
base.BindUI(element);
|
||||
|
||||
_textField = element.Q<TextField>("value-field");
|
||||
if (_textField != null)
|
||||
_inputField = element.Q<UTKInputField>("value-field");
|
||||
if (_inputField != null)
|
||||
{
|
||||
_textField.value = Value;
|
||||
_textField.SetEnabled(!IsReadOnly);
|
||||
_textField.RegisterValueChangedCallback(OnTextChanged);
|
||||
_inputField.Value = Value;
|
||||
_inputField.SetEnabled(!IsReadOnly);
|
||||
_inputField.OnValueChanged += OnTextChanged;
|
||||
}
|
||||
}
|
||||
|
||||
public override void UnbindUI(VisualElement element)
|
||||
{
|
||||
if (_textField != null)
|
||||
if (_inputField != null)
|
||||
{
|
||||
_textField.UnregisterValueChangedCallback(OnTextChanged);
|
||||
_textField = null;
|
||||
_inputField.OnValueChanged -= OnTextChanged;
|
||||
_inputField = null;
|
||||
}
|
||||
|
||||
base.UnbindUI(element);
|
||||
@@ -106,9 +128,9 @@ namespace UVC.UIToolkit
|
||||
|
||||
public override void RefreshUI()
|
||||
{
|
||||
if (_textField != null && _textField.value != Value)
|
||||
if (_inputField != null && _inputField.Value != Value)
|
||||
{
|
||||
_textField.SetValueWithoutNotify(Value);
|
||||
_inputField.SetValue(Value, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,17 +138,17 @@ namespace UVC.UIToolkit
|
||||
{
|
||||
base.UpdateReadOnlyState();
|
||||
|
||||
if (_textField != null)
|
||||
if (_inputField != null)
|
||||
{
|
||||
_textField.SetEnabled(!IsReadOnly);
|
||||
_inputField.SetEnabled(!IsReadOnly);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
private void OnTextChanged(ChangeEvent<string> evt)
|
||||
private void OnTextChanged(string newValue)
|
||||
{
|
||||
DebounceValueChange(evt.newValue).Forget();
|
||||
DebounceValueChange(newValue).Forget();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user