Skip to main content

Module material

Module material 

Source
Expand description

Material Icons

The Material Design Icons can be embedded using the "material_icons*" crate features.

zng = { version = "0.22.10", features = ["material_icons"] }

Handlers are registered for ICONS that provides the icons, the raw codepoints and glyph icon metadata is available in each font module.

If multiple material icons are enabled they are resolved in this order:

  • outlined
  • filled
  • rounded
  • sharp

You can disambiguate icons by using a the "material/{set}/{name}" where {set} is one of the items from the list above, and {name} is the icon name.

§Subsetting

Compiling with the "material_icons" feature embeds the font file and a name table that around 2MB to the compiled executable. Compiling with only one icon set adds around 350KB, you can optimize further by compiling with only the subset of icons used.

§Step 1

To subset the icons you must create a profile file that lists all icons used by the app. To get started build this crate with the "material_icons_usage_recorder" feature, run it and load every screen that uses an icon, close the app.

The subset profile is saved to res/optimization-profiles/zng-wgt-material-icons.rec.subset by default, you can change the location by setting the ZNG_MATERIAL_ICONS_PROFILE_FILE env var.

The profile is a text file with format:

# comments

{set}/{name}

The generated file will has a comment header with instruction on how to manually add icons.

The profile file can be added to source control, the recorded entries are sorted so changes are stable.

§Step 2

With the a subset profile ready you only need to enable the "material_icons_subset" crate feature. On build the profile will be used to generate a subset font and only the used icons are added to the name table, greatly reducing the binary size.

The profile file is found using the ZNG_MATERIAL_ICONS_PROFILE_FILE env var is set, or in the default location. If two files .rec.subset and .subset are present with the same name both are used.

§Full API

See zng_wgt_material_icons for the full API.

Modules§

filled
Filled icons.
outlined
Outline icons.
rounded
Rounded icons.
sharp
Sharp icons.