UIButtonGrid.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 numCols, int margin=0, bool createWidget = true );
  33. virtual ~UIButtonGrid();
  34. virtual String GetGridId( int row, int col ); /// returns id text at r,c, ie, "A1" for 0,0
  35. virtual void SetGridText ( int row, int col, String str ); /// set button text at r,c location
  36. virtual String GetGridText( int row, int col ); /// returns button text at r,c
  37. virtual UIWidget* GetGridWidget( int row, int col ); /// returns widget at r,c
  38. virtual int AddGridText ( String str ); /// add strings starting at 0,0 and filling out cols, then next row... , returns count
  39. virtual void ResetAddCount() { m_count = 0; } /// resets the counter for AddGridText()
  40. virtual UIWidget* AtGridWidget( int count ); /// returns widget at count
  41. virtual String AtGridText( int count ); /// returns text at count
  42. virtual void DisableEmptyButtons(); /// convience function to disable buttons with no text, and enable those with text.
  43. virtual int GetNumRows() const; /// returns number of rows that were programmed
  44. virtual int GetNumCols() const; /// returns number of cols that were programmed
  45. virtual int GetRowHeight() const; /// returns current row height
  46. virtual int GetColWidth() const; /// returns current col width
  47. virtual int GetMargin() const; /// returns current margin value
  48. protected:
  49. virtual bool OnEvent(const tb::TBWidgetEvent &ev);
  50. virtual void OnResized(int old_w, int old_h);
  51. private:
  52. void GenerateGrid();
  53. void ResizeGrid();
  54. virtual void AddGridRow( int rownum );
  55. int m_rows;
  56. int m_cols;
  57. int m_margin;
  58. int m_rowHeight;
  59. int m_colWidth;
  60. int m_count;
  61. };
  62. }