Skip to content
Pablo Mayobre edited this page Mar 25, 2015 · 2 revisions

#Roboto

The Roboto font has been part of Android for years now, and Material-Design comes with a new version of Roboto, which has different variations.

Material-Design specifies which variation, size and lineheight should be used for each type of text (Titles, Captions, Body, etc.)

The Roboto library handles all this stuff for you in order to make use of this font in a really simple way.

Usage

You first need to require the roboto.lua file, which returns a function that expects just one argument, the path to the asset folder, and returns the roboto module.

In one call:

love.load = function ()
    roboto = require "material-love.libs.roboto" ("material-love/assets")
end

Then you can easily use this to change the current font to one of the available fonts. There are two ways to do this, the first one is using it as a table

love.graphics.setFont(roboto["body2"])
love.graphics.setFont(roboto.title)

But if the font doesnt exist, this will error with "love.graphics.setFont argument #1, font expected, got nil" which is not nice, so in order to provide better errors, use roboto as a function:

love.graphics.setFont(roboto("body2"))
love.graphics.setFont(roboto "title")

Available fonts

There are 11 available fonts, here you have got a list:

  • display4 (Roboto Light, Size: 112)
  • display3 (Roboto Regular, Size: 56)
  • display2 (Roboto Regular, Size: 45, Lineheight: 48)
  • display1 (Roboto Regular, Size: 34, Lineheight: 40)
  • headline (Roboto Regular, Size: 24, Lineheight: 32)
  • title (Roboto Medium, Size: 20)
  • subhead (Roboto Regular, Size: 16 / 15, Lineheight: 28)
  • body2 (Roboto Medium, Size: 14 / 13, Lineheight: 24)
  • body1 (Roboto Regular, Size: 14 / 13, Lineheight: 20)
  • caption (Roboto Regular, Size: 12)
  • button (Roboto Medium, Size: 15)

When Lineheight is not specified, the font should not be used for multiple lines.

When two Sizes are specified, the first one is for Android and iOS devices, while the other is for Desktop.

For a guide on where to use each font check this

Files

This is the list of needed files:

  • libs/roboto.lua
  • assets/roboto-light.ttf
  • assets/roboto-medium.ttf
  • assets/roboto-regular.ttf
Clone this wiki locally