Skip to content

Commit e6cb8f0

Browse files
author
CamronG
committed
add typeface support
1 parent 47a10b4 commit e6cb8f0

16 files changed

+386
-297
lines changed

configurator/bin/configurator.dart

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ Future<void> generateConfigurations({
149149
FileUtils.writeFile(
150150
path: outputFilePath,
151151
content: DartFormatter().format( await result.write() ),
152+
// content: await result.write(),
152153
);
153154

154155
print( outputFilePath );

configurator/lib/configurator.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library configurator;
22

3-
export 'src/models/typeface.dart';
3+
export 'src/models/yaml_text_style.dart';
44
export 'src/scopes/scope.dart';
55
export 'src/scopes/proxy.dart';
66
export 'src/configuration.dart';

configurator/lib/src/configuration.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ class Configuration {
107107
})?.misc[ id ];
108108
}
109109

110-
dynamic typefaces( String id ) {
110+
Map<String, dynamic> textStyle( String id ) {
111111
return _scopesSorted.reversed.firstWhereOrNull( ( s ) {
112-
return s.typefaces.containsKey( id );
113-
})?.misc[ id ];
112+
return s.textStyles.containsKey( id );
113+
})?.textStyles[ id ];
114114
}
115115

116116
double size( String id ) {

configurator/lib/src/models/processed_config.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import 'package:configurator/src/writers/slang_writer.dart';
1717
import 'package:configurator/src/writers/theme_writer.dart';
1818
import 'package:configurator/src/writers/weight_writer.dart';
1919

20-
import '../writers/typeface_writer.dart';
20+
import '../writers/text_style_writer.dart';
2121

2222
class ProcessedConfig {
2323

@@ -37,7 +37,7 @@ class ProcessedConfig {
3737
Directive.import( 'package:slang/builder/model/node.dart' ),
3838
Directive.export( 'package:slang_flutter/slang_flutter.dart' ),
3939
]);
40-
40+
4141
builder.body.addAll([
4242

4343
TitleWriter( 'Color Util' ).write(),
@@ -76,8 +76,8 @@ class ProcessedConfig {
7676
TitleWriter( 'Misc' ).write(),
7777
MiscWriter( frameworkName, yamlConfiguration.misc ).write(),
7878

79-
TitleWriter( 'Typefaces' ).write(),
80-
TypefaceWriter( frameworkName, yamlConfiguration.typefaces ).write(),
79+
TitleWriter( 'TextStyles' ).write(),
80+
TextStyleWriter( frameworkName, yamlConfiguration.textStyles ).write(),
8181

8282
TitleWriter( 'Slang (i18n)' ).write(),
8383
SlangWriter( yamlConfiguration.strings ).write(),

configurator/lib/src/models/typeface.dart

-28
This file was deleted.

configurator/lib/src/models/yaml_configuration.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ class YamlConfiguration {
1111
final List<YamlSetting> colors;
1212
final List<YamlSetting> images;
1313
final List<YamlSetting> misc;
14-
final List<YamlSetting> typefaces;
1514
final List<YamlSetting> sizes;
1615
final List<YamlSetting> padding;
1716
final List<YamlSetting> margins;
17+
final List<YamlTextStyle> textStyles;
1818
final List<YamlRoute> routes;
1919
final List<YamlI18n> strings;
2020

@@ -26,7 +26,7 @@ class YamlConfiguration {
2626
this.colors = const [],
2727
this.images = const [],
2828
this.misc = const [],
29-
this.typefaces = const [],
29+
this.textStyles = const [],
3030
this.sizes = const [],
3131
this.routes = const [],
3232
this.strings = const [],
@@ -41,7 +41,7 @@ class YamlConfiguration {
4141
'flags': { for (var e in flags) e.name: e.value},
4242
'images': { for (var e in images) e.name: e.value},
4343
'misc': { for (var e in misc) e.name: e.value},
44-
'typefaces': { for (var e in typefaces) e.name: e.value},
44+
'textStyles': { for (var e in textStyles) e.key: e.toJson()},
4545
'sizes': { for (var e in sizes) e.name: e.value},
4646
'colors': { for (var e in colors) e.name: e.value},
4747
'routes': { for (var e in routes) e.id : e.path },
@@ -55,8 +55,8 @@ class YamlConfiguration {
5555
misc.removeWhere(( e ) => t.misc.contains( e ));
5656
misc.addAll( t.misc );
5757

58-
typefaces.removeWhere(( e ) => t.typefaces.contains( e ));
59-
typefaces.addAll( t.typefaces );
58+
textStyles.removeWhere(( e ) => t.textStyles.contains( e ));
59+
textStyles.addAll( t.textStyles );
6060

6161
padding.removeWhere(( e ) => t.padding.contains( e ));
6262
padding.addAll( t.padding );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class YamlTextStyle {
2+
final String key;
3+
final String color;
4+
final int size;
5+
final int weight;
6+
7+
final Map<String, String> typeface;
8+
9+
/// Model containing TextStyle information
10+
YamlTextStyle({
11+
required this.key,
12+
required this.color,
13+
required this.size,
14+
required this.weight,
15+
required this.typeface,
16+
});
17+
18+
factory YamlTextStyle.fromJson(Map json) => YamlTextStyle(
19+
key: json['key'] as String,
20+
color: json['color'] as String,
21+
size: json['size'] as int,
22+
weight: json['weight'] as int,
23+
typeface: json['typeface'] as Map<String, String>,
24+
);
25+
26+
Map<String, dynamic> toJson() => <String, dynamic>{
27+
'key': key,
28+
'color': color,
29+
'size': size,
30+
'weight': weight,
31+
'typeface': typeface,
32+
};
33+
}

configurator/lib/src/scopes/proxy.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ProxyScope extends ConfigScope {
3535
Map<String, dynamic> misc;
3636

3737
@override
38-
Map<String, dynamic> typefaces;
38+
Map<String, dynamic> textStyles;
3939

4040
ProxyScope({
4141
required this.name,
@@ -49,6 +49,6 @@ class ProxyScope extends ConfigScope {
4949
this.padding = const {},
5050
this.margins = const {},
5151
this.misc = const {},
52-
this.typefaces = const {},
52+
this.textStyles = const {},
5353
});
5454
}

configurator/lib/src/scopes/scope.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ abstract class ConfigScope {
1515
Map<String, double> get padding;
1616
Map<String, double> get margins;
1717
Map<String, double> get radius => {};
18-
Map<String, dynamic> get typefaces => {};
18+
Map<String, dynamic> get textStyles => {};
1919
Map<int, String?> get routes;
2020

2121

@@ -33,7 +33,7 @@ abstract class ConfigScope {
3333
flags: { for (var e in config.flags) e.name : e.value },
3434
images: { for (var e in config.images) e.name : e.value },
3535
misc: { for (var e in config.misc) e.name : e.value },
36-
typefaces: { for (var e in config.typefaces) e.name : e.value },
36+
textStyles: { for (var e in config.textStyles) e.key : e },
3737
routes: { for (var e in config.routes) e.id : e.path },
3838
sizes: { for (var e in config.sizes) e.name : e.value },
3939
padding: { for (var e in config.padding) e.name : e.value },
@@ -48,7 +48,7 @@ abstract class ConfigScope {
4848
'flags': { for (var e in flags.entries) e.key: e.value},
4949
'images': { for (var e in images.entries) e.key: e.value},
5050
'misc': { for (var e in misc.entries) e.key: e.value},
51-
'typefaces': { for (var e in typefaces.entries) e.key: e.value},
51+
'textStyles': { for (var e in textStyles.entries) e.key: e.value},
5252
'sizes': { for (var e in sizes.entries) e.key: e.value},
5353
'padding': { for (var e in padding.entries) e.key: e.value},
5454
'margins': { for (var e in margins.entries) e.key: e.value},
@@ -66,7 +66,7 @@ abstract class ConfigScope {
6666
const ListEquality().equals( partFiles, other.partFiles ) &&
6767
const MapEquality().equals( images, other.images ) &&
6868
const MapEquality().equals( misc, other.misc ) &&
69-
const MapEquality().equals( typefaces, other.typefaces ) &&
69+
const MapEquality().equals( textStyles, other.textStyles ) &&
7070
const MapEquality().equals( routes, other.routes ) &&
7171
const MapEquality().equals( colors, other.colors ) &&
7272
const MapEquality().equals( padding, other.padding ) &&
@@ -80,7 +80,7 @@ abstract class ConfigScope {
8080
^ partFiles.hashCode
8181
^ images.hashCode
8282
^ misc.hashCode
83-
^ typefaces.hashCode
83+
^ textStyles.hashCode
8484
^ padding.hashCode
8585
^ margins.hashCode
8686
^ routes.hashCode

0 commit comments

Comments
 (0)