UIButtonGrid.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // Copyright (c) 2014-2017, 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 <ThirdParty/TurboBadger/tb_layout.h>
  24. #include "UIWidget.h"
  25. namespace Atomic
  26. {
  27. /// A grid of buttons that keep their shape and size, with minimal programming.
  28. class ATOMIC_API UIButtonGrid : public UIWidget
  29. {
  30. ATOMIC_OBJECT(UIButtonGrid, UIWidget)
  31. public:
  32. UIButtonGrid(Context* context, int numRows, int numColumns, int margin=0, bool createWidget = true );
  33. virtual ~UIButtonGrid();
  34. /// returns id text for a row,column location, ie, A1 for location 0,0
  35. String GetGridId( int row, int column );
  36. /// set the button text at the row,column location
  37. void SetGridText ( int row, int column, String str );
  38. /// returns the button text at the row,column location
  39. String GetGridText( int row, int column );
  40. /// returns widget at the row,column location
  41. UIWidget* GetGridWidget( int row, int column );
  42. /// adds button text strings starting at 0,0 and filling out by cols, then rows, returns count
  43. int AddGridText ( String str );
  44. /// resets the counter for AddGridText()
  45. void ResetAddCount() { addCount_ = 0; }
  46. /// returns the widget at count
  47. UIWidget* AtGridWidget( int count );
  48. /// returns the button text at count
  49. String AtGridText( int count );
  50. /// convience function to disable buttons with no text, and enable those with text.
  51. void DisableEmptyButtons();
  52. /// returns number of rows that were programmed
  53. int GetNumRows() const;
  54. /// returns number of columns that were programmed
  55. int GetNumColumns() const;
  56. /// returns current row height value
  57. int GetRowHeight() const;
  58. /// returns current column width value
  59. int GetColumnWidth() const;
  60. /// returns current margin value
  61. int GetMargin() const;
  62. protected:
  63. virtual bool OnEvent(const tb::TBWidgetEvent &ev);
  64. virtual void OnResized(int old_w, int old_h);
  65. private:
  66. /// internal method to create the widgets in the assembly
  67. void GenerateGrid();
  68. /// internal method to adjust the row and column sizes based on new geometry
  69. void ResizeGrid();
  70. /// internal utility method to create a row of widgets.
  71. virtual void AddGridRow( int rownum );
  72. int rows_;
  73. int columns_;
  74. int margin_;
  75. int rowHeight_;
  76. int columnWidth_;
  77. int addCount_;
  78. };
  79. }