show.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #include "ui/layers/show.h"
  8. #include "ui/toast/toast.h"
  9. namespace Ui {
  10. namespace {
  11. using namespace Toast;
  12. } // namespace
  13. void Show::showBox(
  14. object_ptr<BoxContent> content,
  15. LayerOptions options,
  16. anim::type animated) const {
  17. return showOrHideBoxOrLayer(std::move(content), options, animated);
  18. }
  19. void Show::showLayer(
  20. std::unique_ptr<LayerWidget> layer,
  21. LayerOptions options,
  22. anim::type animated) const {
  23. return showOrHideBoxOrLayer(std::move(layer), options, animated);
  24. }
  25. void Show::hideLayer(anim::type animated) const {
  26. return showOrHideBoxOrLayer(v::null, LayerOptions(), animated);
  27. }
  28. base::weak_ptr<Instance> Show::showToast(Config &&config) const {
  29. if (const auto strong = _lastToast.get()) {
  30. strong->hideAnimated();
  31. }
  32. _lastToast = valid()
  33. ? Toast::Show(toastParent(), std::move(config))
  34. : base::weak_ptr<Instance>();
  35. return _lastToast;
  36. }
  37. base::weak_ptr<Instance> Show::showToast(
  38. TextWithEntities &&text,
  39. crl::time duration) const {
  40. return showToast({ .text = std::move(text), .duration = duration });
  41. }
  42. base::weak_ptr<Instance> Show::showToast(
  43. const QString &text,
  44. crl::time duration) const {
  45. return showToast({
  46. .text = TextWithEntities{ text },
  47. .duration = duration,
  48. });
  49. }
  50. } // namespace Ui