confirm_box.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "ui/layers/generic_box.h"
  9. #include "ui/text/text_variant.h"
  10. namespace Ui {
  11. struct ConfirmBoxArgs {
  12. using Callback = std::variant<
  13. v::null_t,
  14. Fn<void()>,
  15. Fn<void(Fn<void()>)>>;
  16. v::text::data text = v::null;
  17. Callback confirmed = v::null;
  18. Callback cancelled = v::null;
  19. v::text::data confirmText;
  20. v::text::data cancelText;
  21. const style::RoundButton *confirmStyle = nullptr;
  22. const style::RoundButton *cancelStyle = nullptr;
  23. const style::FlatLabel *labelStyle = nullptr;
  24. Fn<bool(const ClickHandlerPtr&, Qt::MouseButton)> labelFilter;
  25. std::optional<QMargins> labelPadding;
  26. v::text::data title = v::null;
  27. bool inform = false;
  28. // If strict cancel is set the cancel.callback() is only called
  29. // if the cancel button was pressed.
  30. bool strictCancel = false;
  31. };
  32. void ConfirmBox(not_null<GenericBox*> box, ConfirmBoxArgs &&args);
  33. inline void InformBox(not_null<GenericBox*> box, ConfirmBoxArgs &&args) {
  34. args.inform = true;
  35. ConfirmBox(box, std::move(args));
  36. }
  37. [[nodiscard]] object_ptr<GenericBox> MakeConfirmBox(ConfirmBoxArgs &&args);
  38. [[nodiscard]] inline object_ptr<GenericBox> MakeInformBox(
  39. ConfirmBoxArgs &&args) {
  40. args.inform = true;
  41. return MakeConfirmBox(std::move(args));
  42. }
  43. [[nodiscard]] inline object_ptr<GenericBox> MakeInformBox(
  44. v::text::data text) {
  45. return MakeInformBox({ .text = std::move(text) });
  46. }
  47. void IconWithTitle(
  48. not_null<VerticalLayout*> container,
  49. not_null<RpWidget*> icon,
  50. not_null<RpWidget*> title,
  51. RpWidget *subtitle = nullptr);
  52. } // namespace Ui