Move some style code to lib_ui.

This commit is contained in:
John Preston
2019-09-13 13:24:06 +03:00
parent 5a1c8e6a0a
commit e2f54eb3e9
69 changed files with 1119 additions and 856 deletions

View File

@@ -7,6 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "ui/style/style_core.h"
#include "emoji.h"
#define DeclareReadSetting(Type, Name) extern Type g##Name; \
inline const Type &c##Name() { \
return g##Name; \
@@ -22,10 +25,9 @@ inline Type &cRef##Name() { \
return g##Name; \
}
DeclareSetting(bool, Rtl);
DeclareSetting(Qt::LayoutDirection, LangDir);
inline bool rtl() {
return cRtl();
return style::RightToLeft();
}
DeclareSetting(bool, InstallBetaVersion);
@@ -94,19 +96,6 @@ DeclareSetting(int, ScreenScale);
DeclareSetting(int, ConfigScale);
DeclareSetting(QString, TimeFormat);
inline void cChangeTimeFormat(const QString &newFormat) {
if (!newFormat.isEmpty()) cSetTimeFormat(newFormat);
}
namespace Ui {
namespace Emoji {
class One;
} // namespace Emoji
} // namespace Ui
using EmojiPtr = const Ui::Emoji::One*;
using EmojiPack = QVector<EmojiPtr>;
using RecentEmojiPreloadOldOld = QVector<QPair<uint32, ushort>>;
using RecentEmojiPreloadOld = QVector<QPair<uint64, ushort>>;
using RecentEmojiPreload = QVector<QPair<QString, ushort>>;
@@ -138,6 +127,20 @@ DeclareSetting(bool, PasswordRecovered);
DeclareSetting(int32, PasscodeBadTries);
DeclareSetting(crl::time, PasscodeLastTry);
DeclareSetting(QStringList, SendPaths);
DeclareSetting(QString, StartUrl);
DeclareSetting(int, OtherOnline);
inline void cChangeTimeFormat(const QString &newFormat) {
if (!newFormat.isEmpty()) cSetTimeFormat(newFormat);
}
RecentEmojiPack &GetRecentEmoji();
QVector<EmojiPtr> GetRecentEmojiSection();
void AddRecentEmoji(EmojiPtr emoji);
[[nodiscard]] rpl::producer<> UpdatedRecentEmoji();
inline bool passcodeCanTry() {
if (cPasscodeBadTries() < 3) return true;
auto dt = crl::now() - cPasscodeLastTry();
@@ -151,46 +154,27 @@ inline bool passcodeCanTry() {
return dt >= 30000;
}
DeclareSetting(QStringList, SendPaths);
DeclareSetting(QString, StartUrl);
inline float64 cRetinaFactor() {
return style::DevicePixelRatio();
}
DeclareSetting(float64, RetinaFactor);
DeclareSetting(int32, IntRetinaFactor);
DeclareSetting(int, OtherOnline);
constexpr auto kInterfaceScaleAuto = 0;
constexpr auto kInterfaceScaleMin = 100;
constexpr auto kInterfaceScaleDefault = 100;
constexpr auto kInterfaceScaleMax = 300;
inline int32 cIntRetinaFactor() {
return style::DevicePixelRatio();
}
inline int cEvalScale(int scale) {
return (scale == kInterfaceScaleAuto) ? cScreenScale() : scale;
return (scale == style::kScaleAuto) ? cScreenScale() : scale;
}
inline int cScale() {
return cEvalScale(cConfigScale());
}
template <typename T>
inline T ConvertScale(T value, int scale) {
return (value < 0.)
? (-ConvertScale(-value, scale))
: T(std::round((float64(value) * scale / 100.) - 0.01));
}
template <typename T>
inline T ConvertScale(T value) {
return ConvertScale(value, cScale());
}
inline QSize ConvertScale(QSize size) {
return QSize(ConvertScale(size.width()), ConvertScale(size.height()));
return style::Scale();
}
inline void SetScaleChecked(int scale) {
const auto checked = (scale == kInterfaceScaleAuto)
? kInterfaceScaleAuto
: snap(scale, kInterfaceScaleMin, kInterfaceScaleMax / cIntRetinaFactor());
cSetConfigScale(checked);
cSetConfigScale(style::CheckScale(scale));
}
inline void ValidateScale() {
SetScaleChecked(cConfigScale());
style::SetScale(cEvalScale(cConfigScale()));
}