UIButton.cpp 1015 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <TurboBadger/tb_widgets.h>
  2. #include <TurboBadger/tb_widgets_common.h>
  3. #include <Atomic/IO/Log.h>
  4. #include <Atomic/IO/FileSystem.h>
  5. #include "UIEvents.h"
  6. #include "UI.h"
  7. #include "UIButton.h"
  8. using namespace tb;
  9. namespace Atomic
  10. {
  11. UIButton::UIButton(Context* context, bool createWidget) : UIWidget(context, false)
  12. {
  13. if (createWidget)
  14. {
  15. widget_ = new TBButton();
  16. widget_->SetDelegate(this);
  17. GetSubsystem<UI>()->WrapWidget(this, widget_);
  18. }
  19. }
  20. UIButton::~UIButton()
  21. {
  22. }
  23. void UIButton::SetSqueezable(bool value)
  24. {
  25. if (!widget_)
  26. return;
  27. ((TBButton*)widget_)->SetSqueezable(value);
  28. }
  29. bool UIButton::OnEvent(const tb::TBWidgetEvent &ev)
  30. {
  31. if (ev.type == EVENT_TYPE_CLICK)
  32. {
  33. String text = GetText();
  34. if (text.StartsWith("http://") || text.StartsWith("https://"))
  35. {
  36. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  37. fileSystem->SystemOpen(text);
  38. }
  39. }
  40. return UIWidget::OnEvent(ev);
  41. }
  42. }