From 85ce179f581da7e9d50ff02dca775eb437732194 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 22 Jul 2021 00:34:41 +0300 Subject: [PATCH] Added layout utils file. --- Telegram/CMakeLists.txt | 2 ++ Telegram/SourceFiles/layout/layout_utils.cpp | 26 ++++++++++++++++++++ Telegram/SourceFiles/layout/layout_utils.h | 21 ++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 Telegram/SourceFiles/layout/layout_utils.cpp create mode 100644 Telegram/SourceFiles/layout/layout_utils.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index ae16f1916..d82446828 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -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 diff --git a/Telegram/SourceFiles/layout/layout_utils.cpp b/Telegram/SourceFiles/layout/layout_utils.cpp new file mode 100644 index 000000000..5dfe6e645 --- /dev/null +++ b/Telegram/SourceFiles/layout/layout_utils.cpp @@ -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 diff --git a/Telegram/SourceFiles/layout/layout_utils.h b/Telegram/SourceFiles/layout/layout_utils.h new file mode 100644 index 000000000..c9266cf93 --- /dev/null +++ b/Telegram/SourceFiles/layout/layout_utils.h @@ -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