Adding new text related components and upgrading old components to use the new features like anchor

This commit is contained in:
Luan Nico
2019-01-01 22:48:08 -02:00
parent 307e375378
commit 8dacfc90a6
8 changed files with 239 additions and 78 deletions

View File

@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:ui';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart' as material;
import 'package:flutter/services.dart';
import 'position.dart';
@ -49,43 +48,6 @@ class Util {
});
}
/// Returns a [material.TextPainter] that allows for text rendering and size measuring.
///
/// Rendering text on the Canvas is not as trivial as it should.
/// This methods exposes all possible parameters you might want to pass to render text, with sensible defaults.
/// Only the [text] is mandatory.
/// It returns a [material.TextPainter]. that have the properties: paint, width and height.
/// Example usage:
///
/// final tp = Flame.util.text('Score: $score', fontSize: 48.0, fontFamily: 'Awesome Font');
/// tp.paint(c, Offset(size.width - p.width - 10, size.height - p.height - 10));
///
material.TextPainter text(
String text, {
double fontSize: 24.0,
Color color: material.Colors.black,
String fontFamily: 'Arial',
TextAlign textAlign: TextAlign.left,
TextDirection textDirection: TextDirection.ltr,
}) {
material.TextStyle style = new material.TextStyle(
color: color,
fontSize: fontSize,
fontFamily: fontFamily,
);
material.TextSpan span = new material.TextSpan(
style: style,
text: text,
);
material.TextPainter tp = new material.TextPainter(
text: span,
textAlign: textAlign,
textDirection: textDirection,
);
tp.layout();
return tp;
}
/// This properly binds a gesture recognizer to your game.
///
/// Use this in order to get it to work in case your app also contains other widgets.