emotes now have less margin

This commit is contained in:
2017-12-28 17:46:36 +01:00
parent e0bdc5ccf9
commit 1940b0197c
2 changed files with 34 additions and 14 deletions

View file

@ -8,6 +8,7 @@
#define MARGIN_RIGHT (int)(8 * this->scale) #define MARGIN_RIGHT (int)(8 * this->scale)
#define MARGIN_TOP (int)(4 * this->scale) #define MARGIN_TOP (int)(4 * this->scale)
#define MARGIN_BOTTOM (int)(4 * this->scale) #define MARGIN_BOTTOM (int)(4 * this->scale)
#define COMPACT_EMOTES_OFFSET 6
using namespace chatterino::messages; using namespace chatterino::messages;
@ -96,6 +97,8 @@ void MessageRef::actuallyLayout(int width)
const int spaceWidth = 4; const int spaceWidth = 4;
const int right = width - MARGIN_RIGHT; const int right = width - MARGIN_RIGHT;
bool overlapEmotes = true;
// clear word parts // clear word parts
this->wordParts.clear(); this->wordParts.clear();
@ -137,7 +140,7 @@ void MessageRef::actuallyLayout(int width)
// word wrapping // word wrapping
if (word.isText() && word.getWidth(this->scale) + MARGIN_LEFT > right) { if (word.isText() && word.getWidth(this->scale) + MARGIN_LEFT > right) {
// align and end the current line // align and end the current line
alignWordParts(lineStart, lineHeight, width, firstLineHeight); this->_alignWordParts(lineStart, lineHeight, width, firstLineHeight);
y += lineHeight; y += lineHeight;
int currentPartStart = 0; int currentPartStart = 0;
@ -172,10 +175,8 @@ void MessageRef::actuallyLayout(int width)
lineNumber, mid, mid, true, currentPartStart)); lineNumber, mid, mid, true, currentPartStart));
x = currentLineWidth + MARGIN_LEFT + spaceWidth; x = currentLineWidth + MARGIN_LEFT + spaceWidth;
lineHeight = word.getHeight(this->scale); lineHeight = this->_updateLineHeight(0, word, overlapEmotes);
lineStart = this->wordParts.size() - 1; lineStart = this->wordParts.size() - 1;
first = false;
} }
// fits in the current line // fits in the current line
else if (first || x + word.getWidth(this->scale) + xOffset <= right) { else if (first || x + word.getWidth(this->scale) + xOffset <= right) {
@ -185,14 +186,12 @@ void MessageRef::actuallyLayout(int width)
x += word.getWidth(this->scale) + xOffset; x += word.getWidth(this->scale) + xOffset;
x += spaceWidth; x += spaceWidth;
lineHeight = std::max(word.getHeight(this->scale), lineHeight); lineHeight = this->_updateLineHeight(lineHeight, word, overlapEmotes);
first = false;
} }
// doesn't fit in the line // doesn't fit in the line
else { else {
// align and end the current line // align and end the current line
alignWordParts(lineStart, lineHeight, width, firstLineHeight); this->_alignWordParts(lineStart, lineHeight, width, firstLineHeight);
y += lineHeight; y += lineHeight;
@ -203,15 +202,17 @@ void MessageRef::actuallyLayout(int width)
lineStart = this->wordParts.size() - 1; lineStart = this->wordParts.size() - 1;
lineHeight = word.getHeight(this->scale); lineHeight = this->_updateLineHeight(0, word, overlapEmotes);
x = word.getWidth(this->scale) + MARGIN_LEFT; x = word.getWidth(this->scale) + MARGIN_LEFT;
x += spaceWidth; x += spaceWidth;
} }
first = false;
} }
// align and end the current line // align and end the current line
alignWordParts(lineStart, lineHeight, width, firstLineHeight); this->_alignWordParts(lineStart, lineHeight, width, firstLineHeight);
this->collapsedHeight = firstLineHeight == -1 ? (int)(24 * this->scale) this->collapsedHeight = firstLineHeight == -1 ? (int)(24 * this->scale)
: firstLineHeight + MARGIN_TOP + MARGIN_BOTTOM; : firstLineHeight + MARGIN_TOP + MARGIN_BOTTOM;
@ -259,8 +260,10 @@ const std::vector<WordPart> &MessageRef::getWordParts() const
return this->wordParts; return this->wordParts;
} }
void MessageRef::alignWordParts(int lineStart, int lineHeight, int width, int &firstLineHeight) void MessageRef::_alignWordParts(int lineStart, int lineHeight, int width, int &firstLineHeight)
{ {
bool compactEmotes = true;
if (firstLineHeight == -1) { if (firstLineHeight == -1) {
firstLineHeight = lineHeight; firstLineHeight = lineHeight;
} }
@ -272,12 +275,28 @@ void MessageRef::alignWordParts(int lineStart, int lineHeight, int width, int &f
} }
for (size_t i = lineStart; i < this->wordParts.size(); i++) { for (size_t i = lineStart; i < this->wordParts.size(); i++) {
WordPart &wordPart2 = this->wordParts.at(i); WordPart &wordPart = this->wordParts.at(i);
wordPart2.setPosition(wordPart2.getX() + xOffset, wordPart2.getY() + lineHeight); int yExtra = compactEmotes && wordPart.getWord().isImage()
? (COMPACT_EMOTES_OFFSET / 2) * this->scale
: 0;
wordPart.setPosition(wordPart.getX() + xOffset, wordPart.getY() + lineHeight + yExtra);
} }
} }
int MessageRef::_updateLineHeight(int currentLineHeight, Word &word, bool compactEmotes)
{
int newLineHeight = word.getHeight(this->scale);
// fourtf: doesn't care about the height of a normal line
if (compactEmotes && word.isImage()) {
newLineHeight -= COMPACT_EMOTES_OFFSET * this->scale;
}
return std::max(currentLineHeight, newLineHeight);
}
const Word *MessageRef::tryGetWordPart(QPoint point) const Word *MessageRef::tryGetWordPart(QPoint point)
{ {
// go through all words and return the first one that contains the point. // go through all words and return the first one that contains the point.

View file

@ -58,7 +58,8 @@ private:
// methods // methods
void rebuild(); void rebuild();
void actuallyLayout(int width); void actuallyLayout(int width);
void alignWordParts(int lineStart, int lineHeight, int width, int &firstLineHeight); void _alignWordParts(int lineStart, int lineHeight, int width, int &firstLineHeight);
int _updateLineHeight(int currentLineHeight, Word &word, bool overlapEmotes);
void updateTextSizes(); void updateTextSizes();
void updateImageSizes(); void updateImageSizes();
}; };