andyduke / styled_text_package

Text widget with formatted text using tags. Makes it easier to use formatted text in multilingual applications.
https://pub.dev/packages/styled_text
BSD 3-Clause "New" or "Revised" License
75 stars 48 forks source link

IconStyle() is limited and does not provide any properties for customization of presentation #20

Closed Zabadam closed 3 years ago

Zabadam commented 3 years ago

Rudimentary Workaround

Suggestion:

class IconStyle extends TextStyle {
    /// Icon to insert into text
    final IconData icon;
    final Color color;
    final double size;
    final Color backgroundColor;

    IconStyle(this.icon,
        {this.color = const Color(0xFFFFFFFF),    // or something
        this.size = 24,    // or something
        this.backgroundColor = const Color(0x00000000),    // or something
    });
}
if (style is IconStyle) {
    node = TextSpan(
        text: String.fromCharCode(style.icon.codePoint),
        style: TextStyle(
            fontFamily: style.icon.fontFamily,
            package: style.icon.fontPackage,
            color: style.color,
            fontSize: style.size,
            backgroundColor: style.backgroundColor,
        ),
    );
}
Zabadam commented 3 years ago

Initially I did not even have my custom icons.otf setup as an class with IconDatas, but I decided having the self-terminating <tags/> would be worth the effort.

andyduke commented 3 years ago

@Zabadam I have released a new version with these improvements.

Zabadam commented 3 years ago

@Zabadam I have released a new version with these improvements.

Rapid response. Excellent package, thank you! P.S. I ended up adding an xPadding property myself that's passed as letterSpacing (since Icons are only one 'letter' this hacks out just fine).