ListView.pkg 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. /// Add item to the end of the list.
  17. void AddItem(UIElement* item);
  18. /// \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.
  19. /// If index is greater than the total items then the new item is inserted at the end of the list.
  20. /// 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.
  21. /// 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.
  22. void InsertItem(unsigned index, UIElement* item, UIElement* parentItem = 0);
  23. /// Remove specific item, starting search at the specified index if provided. In hierarchy mode will also remove any children.
  24. void RemoveItem(UIElement* item, unsigned index = 0);
  25. /// Remove item at index. In hierarchy mode will also remove any children.
  26. void RemoveItem(unsigned index);
  27. /// Remove all items.
  28. void RemoveAllItems();
  29. /// Set selection.
  30. void SetSelection(unsigned index);
  31. /// Add item to the selection, multiselect mode only.
  32. void AddSelection(unsigned index);
  33. /// Remove item from the selection.
  34. void RemoveSelection(unsigned index);
  35. /// Toggle selection of an item.
  36. void ToggleSelection(unsigned index);
  37. /// Move selection by a delta and clamp at list ends. If additive (multiselect only), will add to the existing selection.
  38. void ChangeSelection(int delta, bool additive = false);
  39. /// Clear selection.
  40. void ClearSelection();
  41. /// Set selected items' highlight mode.
  42. void SetHighlightMode(HighlightMode mode);
  43. /// Enable multiselect.
  44. void SetMultiselect(bool enable);
  45. /// \brief Enable hierarchy mode. Allows items to have parent-child relationship at different indent level and the ability to expand/collapse child items.
  46. /// All items in the list will be lost during mode change.
  47. void SetHierarchyMode(bool enable);
  48. /// Set base indent, i.e. the indent level of the ultimate parent item.
  49. void SetBaseIndent(int baseIndent);
  50. /// Enable clearing of selection on defocus.
  51. void SetClearSelectionOnDefocus(bool enable);
  52. /// Set item doubleclick interval in seconds.
  53. void SetDoubleClickInterval(float interval);
  54. /// Expand item at index. Only has effect in hierarchy mode.
  55. void Expand(unsigned index, bool enable, bool recursive = false);
  56. /// Toggle item's expanded flag at index. Only has effect in hierarchy mode.
  57. void ToggleExpand(unsigned index, bool recursive = false);
  58. /// Return number of items.
  59. unsigned GetNumItems() const;
  60. /// Return item at index.
  61. UIElement* GetItem(unsigned index) const;
  62. /// Return index of item, or M_MAX_UNSIGNED If not found.
  63. unsigned FindItem(UIElement* item) const;
  64. /// Return first selected index, or M_MAX_UNSIGNED if none selected.
  65. unsigned GetSelection() const;
  66. /// Return first selected item, or null if none selected.
  67. UIElement* GetSelectedItem() const;
  68. /// Return whether an item at index is seleccted.
  69. bool IsSelected(unsigned index) const;
  70. /// Return whether an item at index has its children expanded (in hierachy mode only).
  71. bool IsExpanded(unsigned index) const;
  72. /// Return highlight mode.
  73. HighlightMode GetHighlightMode() const { return highlightMode_; }
  74. /// Return whether multiselect enabled.
  75. bool GetMultiselect() const { return multiselect_; }
  76. /// Return whether selection is cleared on defocus.
  77. bool GetClearSelectionOnDefocus() const { return clearSelectionOnDefocus_; }
  78. /// Return whether hierarchy mode enabled.
  79. bool GetHierarchyMode() const { return hierarchyMode_; }
  80. /// Return base indent.
  81. int GetBaseIndent() const { return baseIndent_; }
  82. /// Return item doubleclick interval in seconds.
  83. float GetDoubleClickInterval() const;
  84. };