Improve quotes / code blocks geometries.

This commit is contained in:
John Preston 2023-10-13 18:24:22 +04:00
parent 9661bac876
commit 575684670c
11 changed files with 29 additions and 30 deletions

View File

@ -1622,8 +1622,8 @@ void Message::paintText(
.position = trect.topLeft(), .position = trect.topLeft(),
.availableWidth = trect.width(), .availableWidth = trect.width(),
.palette = &stm->textPalette, .palette = &stm->textPalette,
.pre = stm->preBlockCache.get(), .pre = stm->preCache.get(),
.blockquote = stm->blockquoteBlockCache.get(), .blockquote = stm->blockquoteCache.get(),
.colors = context.st->highlightColors(), .colors = context.st->highlightColors(),
.spoiler = Ui::Text::DefaultSpoilerCache(), .spoiler = Ui::Text::DefaultSpoilerCache(),
.now = context.now, .now = context.now,

View File

@ -748,8 +748,8 @@ void Document::draw(
.position = { st::msgPadding.left(), captiontop }, .position = { st::msgPadding.left(), captiontop },
.availableWidth = captionw, .availableWidth = captionw,
.palette = &stm->textPalette, .palette = &stm->textPalette,
.pre = stm->preBlockCache.get(), .pre = stm->preCache.get(),
.blockquote = stm->blockquoteBlockCache.get(), .blockquote = stm->blockquoteCache.get(),
.colors = context.st->highlightColors(), .colors = context.st->highlightColors(),
.spoiler = Ui::Text::DefaultSpoilerCache(), .spoiler = Ui::Text::DefaultSpoilerCache(),
.now = context.now, .now = context.now,

View File

@ -235,8 +235,8 @@ void ExtendedPreview::draw(Painter &p, const PaintContext &context) const {
painty + painth + st::mediaCaptionSkip), painty + painth + st::mediaCaptionSkip),
.availableWidth = captionw, .availableWidth = captionw,
.palette = &stm->textPalette, .palette = &stm->textPalette,
.pre = stm->preBlockCache.get(), .pre = stm->preCache.get(),
.blockquote = stm->blockquoteBlockCache.get(), .blockquote = stm->blockquoteCache.get(),
.colors = context.st->highlightColors(), .colors = context.st->highlightColors(),
.spoiler = Ui::Text::DefaultSpoilerCache(), .spoiler = Ui::Text::DefaultSpoilerCache(),
.now = context.now, .now = context.now,

View File

@ -709,8 +709,8 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
.position = QPoint(st::msgPadding.left(), top), .position = QPoint(st::msgPadding.left(), top),
.availableWidth = captionw, .availableWidth = captionw,
.palette = &stm->textPalette, .palette = &stm->textPalette,
.pre = stm->preBlockCache.get(), .pre = stm->preCache.get(),
.blockquote = stm->blockquoteBlockCache.get(), .blockquote = stm->blockquoteCache.get(),
.colors = context.st->highlightColors(), .colors = context.st->highlightColors(),
.spoiler = Ui::Text::DefaultSpoilerCache(), .spoiler = Ui::Text::DefaultSpoilerCache(),
.now = context.now, .now = context.now,

View File

@ -367,8 +367,8 @@ void GroupedMedia::draw(Painter &p, const PaintContext &context) const {
captiony), captiony),
.availableWidth = captionw, .availableWidth = captionw,
.palette = &stm->textPalette, .palette = &stm->textPalette,
.pre = stm->preBlockCache.get(), .pre = stm->preCache.get(),
.blockquote = stm->blockquoteBlockCache.get(), .blockquote = stm->blockquoteCache.get(),
.colors = context.st->highlightColors(), .colors = context.st->highlightColors(),
.spoiler = Ui::Text::DefaultSpoilerCache(), .spoiler = Ui::Text::DefaultSpoilerCache(),
.now = context.now, .now = context.now,

View File

