feat: add message bubble radius slider

This commit is contained in:
Ireina
2026-04-04 03:14:17 +03:00
committed by AlexeyZavar
parent b83533637d
commit 969cc0778b
10 changed files with 173 additions and 33 deletions
@@ -28,6 +28,9 @@ rpl::lifetime PaletteChangedLifetime;
std::array<std::array<QImage, 4>, kCachedCornerRadiusCount> CachedMasks;
[[nodiscard]] std::array<QImage, 4> PrepareCorners(int32 radius, const QBrush &brush, const style::color *shadow = nullptr) {
if (radius <= 0) {
return {};
}
int32 r = radius * style::DevicePixelRatio(), s = st::msgShadow * style::DevicePixelRatio();
QImage rect(r * 3, r * 3 + (shadow ? s : 0), QImage::Format_ARGB32_Premultiplied);
rect.fill(Qt::transparent);
@@ -17,10 +17,41 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Ui {
namespace {
constexpr auto kBubbleRadiusSliderMax = 16;
int AppliedBubbleRadius = 16;
int BubbleRadiusOverride = -1;
[[nodiscard]] int ClampBubbleRadiusValue(int value) {
return (value < 0)
? 0
: (value > kBubbleRadiusSliderMax)
? kBubbleRadiusSliderMax
: value;
}
[[nodiscard]] int EffectiveBubbleRadiusValue() {
return (BubbleRadiusOverride >= 0)
? BubbleRadiusOverride
: AppliedBubbleRadius;
}
[[nodiscard]] int MapBubbleRadius(int sliderValue, int maximum) {
if (sliderValue <= 0 || maximum <= 0) {
return 0;
} else if (sliderValue >= kBubbleRadiusSliderMax) {
return maximum;
}
const auto result = (sliderValue * maximum + (kBubbleRadiusSliderMax / 2))
/ kBubbleRadiusSliderMax;
return (result < 0) ? 0 : (result > maximum) ? maximum : result;
}
base::options::toggle UseSmallMsgBubbleRadius({
.id = kOptionUseSmallMsgBubbleRadius,
.name = "Use small message bubble radius",
.description = "Makes most message bubbles square-ish.",
.scope = static_cast<base::options::details::ScopeFlag>(0),
.restartRequired = true,
});
@@ -28,34 +59,60 @@ base::options::toggle UseSmallMsgBubbleRadius({
const char kOptionUseSmallMsgBubbleRadius[] = "use-small-msg-bubble-radius";
void SetAppliedBubbleRadius(int value) {
AppliedBubbleRadius = ClampBubbleRadiusValue(value);
}
void SetBubbleRadiusOverride(int value) {
BubbleRadiusOverride = ClampBubbleRadiusValue(value);
}
void ClearBubbleRadiusOverride() {
BubbleRadiusOverride = -1;
}
int BubbleRadiusSmall() {
return st::bubbleRadiusSmall;
static auto cachedValue = -1;
static auto cachedRadius = st::bubbleRadiusSmall;
const auto value = EffectiveBubbleRadiusValue();
if (cachedValue != value) {
cachedValue = value;
cachedRadius = MapBubbleRadius(value, st::bubbleRadiusSmall);
}
return cachedRadius;
}
int BubbleRadiusLarge() {
static const auto result = [] {
if (UseSmallMsgBubbleRadius.value()) {
return st::bubbleRadiusSmall;
} else {
return st::bubbleRadiusLarge;
}
}();
return result;
static auto cachedValue = -1;
static auto cachedRadius = st::bubbleRadiusLarge;
const auto value = EffectiveBubbleRadiusValue();
if (cachedValue != value) {
cachedValue = value;
cachedRadius = MapBubbleRadius(value, st::bubbleRadiusLarge);
}
return cachedRadius;
}
int MsgFileThumbRadiusSmall() {
return st::msgFileThumbRadiusSmall;
static auto cachedValue = -1;
static auto cachedRadius = st::msgFileThumbRadiusSmall;
const auto value = EffectiveBubbleRadiusValue();
if (cachedValue != value) {
cachedValue = value;
cachedRadius = MapBubbleRadius(value, st::msgFileThumbRadiusSmall);
}
return cachedRadius;
}
int MsgFileThumbRadiusLarge() {
static const auto result = [] {
if (UseSmallMsgBubbleRadius.value()) {
return st::msgFileThumbRadiusSmall;
} else {
return st::msgFileThumbRadiusLarge;
}
}();
return result;
static auto cachedValue = -1;
static auto cachedRadius = st::msgFileThumbRadiusLarge;
const auto value = EffectiveBubbleRadiusValue();
if (cachedValue != value) {
cachedValue = value;
cachedRadius = MapBubbleRadius(value, st::msgFileThumbRadiusLarge);
}
return cachedRadius;
}
}
@@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Ui {
void SetAppliedBubbleRadius(int value);
void SetBubbleRadiusOverride(int value);
void ClearBubbleRadiusOverride();
[[nodiscard]] int BubbleRadiusSmall();
[[nodiscard]] int BubbleRadiusLarge();