1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
//! ``` //! use glyph_brush::{BrushAction, BrushError, GlyphBrushBuilder, Section}; //! //! # fn main() -> Result<(), glyph_brush::BrushError> { //! let dejavu: &[u8] = include_bytes!("../../fonts/DejaVuSans.ttf"); //! let mut glyph_brush = GlyphBrushBuilder::using_font_bytes(dejavu).build(); //! # let some_other_section = Section { text: "another", ..Section::default() }; //! //! glyph_brush.queue(Section { //! text: "Hello glyph_brush", //! ..Section::default() //! }); //! glyph_brush.queue(some_other_section); //! //! # let screen_dimensions = (1024, 768); //! # let update_texture = |_, _| {}; //! # let into_vertex = |_| (); //! match glyph_brush.process_queued( //! screen_dimensions, //! |rect, tex_data| update_texture(rect, tex_data), //! |vertex_data| into_vertex(vertex_data), //! ) { //! Ok(BrushAction::Draw(vertices)) => { //! // Draw new vertices. //! } //! Ok(BrushAction::ReDraw) => { //! // Re-draw last frame's vertices unmodified. //! } //! Err(BrushError::TextureTooSmall { suggested }) => { //! // Enlarge texture + glyph_brush texture cache and retry. //! } //! } //! # Ok(()) //! # } //! ``` mod glyph_brush; mod glyph_calculator; mod owned_section; mod section; pub use crate::{glyph_brush::*, glyph_calculator::*, owned_section::*, section::*}; pub use glyph_brush_layout::*; use glyph_brush_layout::rusttype::*; /// A "practically collision free" `Section` hasher pub type DefaultSectionHasher = twox_hash::RandomXxHashBuilder; #[test] fn default_section_hasher() { use std::hash::{BuildHasher, Hash, Hasher}; let section_a = Section { text: "Hovered Tile: Some((0, 0))", screen_position: (5.0, 60.0), scale: Scale { x: 20.0, y: 20.0 }, color: [1.0, 1.0, 1.0, 1.0], ..<_>::default() }; let section_b = Section { text: "Hovered Tile: Some((1, 0))", screen_position: (5.0, 60.0), scale: Scale { x: 20.0, y: 20.0 }, color: [1.0, 1.0, 1.0, 1.0], ..<_>::default() }; let hash = |s: &Section| { let s: VariedSection = s.into(); let mut hasher = DefaultSectionHasher::default().build_hasher(); s.hash(&mut hasher); hasher.finish() }; assert_ne!(hash(§ion_a), hash(§ion_b)); }