@ -405,8 +405,8 @@ void Photo::draw(Painter &p, const PaintContext &context) const {
.position = QPoint(st::msgPadding.left(), top), .position = QPoint(st::msgPadding.left(), top),
.availableWidth = captionw, .availableWidth = captionw,
.palette = &stm->textPalette, .palette = &stm->textPalette,
.pre = stm->preBlockCache.get(), .pre = stm->preCache.get(),
.blockquote = stm->blockquoteBlockCache.get(), .blockquote = stm->blockquoteCache.get(),
.colors = context.st->highlightColors(), .colors = context.st->highlightColors(),
.spoiler = Ui::Text::DefaultSpoilerCache(), .spoiler = Ui::Text::DefaultSpoilerCache(),
.now = context.now, .now = context.now,

View File

@ -78,8 +78,8 @@ private:
[[nodiscard]] style::font scaled( [[nodiscard]] style::font scaled(
const style::font &value, const style::font &value,
int size) const; int size) const;
[[nodiscard]] style::ParagraphStyle scaled( [[nodiscard]] style::QuoteStyle scaled(
const style::ParagraphStyle &value) const; const style::QuoteStyle &value) const;
[[nodiscard]] style::TextStyle scaled( [[nodiscard]] style::TextStyle scaled(
const style::TextStyle &value, const style::TextStyle &value,
int fontSize) const; int fontSize) const;
@ -327,8 +327,7 @@ style::font Preview::scaled(const style::font &font, int size) const {
return style::font(scaled(size), font->flags(), font->family()); return style::font(scaled(size), font->flags(), font->family());
} }
style::ParagraphStyle Preview::scaled( style::QuoteStyle Preview::scaled(const style::QuoteStyle &value) const {
const style::ParagraphStyle &value) const {
return { return {
.padding = scaled(value.padding), .padding = scaled(value.padding),
.verticalSkip = scaled(value.verticalSkip), .verticalSkip = scaled(value.verticalSkip),

View File

@ -40,19 +40,19 @@ msgDateDelta: point(2px, 5px);
msgDateImgDelta: 4px; msgDateImgDelta: 4px;
msgDateImgPadding: point(8px, 2px); msgDateImgPadding: point(8px, 2px);
messageParagraphStyle: ParagraphStyle(defaultParagraphStyle) { messageQuoteStyle: QuoteStyle(defaultQuoteStyle) {
padding: margins(10px, 2px, 4px, 2px); padding: margins(10px, 2px, 4px, 2px);
verticalSkip: 4px; verticalSkip: 4px;
outline: 3px; outline: 3px;
radius: 5px; radius: 5px;
} }
messageTextStyle: TextStyle(defaultTextStyle) { messageTextStyle: TextStyle(defaultTextStyle) {
blockquote: ParagraphStyle(messageParagraphStyle) { blockquote: QuoteStyle(messageQuoteStyle) {
padding: margins(10px, 2px, 20px, 2px); padding: margins(10px, 2px, 20px, 2px);
icon: icon{{ "chat/mini_quote", windowFg }}; icon: icon{{ "chat/mini_quote", windowFg }};
iconPosition: point(4px, 2px); iconPosition: point(4px, 2px);
} }
pre: ParagraphStyle(messageParagraphStyle) { pre: QuoteStyle(messageQuoteStyle) {
header: 20px; header: 20px;
headerPosition: point(10px, 2px); headerPosition: point(10px, 2px);
scrollable: true; scrollable: true;

View File

@ -30,12 +30,12 @@ void EnsureCorners(
} }
void EnsureBlockquoteCache( void EnsureBlockquoteCache(
std::unique_ptr<Text::BlockPaintCache> &cache, std::unique_ptr<Text::QuotePaintCache> &cache,
const style::color &color) { const style::color &color) {
if (cache) { if (cache) {
return; return;
} }
cache = std::make_unique<Text::BlockPaintCache>(); cache = std::make_unique<Text::QuotePaintCache>();
cache->bg = color->c; cache->bg = color->c;
cache->bg.setAlphaF(0.12); cache->bg.setAlphaF(0.12);
cache->outline = color->c; cache->outline = color->c;
@ -44,13 +44,13 @@ void EnsureBlockquoteCache(
} }
void EnsurePreCache( void EnsurePreCache(
std::unique_ptr<Text::BlockPaintCache> &cache, std::unique_ptr<Text::QuotePaintCache> &cache,
const style::color &color, const style::color &color,
Fn<std::optional<QColor>()> bgOverride) { Fn<std::optional<QColor>()> bgOverride) {
if (cache) { if (cache) {
return; return;
} }
cache = std::make_unique<Text::BlockPaintCache>(); cache = std::make_unique<Text::QuotePaintCache>();
const auto bg = bgOverride(); const auto bg = bgOverride();
cache->bg = bg.value_or(color->c); cache->bg = bg.value_or(color->c);
if (!bg) { if (!bg) {
@ -521,8 +521,8 @@ void ChatStyle::assignPalette(not_null<const style::palette*> palette) {
for (auto &style : _messageStyles) { for (auto &style : _messageStyles) {
style.msgBgCornersSmall = {}; style.msgBgCornersSmall = {};
style.msgBgCornersLarge = {}; style.msgBgCornersLarge = {};
style.blockquoteBlockCache = nullptr; style.blockquoteCache = nullptr;
style.preBlockCache = nullptr; style.preCache = nullptr;
} }
for (auto &style : _imageStyles) { for (auto &style : _imageStyles) {
style.msgDateImgBgCorners = {}; style.msgDateImgBgCorners = {};
@ -578,7 +578,7 @@ const MessageStyle &ChatStyle::messageStyle(bool outbg, bool selected) const {
result.msgBg, result.msgBg,
&result.msgShadow); &result.msgShadow);
EnsureBlockquoteCache( EnsureBlockquoteCache(
result.blockquoteBlockCache, result.blockquoteCache,
result.msgReplyBarColor); result.msgReplyBarColor);
const auto preBgOverride = [&] { const auto preBgOverride = [&] {
@ -589,7 +589,7 @@ const MessageStyle &ChatStyle::messageStyle(bool outbg, bool selected) const {
return dark ? QColor(0, 0, 0, 192) : std::optional<QColor>(); return dark ? QColor(0, 0, 0, 192) : std::optional<QColor>();
}; };
EnsurePreCache( EnsurePreCache(
result.preBlockCache, result.preCache,
(selected (selected
? result.textPalette.selectMonoFg ? result.textPalette.selectMonoFg
: result.textPalette.monoFg), : result.textPalette.monoFg),

View File

@ -76,8 +76,8 @@ struct MessageStyle {
style::icon historyPollChoiceRight = { Qt::Uninitialized }; style::icon historyPollChoiceRight = { Qt::Uninitialized };
style::icon historyTranscribeIcon = { Qt::Uninitialized }; style::icon historyTranscribeIcon = { Qt::Uninitialized };
style::icon historyTranscribeHide = { Qt::Uninitialized }; style::icon historyTranscribeHide = { Qt::Uninitialized };
std::unique_ptr<Text::BlockPaintCache> blockquoteBlockCache; std::unique_ptr<Text::QuotePaintCache> blockquoteCache;
std::unique_ptr<Text::BlockPaintCache> preBlockCache; std::unique_ptr<Text::QuotePaintCache> preCache;
}; };

@ -1 +1 @@
Subproject commit 46465fc5ce14c4ca356870f0a8d51eb0285112a9 Subproject commit 9eb9fcf043276bb3a73f1fc25531e4f4862d6fc9