UIWindow.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <TurboBadger/tb_widgets.h>
  2. #include <TurboBadger/tb_widgets_common.h>
  3. #include <TurboBadger/tb_window.h>
  4. #include "../IO/Log.h"
  5. #include "UI.h"
  6. #include "UIEvents.h"
  7. #include "UIWindow.h"
  8. using namespace tb;
  9. namespace Atomic
  10. {
  11. UIWindow::UIWindow(Context* context, bool createWidget) : UIWidget(context, false)
  12. {
  13. if (createWidget)
  14. {
  15. widget_ = new TBWindow();
  16. widget_->SetDelegate(this);
  17. GetSubsystem<UI>()->WrapWidget(this, widget_);
  18. }
  19. }
  20. UI_WINDOW_SETTINGS UIWindow::GetSettings()
  21. {
  22. if (!widget_)
  23. return UI_WINDOW_SETTINGS_DEFAULT;
  24. return (UI_WINDOW_SETTINGS) ((TBWindow*)widget_)->GetSettings();
  25. }
  26. void UIWindow::SetSettings(UI_WINDOW_SETTINGS settings)
  27. {
  28. if (!widget_)
  29. return;
  30. ((TBWindow*)widget_)->SetSettings((WINDOW_SETTINGS) settings);
  31. }
  32. void UIWindow::ResizeToFitContent()
  33. {
  34. if (!widget_)
  35. return;
  36. ((TBWindow*)widget_)->ResizeToFitContent();
  37. }
  38. void UIWindow::Close()
  39. {
  40. if (!widget_)
  41. return;
  42. ((TBWindow*)widget_)->Close();
  43. }
  44. void UIWindow::AddChild(UIWidget *child)
  45. {
  46. if (!widget_ || !child->GetInternalWidget())
  47. return;
  48. UIWidget::AddChild(child);
  49. // this is to get proper padding, this may cause problems
  50. // as this is called from the widget_reader, and not as part of
  51. // AddChild. This may also need to be called from other widgets
  52. // that have padding, etc
  53. widget_->OnInflateChild(child->GetInternalWidget());
  54. }
  55. UIWindow::~UIWindow()
  56. {
  57. }
  58. bool UIWindow::OnEvent(const tb::TBWidgetEvent &ev)
  59. {
  60. return UIWidget::OnEvent(ev);
  61. }
  62. }