UIEditField.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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::SetWrapping(bool wrap)
  23. {
  24. if (!widget_)
  25. return;
  26. TBEditField* w = (TBEditField*) widget_;
  27. w->SetWrapping(wrap);
  28. }
  29. bool UIEditField::GetWrapping()
  30. {
  31. if (!widget_)
  32. return false;
  33. TBEditField* w = (TBEditField*) widget_;
  34. return w->GetWrapping();
  35. }
  36. void UIEditField::SetTextAlign(TEXT_ALIGN align)
  37. {
  38. if (!widget_)
  39. return;
  40. // safe cast?
  41. TBEditField* w = (TBEditField*) widget_;
  42. switch (align)
  43. {
  44. case TEXT_ALIGN_CENTER:
  45. w->SetTextAlign(TB_TEXT_ALIGN_CENTER);
  46. break;
  47. case TEXT_ALIGN_LEFT:
  48. w->SetTextAlign(TB_TEXT_ALIGN_LEFT);
  49. break;
  50. case TEXT_ALIGN_RIGHT:
  51. w->SetTextAlign(TB_TEXT_ALIGN_RIGHT);
  52. break;
  53. }
  54. }
  55. bool UIEditField::OnEvent(const tb::TBWidgetEvent &ev)
  56. {
  57. return false;
  58. }
  59. }