UISelectList.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include <TurboBadger/tb_select.h>
  2. #include "UI.h"
  3. #include "UIEvents.h"
  4. #include "UISelectList.h"
  5. using namespace tb;
  6. namespace Atomic
  7. {
  8. UISelectList::UISelectList(Context* context, bool createWidget) : UIWidget(context, false)
  9. {
  10. if (createWidget)
  11. {
  12. widget_ = new TBSelectList();
  13. widget_->SetDelegate(this);
  14. GetSubsystem<UI>()->WrapWidget(this, widget_);
  15. }
  16. }
  17. UISelectList::~UISelectList()
  18. {
  19. }
  20. tb::TBSelectList* UISelectList::GetTBSelectList()
  21. {
  22. return (TBSelectList*) widget_;
  23. }
  24. void UISelectList::SetFilter(const String& filter)
  25. {
  26. if (!widget_)
  27. return;
  28. ((TBSelectList*)widget_)->SetFilter(filter.CString());
  29. }
  30. void UISelectList::SetValue(int value)
  31. {
  32. if (!widget_)
  33. return;
  34. ((TBSelectList*)widget_)->SetValue(value);
  35. }
  36. int UISelectList::GetValue()
  37. {
  38. if (!widget_)
  39. return 0;
  40. return ((TBSelectList*)widget_)->GetValue();
  41. }
  42. void UISelectList::InvalidateList()
  43. {
  44. if (!widget_)
  45. return;
  46. return ((TBSelectList*)widget_)->InvalidateList();
  47. }
  48. String UISelectList::GetSelectedItemID()
  49. {
  50. if (!widget_)
  51. return "";
  52. String id_;
  53. TBID id = ((TBSelectList*)widget_)->GetSelectedItemID();
  54. GetSubsystem<UI>()->GetTBIDString(id, id_);
  55. return id_;
  56. }
  57. String UISelectList::GetHoverItemID()
  58. {
  59. if (!widget_)
  60. return "";
  61. if (!TBWidget::hovered_widget)
  62. return "";
  63. TBSelectList* select = (TBSelectList*) widget_;
  64. if (!select->IsAncestorOf(TBWidget::hovered_widget))
  65. {
  66. return "";
  67. }
  68. String id_;
  69. GetSubsystem<UI>()->GetTBIDString(TBWidget::hovered_widget->GetID(), id_);
  70. return id_;
  71. }
  72. void UISelectList::SetSource(UISelectItemSource* source)
  73. {
  74. if (!widget_)
  75. return;
  76. ((TBSelectList*)widget_)->SetSource(source ? source->GetTBItemSource() : NULL);
  77. }
  78. bool UISelectList::OnEvent(const tb::TBWidgetEvent &ev)
  79. {
  80. return false;
  81. }
  82. }