[−][src]Crate glyph_brush_layout
Text layout for rusttype.
Example
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
rusttype | Re-exported rusttype types. |
Structs
FontId | Id for a font |
SectionGeometry | |
SectionText |
Enums
BuiltInLineBreaker | Built-in linebreaking logic. |
GlyphChange | |
HorizontalAlign | Describes horizontal alignment preference for positioning & bounds. |
Layout | Built-in |
LineBreak | Indicator that a character is a line break, soft or hard. Includes the offset (byte-index) position. |
VerticalAlign | Describes vertical alignment preference for positioning & bounds. Currently a placeholder for future functionality. |
Traits
FontMap | |
GlyphPositioner | Logic to calculate glyph positioning using |
LineBreaker | Producer of a |
Type Definitions
Color | RGBA |