layout_position.cpp 748 B

12345678910111213141516171819202122232425262728293031
  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 "layout/layout_position.h"
  8. namespace Layout {
  9. namespace {
  10. constexpr auto kMatrixRowShift = 40000;
  11. } // namespace
  12. Layout::Position IndexToPosition(int index) {
  13. return {
  14. (index >= 0) ? (index / kMatrixRowShift) : -1,
  15. (index >= 0) ? (index % kMatrixRowShift) : -1 };
  16. }
  17. int PositionToIndex(int row, int column) {
  18. return row * kMatrixRowShift + column;
  19. }
  20. int PositionToIndex(const Layout::Position &position) {
  21. return PositionToIndex(position.row, position.column);
  22. }
  23. } // namespace Layout