ListView.pkg 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. $#include "ListView.h"
  2. /// %ListView selection highlight mode.
  3. enum HighlightMode
  4. {
  5. /// Never highlight selections.
  6. HM_NEVER,
  7. /// Highlight when focused.
  8. HM_FOCUS,
  9. /// Highlight always.
  10. HM_ALWAYS
  11. };
  12. /// Scrollable list %UI element.
  13. class ListView : public ScrollView
  14. {
  15. public:
  16. /// Construct.
  17. ListView(Context* context);
  18. /// Destruct.
  19. virtual ~ListView();
  20. /// Add item to the end of the list.
  21. void AddItem(UIElement* item);
  22. /// \brief Insert item at a specific index. In hierarchy mode, the optional parameter will be used to determine the child's indent level in respect to its parent.
  23. /// If index is greater than the total items then the new item is inserted at the end of the list.
  24. /// In hierarchy mode, if index is greater than the index of last children of the specified parent item then the new item is inserted next to the last children.
  25. /// And if the index is lesser than the index of the parent item itself then the new item is inserted before the first child item.
  26. void InsertItem(unsigned index, UIElement* item, UIElement* parentItem = 0);
  27. /// Remove specific item, starting search at the specified index if provided. In hierarchy mode will also remove any children.
  28. void RemoveItem(UIElement* item, unsigned index = 0);
  29. /// Remove item at index. In hierarchy mode will also remove any children.
  30. void RemoveItem(unsigned index);
  31. /// Remove all items.
  32. void RemoveAllItems();
  33. /// Set selection.
  34. void SetSelection(unsigned index);
  35. /// Add item to the selection, multiselect mode only.
  36. void AddSelection(unsigned index);
  37. /// Remove item from the selection.
  38. void RemoveSelection(unsigned index);
  39. /// Toggle selection of an item.
  40. void ToggleSelection(unsigned index);
  41. /// Move selection by a delta and clamp at list ends. If additive (multiselect only), will add to the existing selection.
  42. void ChangeSelection(int delta, bool additive = false);
  43. /// Clear selection.
  44. void ClearSelection();
  45. /// Set selected items' highlight mode.
  46. void SetHighlightMode(HighlightMode mode);
  47. /// Enable multiselect.
  48. void SetMultiselect(bool enable);
  49. /// \brief Enable hierarchy mode. Allows items to have parent-child relationship at different indent level and the ability to expand/collapse child items.
  50. /// All items in the list will be lost during mode change.
  51. void SetHierarchyMode(bool enable);
  52. /// Set base indent, i.e. the indent level of the ultimate parent item.
  53. void SetBaseIndent(int baseIndent);
  54. /// Enable clearing of selection on defocus.
  55. void SetClearSelectionOnDefocus(bool enable);
  56. /// Set item doubleclick interval in seconds.
  57. void SetDoubleClickInterval(float interval);
  58. /// Expand item at index. Only has effect in hierarchy mode.
  59. void Expand(unsigned index, bool enable, bool recursive = false);
  60. /// Toggle item's expanded flag at index. Only has effect in hierarchy mode.
  61. void ToggleExpand(unsigned index, bool recursive = false);
  62. /// Return number of items.
  63. unsigned GetNumItems() const;
  64. /// Return item at index.
  65. UIElement* GetItem(unsigned index) const;
  66. /// Return index of item, or M_MAX_UNSIGNED If not found.
  67. unsigned FindItem(UIElement* item) const;
  68. /// Return first selected index, or M_MAX_UNSIGNED if none selected.
  69. unsigned GetSelection() const;
  70. /// Return first selected item, or null if none selected.
  71. UIElement* GetSelectedItem() const;
  72. /// Return whether an item at index is seleccted.
  73. bool IsSelected(unsigned index) const;
  74. /// Return whether an item at index has its children expanded (in hierachy mode only).
  75. bool IsExpanded(unsigned index) const;
  76. /// Return highlight mode.
  77. HighlightMode GetHighlightMode() const { return highlightMode_; }
  78. /// Return whether multiselect enabled.
  79. bool GetMultiselect() const { return multiselect_; }
  80. /// Return whether selection is cleared on defocus.
  81. bool GetClearSelectionOnDefocus() const { return clearSelectionOnDefocus_; }
  82. /// Return whether hierarchy mode enabled.
  83. bool GetHierarchyMode() const { return hierarchyMode_; }
  84. /// Return base indent.
  85. int GetBaseIndent() const { return baseIndent_; }
  86. /// Return item doubleclick interval in seconds.
  87. float GetDoubleClickInterval() const;
  88. };