Crate glyph_brush_layout
source ·Expand description
Text layout for rusttype.
Example
extern crate glyph_brush_layout;
use glyph_brush_layout::{rusttype::*, *};
let dejavu = Font::from_bytes(&include_bytes!("../../fonts/DejaVuSans.ttf")[..])?;
let garamond = Font::from_bytes(&include_bytes!("../../fonts/GaramondNo8-Reg.ttf")[..])?;
// Simple vec font mapping: FontId(0) -> deja vu sans, FontId(1) -> garamond
let fonts = vec![dejavu, garamond];
// Layout "hello glyph_brush_layout" on an unbounded line with the second
// word suitably bigger, greener and serif-ier.
let glyphs = Layout::default().calculate_glyphs(
&fonts,
&SectionGeometry {
screen_position: (150.0, 50.0),
..SectionGeometry::default()
},
&[
SectionText {
text: "hello ",
scale: Scale::uniform(20.0),
..SectionText::default()
},
SectionText {
text: "glyph_brush_layout",
scale: Scale::uniform(25.0),
font_id: FontId(1),
color: [0.0, 1.0, 0.0, 1.0],
},
],
);
assert_eq!(glyphs.len(), 23);
let (o_glyph, glyph_4_color, glyph_4_font) = &glyphs[4];
assert_eq!(o_glyph.id(), fonts[0].glyph('o').id());
assert_eq!(*glyph_4_color, [0.0, 0.0, 0.0, 1.0]);
assert_eq!(*glyph_4_font, FontId(0));
let (s_glyph, glyph_14_color, glyph_14_font) = &glyphs[14];
assert_eq!(s_glyph.id(), fonts[1].glyph('s').id());
assert_eq!(*glyph_14_color, [0.0, 1.0, 0.0, 1.0]);
assert_eq!(*glyph_14_font, FontId(1));
Modules
Re-exported rusttype types.
Structs
Enums
Built-in linebreaking logic.
Describes horizontal alignment preference for positioning & bounds.
Built-in
GlyphPositioner
implementations.Indicator that a character is a line break, soft or hard. Includes the offset (byte-index)
position.
Describes vertical alignment preference for positioning & bounds. Currently a placeholder
for future functionality.
Traits
Type Definitions
RGBA
[0, 1]
color data.