public override void Initialize(Table table, Skin skin, float leftCellWidth) { var button = new TextButton(_name, skin); button.OnClicked += OnButtonClicked; button.OnRightClicked += OnButtonClicked; // we could have zero or 1 param var parameters = (_memberInfo as MethodInfo).GetParameters(); if (parameters.Length == 0) { table.Add(button); return; } var parameter = parameters[0]; _parameterType = parameter.ParameterType; _textField = new TextField( _parameterType.GetTypeInfo().IsValueType ? Activator.CreateInstance(_parameterType).ToString() : "", skin); _textField.ShouldIgnoreTextUpdatesWhileFocused = false; // add a filter for float/int if (_parameterType == typeof(float)) { _textField.SetTextFieldFilter(new FloatFilter()); } if (_parameterType == typeof(int)) { _textField.SetTextFieldFilter(new DigitsOnlyFilter()); } if (_parameterType == typeof(bool)) { _textField.SetTextFieldFilter(new BoolFilter()); } table.Add(button); table.Add(_textField).SetMaxWidth(70); }
public override void Initialize(Table table, Skin skin, float leftCellWidth) { var label = CreateNameLabel(table, skin, leftCellWidth); _textField = new TextField(GetValue <string>(), skin); _textField.SetTextFieldFilter(new FloatFilter()); _textField.OnTextChanged += (field, str) => { SetValue(str); }; table.Add(label); table.Add(_textField).SetMaxWidth(70); }
public override void Initialize(Table table, Skin skin, float leftCellWidth) { var value = GetValue <Vector2>(); var label = CreateNameLabel(table, skin, leftCellWidth); var labelX = new Label("x", skin); _textFieldX = new TextField(value.X.ToString(CultureInfo.InvariantCulture), skin); _textFieldX.SetScale(2f); _textFieldX.SetTextFieldFilter(new FloatFilter()).SetPreferredWidth(100); _textFieldX.OnTextChanged += (field, str) => { float newX; if (float.TryParse(str, NumberStyles.Float, CultureInfo.InvariantCulture, out newX)) { var newValue = GetValue <Vector2>(); newValue.X = newX; SetValue(newValue); } }; var labelY = new Label("y", skin); _textFieldY = new TextField(value.Y.ToString(CultureInfo.InvariantCulture), skin); _textFieldY.SetScale(2f); _textFieldY.SetTextFieldFilter(new FloatFilter()).SetPreferredWidth(100); _textFieldY.OnTextChanged += (field, str) => { float newY; if (float.TryParse(str, NumberStyles.Float, CultureInfo.InvariantCulture, out newY)) { var newValue = GetValue <Vector2>(); newValue.Y = newY; SetValue(newValue); } }; var hBox = new HorizontalGroup(5); hBox.AddElement(labelX); hBox.AddElement(_textFieldX); hBox.AddElement(labelY); hBox.AddElement(_textFieldY); table.Add(label); table.Add(hBox); }
void SetupTextField(Table table, Skin skin, float leftCellWidth) { var label = CreateNameLabel(table, skin, leftCellWidth); _textField = new TextField(GetValue <int>().ToString(), skin); _textField.SetTextFieldFilter(new FloatFilter()); _textField.OnTextChanged += (field, str) => { int newValue; if (int.TryParse(str, out newValue)) { SetValue(newValue); } }; table.Add(label); table.Add(_textField).SetMaxWidth(70); }
void SetupTextField(Table table, Skin skin, float leftCellWidth) { var label = CreateNameLabel(table, skin, leftCellWidth); _textField = new TextField(GetValue <float>().ToString(CultureInfo.InvariantCulture), skin); _textField.SetTextFieldFilter(new FloatFilter()); _textField.OnTextChanged += (field, str) => { float newValue; if (float.TryParse(str, NumberStyles.Float, CultureInfo.InvariantCulture, out newValue)) { SetValue(newValue); } }; table.Add(label); table.Add(_textField).SetMaxWidth(70); }
public override void Initialize(Table table, Skin skin, float leftCellWidth) { var value = GetValue <Color>(); var label = CreateNameLabel(table, skin, leftCellWidth); var labelR = new Label("r", skin); _textFieldR = new TextField(value.R.ToString(), skin); _textFieldR.SetMaxLength(3); _textFieldR.SetTextFieldFilter(new DigitsOnlyFilter()).SetPreferredWidth(28); _textFieldR.OnTextChanged += (field, str) => { int newR; if (int.TryParse(str, out newR)) { var newValue = GetValue <Color>(); newValue.R = (byte)newR; SetValue(newValue); } }; var labelG = new Label("g", skin); _textFieldG = new TextField(value.G.ToString(), skin); _textFieldG.SetMaxLength(3); _textFieldG.SetTextFieldFilter(new DigitsOnlyFilter()).SetPreferredWidth(28); _textFieldG.OnTextChanged += (field, str) => { int newG; if (int.TryParse(str, out newG)) { var newValue = GetValue <Color>(); newValue.G = (byte)newG; SetValue(newValue); } }; var labelB = new Label("b", skin); _textFieldB = new TextField(value.B.ToString(), skin); _textFieldB.SetMaxLength(3); _textFieldB.SetTextFieldFilter(new DigitsOnlyFilter()).SetPreferredWidth(28); _textFieldB.OnTextChanged += (field, str) => { int newB; if (int.TryParse(str, out newB)) { var newValue = GetValue <Color>(); newValue.B = (byte)newB; SetValue(newValue); } }; var labelA = new Label("a", skin); _textFieldA = new TextField(value.A.ToString(), skin); _textFieldA.SetMaxLength(3); _textFieldA.SetTextFieldFilter(new DigitsOnlyFilter()).SetPreferredWidth(28); _textFieldA.OnTextChanged += (field, str) => { int newA; if (int.TryParse(str, out newA)) { var newValue = GetValue <Color>(); newValue.A = (byte)newA; SetValue(newValue); } }; var hBox = new HorizontalGroup(2); hBox.AddElement(labelR); hBox.AddElement(_textFieldR); hBox.AddElement(labelG); hBox.AddElement(_textFieldG); hBox.AddElement(labelB); hBox.AddElement(_textFieldB); hBox.AddElement(labelA); hBox.AddElement(_textFieldA); table.Add(label); table.Add(hBox); }