Commit 3f2369db authored by Viktor Lidholt's avatar Viktor Lidholt

Initial support for labels in skysprites

parent 37d0c1a8
part of skysprites;
class Label extends Node {
Label(this._text, [this._textStyle]) {
if (_textStyle == null) {
_textStyle = new TextStyle();
}
}
String _text;
String get text => _text;
set text(String text) {
_text = text;
_painter = null;
}
TextStyle _textStyle;
TextStyle get textStyle => _textStyle;
set textStyle(TextStyle textStyle) {
_textStyle = textStyle;
_painter = null;
}
TextPainter _painter;
double _width;
final double _maxWidth = 10000.0;
void paint(PaintingCanvas canvas) {
if (_painter == null) {
PlainTextSpan textSpan = new PlainTextSpan(_text);
StyledTextSpan styledTextSpan = new StyledTextSpan(_textStyle, [textSpan]);
_painter = new TextPainter(styledTextSpan);
_painter.maxWidth = _maxWidth;
_painter.minWidth = _maxWidth;
_painter.layout();
_width = _painter.maxContentWidth;
}
Offset offset = Offset.zero;
if (_textStyle.textAlign == TextAlign.center) {
//canvas.translate(-_maxWidth / 2.0, 0.0);
offset = new Offset(-_maxWidth / 2.0, 0.0);
} else if (_textStyle.textAlign == TextAlign.right) {
//canvas.translate(-_maxWidth, 0.0);
offset = new Offset(-_maxWidth, 0.0);
}
_painter.paint(canvas, offset);
}
}
......@@ -17,6 +17,7 @@ import 'package:sky/mojo/asset_bundle.dart';
import 'package:sky/mojo/shell.dart' as shell;
import 'package:sky/rendering/box.dart';
import 'package:sky/rendering/object.dart';
import 'package:sky/painting/text_painter.dart';
import 'package:sky/widgets/framework.dart';
import 'package:sky_services/media/media.mojom.dart';
import 'package:vector_math/vector_math.dart';
......@@ -26,6 +27,7 @@ part 'constraint.dart';
part 'action_spline.dart';
part 'color_secuence.dart';
part 'image_map.dart';
part 'label.dart';
part 'layer.dart';
part 'node.dart';
part 'node3d.dart';
......
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