info_userpic_emoji_builder.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #include "info/userpic/info_userpic_emoji_builder.h"
  8. #include "info/userpic/info_userpic_emoji_builder_common.h"
  9. #include "info/userpic/info_userpic_emoji_builder_layer.h"
  10. #include "info/userpic/info_userpic_emoji_builder_widget.h"
  11. #include "lang/lang_keys.h"
  12. #include "ui/widgets/buttons.h"
  13. #include "ui/wrap/vertical_layout.h"
  14. #include "window/window_session_controller.h"
  15. #include "styles/style_info_userpic_builder.h"
  16. namespace UserpicBuilder {
  17. void ShowLayer(
  18. not_null<Window::SessionController*> controller,
  19. StartData data,
  20. Fn<void(UserpicBuilder::Result)> &&doneCallback) {
  21. auto layer = std::make_unique<LayerWidget>();
  22. const auto layerRaw = layer.get();
  23. {
  24. struct State {
  25. rpl::event_stream<> clicks;
  26. };
  27. const auto state = layer->lifetime().make_state<State>();
  28. const auto content = CreateUserpicBuilder(
  29. layerRaw,
  30. controller,
  31. data,
  32. BothWayCommunication<UserpicBuilder::Result>{
  33. .triggers = state->clicks.events(),
  34. .result = [=, done = std::move(doneCallback)](Result r) {
  35. done(std::move(r));
  36. layerRaw->closeLayer();
  37. },
  38. });
  39. const auto save = Ui::CreateChild<Ui::RoundButton>(
  40. content.get(),
  41. tr::lng_connection_save(),
  42. st::userpicBuilderEmojiButton);
  43. save->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
  44. content->sizeValue(
  45. ) | rpl::start_with_next([=] {
  46. const auto &p = st::userpicBuilderEmojiSavePosiiton;
  47. save->moveToRight(p.x(), p.y());
  48. }, save->lifetime());
  49. save->clicks() | rpl::to_empty | rpl::start_to_stream(
  50. state->clicks,
  51. save->lifetime());
  52. const auto back = Ui::CreateChild<Ui::IconButton>(
  53. content.get(),
  54. st::userpicBuilderEmojiBackButton);
  55. back->setClickedCallback([=] {
  56. layerRaw->closeLayer();
  57. });
  58. content->sizeValue(
  59. ) | rpl::start_with_next([=] {
  60. const auto &p = st::userpicBuilderEmojiBackPosiiton;
  61. back->moveToLeft(p.x(), p.y());
  62. }, back->lifetime());
  63. layer->setContent(content);
  64. }
  65. controller->showLayer(std::move(layer), Ui::LayerOption::KeepOther);
  66. }
  67. } // namespace UserpicBuilder