[][src]Struct wasm_game_lib::graphics::font::Font

pub struct Font { /* fields omitted */ }

This struct represent a font. It is useful when using the Text struct.

Example

use wasm_game_lib::graphics::font::Font;
use wasm_game_lib::graphics::text::Text;
 
// use a default font
let arial = Font::arial();
 
// load a custom font
let trade_winds = Font::load("https://fonts.gstatic.com/s/tradewinds/v8/AYCPpXPpYNIIT7h8-QenM0Jt5vM.woff2").await.unwrap();
 
// use the fonts with the Text struct
let arial_text = Text::new_with_text_and_coords(&arial, String::from("This text is using Arial font."), (0,100));
let trade_winds_text = Text::new_with_text_and_coords(&trade_winds, String::from("This text is using Trade Winds font."), (0,200));

Methods

impl Font[src]

pub async fn load<'_>(url: &'_ str) -> Result<Font, JsValue>[src]

Load a custom font from an url. The load may fail so a Result is returned.

Example

use wasm_game_lib::graphics::font::Font;
use wasm_game_lib::graphics::text::Text;
 
// load the font
let trade_winds = Font::load("https://fonts.gstatic.com/s/tradewinds/v8/AYCPpXPpYNIIT7h8-QenM0Jt5vM.woff2").await.unwrap();
 
// use the font with the Text struct
let trade_winds_text = Text::new_with_text_and_coords(&trade_winds, String::from("This text is using Trade Winds font."), (0,100));

About Google Fonts

If you are using google fonts, you may have a link like "https://fonts.googleapis.com/css?family=Trade+Winds&display=swap". To get the font url from this link, load this link in a web browser. You should get something like that:

/* latin */
@font-face {
    font-family: 'Trade Winds';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: local('Trade Winds'), local('TradeWinds'), url(https://fonts.gstatic.com/s/tradewinds/v8/AYCPpXPpYNIIT7h8-QenM0Jt5vM.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

The url of the font is located at the seventh line, after "url(".

pub async fn load_and_send<'_>(
    url: &'_ str,
    sender: Sender<Result<Font, JsValue>>
)
[src]

Load a custom font from an url and send it trought a oneshot channel.

It works exactly like images so see that for an example.

pub fn sherif() -> Font[src]

Return the Sherif font.

pub fn arial() -> Font[src]

Return the Arial font.

pub fn times_new_roman() -> Font[src]

Return the Times New Roman font.

pub fn times() -> Font[src]

Return the Times font.

pub fn courier_new() -> Font[src]

Return the Courier New font.

pub fn courier() -> Font[src]

Return the Courier font.

pub fn verdana() -> Font[src]

Return the Verdana font.

pub fn georgia() -> Font[src]

Return the Georgia font.

pub fn palatino() -> Font[src]

Return the Palatino font.

pub fn garamond() -> Font[src]

Return the Garamond font.

pub fn bookman() -> Font[src]

Return the Bookman font.

pub fn comic_sans_ms() -> Font[src]

Return the Comic Sans Ms font.

pub fn candara() -> Font[src]

Return the Candara font.

pub fn helvetica() -> Font[src]

Return the Helvetica font.

pub fn arial_black() -> Font[src]

Return the Arial Black font.

pub fn impact() -> Font[src]

Return the Inpact font.

Trait Implementations

impl Debug for Font[src]

Auto Trait Implementations

impl RefUnwindSafe for Font

impl Send for Font

impl Sync for Font

impl Unpin for Font

impl UnwindSafe for Font

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.