/ghost/ui/layout.h

http://ghostcb.googlecode.com/ · C Header · 99 lines · 43 code · 28 blank · 28 comment · 0 complexity · a4af0aa98deba70bf63ae76533be88a1 MD5 · raw file

  1. #ifndef LAYOUT_H
  2. #define LAYOUT_H
  3. #include "common.h"
  4. class CWidget;
  5. /*
  6. Layouts make it possible to place widgets in different
  7. styles (vertical, horizontal).
  8. You need to create a layout and add widgets into it.
  9. Methods setSize and setPosition have limitations so
  10. given values should be reasonable.
  11. */
  12. // TODO: fix recursiveResize, it doesn't work properly with some setups
  13. // for example: 1.fixed size, 2.non-fixed size, 3.fixed size, etc...
  14. // however, we don't use such layouts currently so this isn't
  15. // an issue at the moment
  16. // Layout
  17. class CLayout
  18. {
  19. public:
  20. CLayout(CWidget *parent = 0);
  21. ~CLayout();
  22. // Add widget to layout
  23. void addWidget(CWidget *widget);
  24. // Remove widget from layout
  25. void removeWidget(CWidget *widget);
  26. // Get widget
  27. CWidget *widgetAt(uint index);
  28. // Show layout
  29. void show();
  30. // Hide layout
  31. void hide();
  32. // Update layout
  33. void update(int c);
  34. // Get widgets count
  35. int count();
  36. // Set size
  37. void setSize(uint width, uint height);
  38. // Set position
  39. void setPosition(uint x, uint y);
  40. // Get index of widget. Returns -1, if not found.
  41. int indexOf(CWidget *w);
  42. // Find first widget with custom id. Returns -1, if not found.
  43. int indexOf(int id);
  44. // Get widget at i.
  45. CWidget *at(uint i);
  46. protected:
  47. virtual void recursiveResize(uint from, uint to, uint width, uint height, uint x, uint y);
  48. CWidget *_parent;
  49. CSize _size;
  50. CPoint _pos;
  51. vector<CWidget *> _widgets;
  52. };
  53. // Vertical layout
  54. class CVBoxLayout : public CLayout
  55. {
  56. public:
  57. CVBoxLayout(CWidget *parent = 0);
  58. protected:
  59. void recursiveResize(uint from, uint to, uint width, uint height, uint x, uint y); //fixme?
  60. };
  61. // Horizontal layout
  62. class CHBoxLayout : public CLayout
  63. {
  64. public:
  65. CHBoxLayout(CWidget *parent = 0);
  66. protected:
  67. void recursiveResize(uint from, uint to, uint width, uint height, uint x, uint y); //fixme
  68. };
  69. #endif