Country Flags#
Note
This requires that you have the Twemoji Mozilla font installed.
While it has always been possible to display flags with images or writing your own scripts to make use of emoji, this details some helper methods which have been added to make it easier.
Title formatting#
Note
These examples assume you have a supported value inside a %country% tag. Adjust as
necessary.
A $country_flag function has been added and you can use it like this:
$font(Twemoji Mozilla,16)$country_flag(%country%)
Note
The use of $font is detailed here.
Example
include(fb.ComponentPath + 'helpers.js');
// $font() with no args resets back to the default_font supplied to
// DrawStyledText in on_paint
// also includes $rgb example
var tfo = fb.TitleFormat(
"[$font(Twemoji Mozilla,18)$country_flag(%country%)$font() ]$rgb(255,0,0)%artist%"
);
var str = "";
refresh();
function refresh() {
var item = fb.GetFocusItem();
if (item) {
str = tfo.EvalWithMetadb(item);
} else {
str = "";
}
}
function on_item_focus_change() {
refresh();
window.Repaint();
}
function on_playlist_switch() {
refresh();
window.Repaint();
}
function on_paint(gr) {
// default_font is an empty string, defaulting to Segoe UI, 16px
gr.WriteText(str, "", 0, 0, 0, window.Width, window.Height, 2, 2);
}
JavaScript#
If you prefer not to use title formatting, you can use utils.GetCountryFlag method
which accepts a 2 letter country code or the full country name. See
supported values. An empty string will be returned on failure.
Example
include(fb.ComponentPath + 'helpers.js');
var font = CreateFontString("Twemoji Mozilla", 24);
var flag = utils.GetCountryFlag("GB");
function on_paint(gr) {
gr.WriteText(flag, font, 0, 0, 0, window.Width, window.Height, 2, 2);
}
Supported values#
Case is not important. You can supply the code or full name. A few examples:
| gb | United Kingdom |
| fr | France |
| de | Germany |
A complete list of supported values can be found in this file: countries.json