Added layout utils file.

This commit is contained in:
23rd 2021-07-22 00:34:41 +03:00 committed by John Preston
parent c4d8d52aed
commit 85ce179f58
3 changed files with 49 additions and 0 deletions

View file

@ -704,6 +704,8 @@ PRIVATE
lang/lang_numbers_animation.h
lang/lang_translator.cpp
lang/lang_translator.h
layout/layout_utils.cpp
layout/layout_utils.h
main/main_account.cpp
main/main_account.h
main/main_app_config.cpp

View file

@ -0,0 +1,26 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "layout/layout_utils.h"
namespace Layout {
Layout::Position IndexToPosition(int index) {
return {
(index >= 0) ? (index / MatrixRowShift) : -1,
(index >= 0) ? (index % MatrixRowShift) : -1 };
}
int PositionToIndex(int row, int column) {
return row * MatrixRowShift + column;
}
int PositionToIndex(const Layout::Position &position) {
return PositionToIndex(position.row, position.column);
}
} // namespace Layout

View file

@ -0,0 +1,21 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
namespace Layout {
struct Position {
int row = -1;
int column = -1;
};
[[nodiscard]] Position IndexToPosition(int index);
[[nodiscard]] int PositionToIndex(int row, int column);
[[nodiscard]] int PositionToIndex(const Position &position);
} // namespace Layout