Closed hyobbb closed 3 years ago
I changed the _checkTextFit result like below:
bool exceedHeight = _height >= constraints.maxHeight;
bool exceedWidth = _width >= constraints.maxWidth;
if(tp.didExceedMaxLines){
return false;
} else if(exceedHeight) {
return false;
} else return true;
the original one is like this:
return !(tp.didExceedMaxLines ||
_height >= constraints.maxHeight ||
_width >= constraints.maxWidth);
The thing is that actually comparing width is not necessary because if the textspan width is larger than constraint width it will either exceed max line or exceed height constraint.
Also I changed the while loop condition like below:
int i = 1;
while (left <= right) {
var mid = (left + (right - left) / 2).toInt();
double scale;
if (presetFontSizes == null) {
scale = mid * userScale * widget.stepGranularity / style.fontSize;
} else {
scale = presetFontSizes[mid] * userScale / style.fontSize;
}
print('$i th scale : $scale');
if (_checkTextFits(span, scale, maxLines, size)) {
print('succeed : $left, $right');
left = mid + 1;
lastValueFits = true;
} else {
print('failed : $left, $right');
right = mid - 1;
left = right - 1; //!!! added line !!!
}
i++;
}
when scale doesn't fit to text I forced left to be 1 less than right so not to break the while loop until it guarantees that text would fit the size correctly. Normally it iterates 3 times more but I think it is worth.
forked version is here and any review or opinion will be welcome!
Hi @hyobbb , thank you for the detailed analysis. Do you mind creating a PR so folks can review it and merge it once everything works out?
Ok. Right now I can't afford it but maybe in 2~3weeks I could pull request. Let you know then. Thanks!
Closing issue with PR #16
Hi.
I found that when there's contents padding in input decoration parameter it doesn't expand enough to show every text. so I added some code at the end of "_checkTextFits" functions like below.
For comparing height I added extra value 30 more because when there's multi line input it doesn't expand enough vertically. In general, when you put maxLines = null and keyboardType = TextInputType.multiline, it behaves badly. For example
this is what I am testing for multiline input without minimum font so that users can type text without limitation. I think for multiline text, checking algorithm to adjust fontsize should be changed. because until the textfield expand as big as it's constraints size the given fontsize should be maintained. So in that case height and width condition should be AND.
Still, It has issues for multi line use so I will dig it more. If anyone has an idea please let me know.