UIWidget.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #pragma once
  2. #include <TurboBadger/tb_widgets.h>
  3. #include "../Core/Object.h"
  4. namespace tb
  5. {
  6. class TBWidget;
  7. }
  8. namespace Atomic
  9. {
  10. class UILayoutParams;
  11. class UIFontDescription;
  12. /// Wraps a TurboBadger widget in our Object model
  13. class UIWidget : public Object, public tb::TBWidgetDelegate
  14. {
  15. friend class UI;
  16. OBJECT(UIWidget)
  17. public:
  18. UIWidget(Context* context, bool createWidget = true);
  19. virtual ~UIWidget();
  20. bool Load(const String& filename);
  21. IntRect GetRect();
  22. void SetRect(IntRect r);
  23. void SetSize(int width, int height);
  24. void SetPosition(int x, int y);
  25. void SetText(const String& text);
  26. void SetSkinBg(const String& id);
  27. void SetLayoutParams(UILayoutParams* params);
  28. void SetFontDescription(UIFontDescription* fd);
  29. UIWidget* GetParent();
  30. UIWidget* GetContentRoot();
  31. void RemoveChild(UIWidget* child, bool cleanup = true);
  32. void DeleteAllChildren();
  33. // String ID
  34. const String& GetId();
  35. virtual void SetId(const String& id);
  36. void Center();
  37. void SetGravity(/*WIDGET_GRAVITY*/ unsigned gravity);
  38. void SetValue(double value);
  39. double GetValue();
  40. void SetFocus();
  41. void SetState(/*WIDGET_STATE*/ unsigned state, bool on);
  42. bool GetState(/*WIDGET_STATE*/ unsigned state);
  43. void SetVisibility(/*WIDGET_VISIBILITY*/ unsigned visibility);
  44. void SetStateRaw(/*WIDGET_STATE*/ unsigned state);
  45. /*WIDGET_STATE*/ unsigned GetStateRaw();
  46. void Invalidate();
  47. void Die();
  48. UIWidget* GetFirstChild();
  49. UIWidget* GetNext();
  50. void SetIsFocusable(bool value);
  51. // get this or child widget with id
  52. UIWidget* GetWidget(const String& id);
  53. virtual void AddChild(UIWidget* child);
  54. tb::TBWidget* GetInternalWidget() { return widget_; }
  55. protected:
  56. void ConvertEvent(UIWidget* handler, UIWidget* target, const tb::TBWidgetEvent &ev, VariantMap& data);
  57. void SetWidget(tb::TBWidget* widget);
  58. virtual bool OnEvent(const tb::TBWidgetEvent &ev);
  59. virtual void OnDelete();
  60. String id_;
  61. tb::TBWidget* widget_;
  62. };
  63. }