44import com .google .gwt .dom .client .LinkElement ;
55import gwt .material .design .client .base .HasSymbols ;
66import gwt .material .design .client .base .MaterialWidget ;
7+ import gwt .material .design .client .base .mixin .ColorsMixin ;
78import gwt .material .design .client .base .mixin .CssNameMixin ;
9+ import gwt .material .design .client .constants .Color ;
810import gwt .material .design .client .constants .SymbolType ;
911import gwt .material .design .client .ui .html .Span ;
1012
1113public class MaterialSymbol extends MaterialWidget implements HasSymbols {
1214
13- static {
14- LinkElement linkElement = Document .get ().createLinkElement ();
15- linkElement .setRel ("stylesheet" );
16- linkElement .
setHref (
"https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected] ,100..700,0..1,-50..200" );
17- body ().append (linkElement );
18- }
19-
2015 protected Span span = new Span ();
16+ protected static LinkElement linkElement = Document .get ().createLinkElement ();
2117 protected CssNameMixin <Span , SymbolType > symbolTypeMixin ;
18+ protected ColorsMixin <MaterialSymbol > symbolColorsMixin ;
2219 protected boolean filled ;
2320 protected int weight = 400 ;
2421 protected int grade = 0 ;
2522 protected int opticalSize = 48 ;
2623
24+ static {
25+ linkElement .setRel ("stylesheet" );
26+ body ().append (linkElement );
27+ }
28+
2729 public MaterialSymbol () {
2830 super (Document .get ().createElement ("div" ));
2931 setType (SymbolType .OUTLINED );
@@ -42,9 +44,20 @@ public void setSymbol(String symbol) {
4244 span .getElement ().setInnerText (symbol );
4345 }
4446
47+ @ Override
48+ public void setColor (Color color ) {
49+ getSymbolColorsMixin ().setTextColor (color );
50+ }
51+
52+ @ Override
53+ public void setSymbolSize (String size ) {
54+ span .getElement ().getStyle ().setProperty ("fontSize" , size );
55+ }
56+
4557 @ Override
4658 public void setType (SymbolType type ) {
4759 getSymbolTypeMixin ().setCssName (type );
60+ linkElement .setHref (type .getCssLink ());
4861 }
4962
5063 @ Override
@@ -68,7 +81,14 @@ public void setOpticalSize(int size) {
6881 }
6982
7083 protected void load () {
71- getElement ().setAttribute ("style" , "font-variation-settings: 'FILL' 1, 'wght' 700, 'GRAD' 0, 'opsz' 48;" );
84+ span .getElement ().getStyle ().setProperty ("fontVariationSettings" , "'FILL' " + (filled ? 1 : 0 ) + ", 'wght' " + weight + ", 'GRAD' " + grade + ", 'opsz' " + opticalSize );
85+ }
86+
87+ public ColorsMixin <MaterialSymbol > getSymbolColorsMixin () {
88+ if (symbolColorsMixin == null ) {
89+ symbolColorsMixin = new ColorsMixin <>(this );
90+ }
91+ return symbolColorsMixin ;
7292 }
7393
7494 public CssNameMixin <Span , SymbolType > getSymbolTypeMixin () {
0 commit comments