Ubuntu.Components.FontUtils
FontUtils is a context property, which provides utility functions for font manipulations. More...
Import Statement: | import Ubuntu.Components 1.3 |
Methods
- real modularScale(string size)
- real sizeToPixels(string size)
Detailed Description
FontUtils cannot be instantiated and it is already available as a context property, i.e. 'FontUtils' is an instance that can be used from anywhere in the code.
Example of a Label implementation which uses the default base scale for the font size:
import QtQuick 2.4 import Ubuntu.Components 1.2 Text { property string fontSize: "medium" font.pixelSize: FontUtils.sizeToPixels(fontSize) }
Another example of a custom text input component exposing a fontSize property and a base font unit size to scale its font:
import QtQuick 2.4 import Ubuntu.Components 1.2 TextInput { property string fontSize: "small" property int baseFontUnits: units.dp(20) font.pixelSize: FontUtils.modularScale(fontSize) * units.dp(baseFontUnits) }
Method Documentation
real modularScale(string size) |
The function returns the number interpretation of a given font scale. The scale can have one of the following values:
- xx-small
- x-small
- small
- medium
- large
- x-large
real sizeToPixels(string size) |
The function calculates the pixel size of a given scale. The size scale can be one of the strings specified at modularScale function. On failure returns 0.