UIListView.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "UIWidget.h"
  24. #include "UISelectList.h"
  25. namespace Atomic
  26. {
  27. class ListViewItemSource;
  28. class ListViewItem;
  29. class ATOMIC_API UIListView : public UIWidget
  30. {
  31. ATOMIC_OBJECT(UIListView, UIWidget);
  32. public:
  33. /// Construct.
  34. UIListView(Context* context, bool createWidget = true);
  35. /// Destruct.
  36. virtual ~UIListView();
  37. unsigned AddRootItem(const String& text, const String& icon, const String& id);
  38. unsigned AddChildItem(unsigned parentItemID, const String& text, const String& icon, const String& id);
  39. void SetItemText(const String& id, const String& text);
  40. void SetItemTextSkin(const String& id, const String& skin);
  41. void SetItemIcon(const String& id, const String& icon);
  42. void DeleteItemByID(const String& id);
  43. void ScrollToSelectedItem();
  44. void SetExpanded(unsigned itemID, bool value);
  45. bool GetExpanded(unsigned itemID);
  46. bool GetExpandable(unsigned itemID);
  47. bool GetMultiSelect() const { return multiSelect_; }
  48. void SetMultiSelect(bool value) { multiSelect_ = value; }
  49. void DeleteAllItems();
  50. void SelectItemByID(const String& id, bool selected = true);
  51. String GetHoverItemID() { return rootList_.Null() ? "" : rootList_->GetHoverItemID(); }
  52. String GetSelectedItemID() { return rootList_.Null() ? "" : rootList_->GetSelectedItemID(); }
  53. UISelectList* GetRootList() { return rootList_; }
  54. void UpdateItemVisibility();
  55. void SelectAllItems(bool select = true);
  56. protected:
  57. virtual bool OnEvent(const tb::TBWidgetEvent &ev);
  58. private:
  59. void SendItemSelectedChanged(ListViewItem* item);
  60. void SelectSingleItem(ListViewItem* item, bool expand = true);
  61. void SetValueFirstSelected();
  62. void Move(tb::SPECIAL_KEY key);
  63. bool multiSelect_;
  64. float moveDelta_;
  65. SharedPtr<UISelectList> rootList_;
  66. ListViewItemSource* source_;
  67. HashMap<unsigned,ListViewItem*> itemLookup_;
  68. unsigned itemLookupId_;
  69. void SelectItem(ListViewItem* item, bool select);
  70. ListViewItem* pivot_;
  71. int pivotIndex_;
  72. bool startNewSelection_;
  73. };
  74. }