This commit is contained in:
Erick Zanardo
2020-06-30 23:49:56 -03:00
parent 32df868b5b
commit 629fbb7247
5 changed files with 15 additions and 15 deletions

View File

@ -46,7 +46,8 @@ class TextBoxComponent extends PositionComponent with Resizable {
TextBoxConfig get boxConfig => _boxConfig;
TextBoxComponent(String text, {
TextBoxComponent(
String text, {
TextConfig config,
TextBoxConfig boxConfig,
}) {

View File

@ -27,7 +27,7 @@ class TextComponent extends PositionComponent {
_updateBox();
}
TextComponent(this._text, {TextConfig config }) {
TextComponent(this._text, {TextConfig config}) {
_config = config ?? TextConfig();
_updateBox();
}

View File

@ -1,12 +1,11 @@
/// Simple class to cache values on the cache
///
class MemoryCache <K, V> {
class MemoryCache<K, V> {
final Map<K, V> _cache = {};
final List<K> _addedOrder = [];
final int cacheSize;
MemoryCache({ this.cacheSize = 10 });
MemoryCache({this.cacheSize = 10});
void setValue(K key, V value) {
if (!_cache.containsKey(key)) {

View File

@ -53,7 +53,8 @@ class TextConfig {
/// For proper fonts of languages like Hebrew or Arabic, replace this with [TextDirection.rtl].
final TextDirection textDirection;
final MemoryCache _textPainterCache = MemoryCache<String, material.TextPainter>();
final MemoryCache _textPainterCache =
MemoryCache<String, material.TextPainter>();
/// Creates a constant [TextConfig] with sensible defaults.
///
@ -98,18 +99,18 @@ class TextConfig {
material.TextPainter toTextPainter(String text) {
if (!_textPainterCache.containsKey(text)) {
final material.TextStyle style = material.TextStyle(
color: color,
fontSize: fontSize,
fontFamily: fontFamily,
color: color,
fontSize: fontSize,
fontFamily: fontFamily,
);
final material.TextSpan span = material.TextSpan(
style: style,
text: text,
style: style,
text: text,
);
final material.TextPainter tp = material.TextPainter(
text: span,
textAlign: textAlign,
textDirection: textDirection,
text: span,
textAlign: textAlign,
textDirection: textDirection,
);
tp.layout();

View File

@ -29,4 +29,3 @@ void main() {
});
});
}