guiTextListCtrl.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  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
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell 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
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUITEXTLISTCTRL_H_
  23. #define _GUITEXTLISTCTRL_H_
  24. #ifndef _GUIARRAYCTRL_H_
  25. #include "gui/core/guiArrayCtrl.h"
  26. #endif
  27. class GuiTextListCtrl : public GuiArrayCtrl
  28. {
  29. private:
  30. typedef GuiArrayCtrl Parent;
  31. public:
  32. struct Entry
  33. {
  34. char *text;
  35. U32 id;
  36. bool active;
  37. };
  38. Vector<Entry> mList;
  39. protected:
  40. enum ScrollConst
  41. {
  42. UP = 0,
  43. DOWN = 1
  44. };
  45. enum : U32
  46. {
  47. InvalidId = 0xFFFFFFFF
  48. };
  49. Vector<S32> mColumnOffsets;
  50. bool mFitParentWidth;
  51. bool mClipColumnText;
  52. S32 mRowHeightPadding;
  53. U32 getRowWidth(Entry *row);
  54. bool cellSelected(Point2I cell);
  55. void onCellSelected(Point2I cell);
  56. public:
  57. GuiTextListCtrl();
  58. DECLARE_CONOBJECT(GuiTextListCtrl);
  59. DECLARE_CATEGORY( "Gui Lists" );
  60. DECLARE_DESCRIPTION( "A control that displays text in tabular form." );
  61. DECLARE_CALLBACK( void, onSelect, (S32 cellid, const char* text));
  62. DECLARE_CALLBACK( void, onDeleteKey, ( S32 id ));
  63. static void initPersistFields();
  64. virtual void setCellSize( const Point2I &size ){ mCellSize = size; }
  65. virtual void getCellSize( Point2I &size ){ size = mCellSize; }
  66. const char *getScriptValue();
  67. void setScriptValue(const char *value);
  68. U32 getNumEntries();
  69. void clear();
  70. virtual void addEntry(U32 id, const char *text);
  71. virtual void insertEntry(U32 id, const char *text, S32 index);
  72. void setEntry(U32 id, const char *text);
  73. void setEntryActive(U32 id, bool active);
  74. S32 findEntryById(U32 id);
  75. S32 findEntryByText(const char *text);
  76. bool isEntryActive(U32 id);
  77. U32 getEntryId(U32 index);
  78. bool onWake();
  79. void removeEntry(U32 id);
  80. virtual void removeEntryByIndex(S32 id);
  81. virtual void sort(U32 column, bool increasing = true);
  82. virtual void sortNumerical(U32 column, bool increasing = true);
  83. U32 getSelectedId();
  84. U32 getSelectedRow();
  85. const char *getSelectedText();
  86. bool onKeyDown(const GuiEvent &event);
  87. bool onGamepadAxisUp(const GuiEvent& event);
  88. bool onGamepadAxisDown(const GuiEvent& event);
  89. virtual void onRenderCell(Point2I offset, Point2I cell, bool selected, bool mouseOver);
  90. void setSize(Point2I newSize);
  91. void onRemove();
  92. void addColumnOffset(S32 offset) { mColumnOffsets.push_back(offset); }
  93. void clearColumnOffsets() { mColumnOffsets.clear(); }
  94. };
  95. #endif //_GUI_TEXTLIST_CTRL_H