UIEditField.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <TurboBadger/tb_widgets.h>
  2. #include <TurboBadger/tb_widgets_common.h>
  3. #include <TurboBadger/tb_editfield.h>
  4. #include "UI.h"
  5. #include "UIEvents.h"
  6. #include "UIEditField.h"
  7. using namespace tb;
  8. namespace Atomic
  9. {
  10. UIEditField::UIEditField(Context* context, bool createWidget) : UIWidget(context, false)
  11. {
  12. if (createWidget)
  13. {
  14. widget_ = new TBEditField();
  15. widget_->SetDelegate(this);
  16. GetSubsystem<UI>()->WrapWidget(this, widget_);
  17. }
  18. }
  19. UIEditField::~UIEditField()
  20. {
  21. }
  22. void UIEditField::SetReadOnly(bool readonly)
  23. {
  24. if (!widget_)
  25. return;
  26. TBEditField* w = (TBEditField*) widget_;
  27. w->SetReadOnly(readonly);
  28. }
  29. void UIEditField::SetWrapping(bool wrap)
  30. {
  31. if (!widget_)
  32. return;
  33. TBEditField* w = (TBEditField*) widget_;
  34. w->SetWrapping(wrap);
  35. }
  36. bool UIEditField::GetWrapping()
  37. {
  38. if (!widget_)
  39. return false;
  40. TBEditField* w = (TBEditField*) widget_;
  41. return w->GetWrapping();
  42. }
  43. void UIEditField::SetTextAlign(TEXT_ALIGN align)
  44. {
  45. if (!widget_)
  46. return;
  47. // safe cast?
  48. TBEditField* w = (TBEditField*) widget_;
  49. switch (align)
  50. {
  51. case TEXT_ALIGN_CENTER:
  52. w->SetTextAlign(TB_TEXT_ALIGN_CENTER);
  53. break;
  54. case TEXT_ALIGN_LEFT:
  55. w->SetTextAlign(TB_TEXT_ALIGN_LEFT);
  56. break;
  57. case TEXT_ALIGN_RIGHT:
  58. w->SetTextAlign(TB_TEXT_ALIGN_RIGHT);
  59. break;
  60. }
  61. }
  62. bool UIEditField::OnEvent(const tb::TBWidgetEvent &ev)
  63. {
  64. return UIWidget::OnEvent(ev);
  65. }
  66. }