UIButton.cpp 968 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. String text = GetText();
  33. if (text.StartsWith("http://") || text.StartsWith("https://")) {
  34. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  35. fileSystem->SystemOpen(text);
  36. }
  37. }
  38. return UIWidget::OnEvent(ev);
  39. }
  40. }