2
0

BsGUITextField.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "BsGUITextField.h"
  2. #include "BsGUIArea.h"
  3. #include "BsGUILayout.h"
  4. #include "BsGUILabel.h"
  5. #include "BsGUIInputBox.h"
  6. #include "BsBuiltinResources.h"
  7. #include "BsGUIWidget.h"
  8. #include "BsGUIMouseEvent.h"
  9. #include "BsGUIWidget.h"
  10. #include "BsCmdInputFieldValueChange.h"
  11. using namespace std::placeholders;
  12. namespace BansheeEngine
  13. {
  14. GUITextField::GUITextField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  15. const String& style, const GUILayoutOptions& layoutOptions, bool withLabel)
  16. :TGUIField(dummy, labelContent, labelWidth, style, layoutOptions, withLabel),
  17. mInputBox(nullptr), mValue(L""), mHasInputFocus(false)
  18. {
  19. mInputBox = GUIInputBox::create(false, getSubStyleName(getInputStyleType()));
  20. mLayout->addElement(mInputBox);
  21. mInputBox->onValueChanged.connect(std::bind(&GUITextField::valueChanged, this, _1));
  22. mInputBox->onFocusGained.connect(std::bind(&GUITextField::focusGained, this));
  23. mInputBox->onFocusLost.connect(std::bind(&GUITextField::focusLost, this));
  24. }
  25. GUITextField::~GUITextField()
  26. {
  27. }
  28. void GUITextField::setValue(const WString& value)
  29. {
  30. mValue = value;
  31. mInputBox->setText(value);
  32. }
  33. void GUITextField::styleUpdated()
  34. {
  35. if (mLabel != nullptr)
  36. mLabel->setStyle(getSubStyleName(getLabelStyleType()));
  37. mInputBox->setStyle(getSubStyleName(getInputStyleType()));
  38. }
  39. void GUITextField::valueChanged(const WString& newValue)
  40. {
  41. CmdInputFieldValueChange<GUITextField, WString>::execute(this, newValue);
  42. if (!onValueChanged.empty())
  43. onValueChanged(newValue);
  44. }
  45. void GUITextField::focusGained()
  46. {
  47. UndoRedo::instance().pushGroup("InputBox");
  48. mHasInputFocus = true;
  49. }
  50. void GUITextField::focusLost()
  51. {
  52. UndoRedo::instance().popGroup("InputBox");
  53. mHasInputFocus = false;
  54. }
  55. const String& GUITextField::getGUITypeName()
  56. {
  57. static String typeName = "GUITextField";
  58. return typeName;
  59. }
  60. const String& GUITextField::getInputStyleType()
  61. {
  62. static String LABEL_STYLE_TYPE = "EditorFieldInput";
  63. return LABEL_STYLE_TYPE;
  64. }
  65. }