window_adaptive.cpp 2.0 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 "window/window_adaptive.h"
  8. #include "history/history_item.h"
  9. #include "data/data_media_types.h"
  10. #include "data/data_session.h"
  11. #include "core/application.h"
  12. #include "core/core_settings.h"
  13. namespace Window {
  14. Adaptive::Adaptive() = default;
  15. void Adaptive::setWindowLayout(WindowLayout value) {
  16. _layout = value;
  17. }
  18. void Adaptive::setChatLayout(ChatLayout value) {
  19. _chatLayout = value;
  20. }
  21. rpl::producer<> Adaptive::value() const {
  22. return rpl::merge(
  23. Core::App().settings().adaptiveForWideValue() | rpl::to_empty,
  24. _chatLayout.changes() | rpl::to_empty,
  25. _layout.changes() | rpl::to_empty);
  26. }
  27. rpl::producer<> Adaptive::changes() const {
  28. return rpl::merge(
  29. Core::App().settings().adaptiveForWideChanges() | rpl::to_empty,
  30. _chatLayout.changes() | rpl::to_empty,
  31. _layout.changes() | rpl::to_empty);
  32. }
  33. rpl::producer<bool> Adaptive::oneColumnValue() const {
  34. return _layout.value(
  35. ) | rpl::map([=] {
  36. return isOneColumn();
  37. });
  38. }
  39. rpl::producer<Adaptive::ChatLayout> Adaptive::chatLayoutValue() const {
  40. return _chatLayout.value();
  41. }
  42. bool Adaptive::isOneColumn() const {
  43. return _layout.current() == WindowLayout::OneColumn;
  44. }
  45. bool Adaptive::isNormal() const {
  46. return _layout.current() == WindowLayout::Normal;
  47. }
  48. bool Adaptive::isThreeColumn() const {
  49. return _layout.current() == WindowLayout::ThreeColumn;
  50. }
  51. rpl::producer<bool> Adaptive::chatWideValue() const {
  52. return rpl::combine(
  53. _chatLayout.value(
  54. ) | rpl::map(rpl::mappers::_1 == Adaptive::ChatLayout::Wide),
  55. Core::App().settings().adaptiveForWideValue()
  56. ) | rpl::map(rpl::mappers::_1 && rpl::mappers::_2);
  57. }
  58. bool Adaptive::isChatWide() const {
  59. return Core::App().settings().adaptiveForWide()
  60. && (_chatLayout.current() == Adaptive::ChatLayout::Wide);
  61. }
  62. } // namespace Window