Commit 92236ccf authored by Viktor Lidholt's avatar Viktor Lidholt

Fixes sprite label so it doesn't use a fixed max width

parent 9a21cbc7
...@@ -29,28 +29,28 @@ class Label extends Node { ...@@ -29,28 +29,28 @@ class Label extends Node {
TextPainter _painter; TextPainter _painter;
double _width; double _width;
final double _maxWidth = 10000.0;
void paint(PaintingCanvas canvas) { void paint(PaintingCanvas canvas) {
if (_painter == null) { if (_painter == null) {
PlainTextSpan textSpan = new PlainTextSpan(_text); PlainTextSpan textSpan = new PlainTextSpan(_text);
StyledTextSpan styledTextSpan = new StyledTextSpan(_textStyle, [textSpan]); StyledTextSpan styledTextSpan = new StyledTextSpan(_textStyle, [textSpan]);
_painter = new TextPainter(styledTextSpan); _painter = new TextPainter(styledTextSpan);
_painter.maxWidth = _maxWidth; _painter.maxWidth = double.INFINITY;
_painter.minWidth = _maxWidth; _painter.minWidth = 0.0;
_painter.layout(); _painter.layout();
_width = _painter.maxContentWidth; _width = _painter.maxContentWidth.ceil().toDouble();
_painter.maxWidth = _width;
_painter.minWidth = _width;
_painter.layout();
} }
Offset offset = Offset.zero; Offset offset = Offset.zero;
if (_textStyle.textAlign == TextAlign.center) { if (_textStyle.textAlign == TextAlign.center) {
//canvas.translate(-_maxWidth / 2.0, 0.0); offset = new Offset(-_width / 2.0, 0.0);
offset = new Offset(-_maxWidth / 2.0, 0.0);
} else if (_textStyle.textAlign == TextAlign.right) { } else if (_textStyle.textAlign == TextAlign.right) {
//canvas.translate(-_maxWidth, 0.0); offset = new Offset(-_width, 0.0);
offset = new Offset(-_maxWidth, 0.0);
} }
_painter.paint(canvas, offset); _painter.paint(canvas, offset);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment