UIText.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "UIText.h"
  2. UITextElement::UITextElement()
  3. : UIElement()
  4. {}
  5. void UITextElement::setText(const Framework::Text& text)
  6. {
  7. this->text = text;
  8. }
  9. const Framework::Text& UITextElement::getText() const
  10. {
  11. return text;
  12. }
  13. Framework::XML::Element* UITextElement::toUIML(
  14. Framework::Either<Block*, Entity*> zTarget, Entity* zActor) const
  15. {
  16. Framework::XML::Element* result = UIElement::toUIML(zTarget, zActor);
  17. result->setName("text");
  18. result->setText(text);
  19. return result;
  20. }
  21. UITextElementFactory::UITextElementFactory()
  22. : UIElementFactory()
  23. {}
  24. JSONObjectValidationBuilder* UITextElementFactory::addToValidator(
  25. JSONObjectValidationBuilder* builder) const
  26. {
  27. return UIElementFactory::addToValidator(builder)
  28. ->withRequiredString("text")
  29. ->finishString();
  30. }
  31. UITextElement* UITextElementFactory::fromJson(
  32. Framework::JSON::JSONObject* zJson) const
  33. {
  34. UITextElement* result = UIElementFactory::fromJson(zJson);
  35. result->setText(zJson->zValue("text")->asString()->getString());
  36. return result;
  37. }
  38. Framework::JSON::JSONObject* UITextElementFactory::toJsonObject(
  39. UITextElement* zObject) const
  40. {
  41. Framework::JSON::JSONObject* result
  42. = UIElementFactory::toJsonObject(zObject);
  43. result->addValue(
  44. "text", new Framework::JSON::JSONString(zObject->getText()));
  45. return result;
  46. }
  47. UITextElement* UITextElementFactory::createElement(
  48. Framework::JSON::JSONObject* zJson) const
  49. {
  50. return new UITextElement();
  51. }
  52. const char* UITextElementFactory::getTypeToken() const
  53. {
  54. return "text";
  55. }