Merge pull request #524 from and3md/text_fixes

Fixes for TextWidget/MultilineTextWidget
This commit is contained in:
Vadim Lopatin 2017-11-30 11:41:05 +03:00 committed by GitHub
commit 29aa9ab6c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 4 deletions

View File

@ -115,16 +115,23 @@ class TextWidget : Widget {
return this;
}
private CalcSaver!(Font, dstring, uint, uint) _measureSaver;
private CalcSaver!(Font, dstring, uint, uint, int) _measureSaver;
override void measure(int parentWidth, int parentHeight) {
FontRef font = font();
uint w = (maxLines == 1) ? MAX_WIDTH_UNSPECIFIED :
parentWidth - margins.left - margins.right - padding.left - padding.right;
uint w;
if (maxLines == 1)
w = MAX_WIDTH_UNSPECIFIED;
else {
w = parentWidth - margins.left - margins.right - padding.left - padding.right;
if (maxWidth > 0 && maxWidth < w)
w = maxWidth - padding.left - padding.right;
}
uint flags = textFlags;
// optimization: do not measure if nothing changed
if (_measureSaver.check(font.get, text, w, flags) || _needLayout) {
if (_measureSaver.check(font.get, text, w, flags, maxLines) || _needLayout) {
Point sz;
if (maxLines == 1) {
sz = font.textSize(text, w, 4, 0, flags);