### Configure text layout and calculate placement Source: https://github.com/helgev-in-arcana/suzuri/blob/main/README.md Creates a TextLayoutConfig with max width, alignment, line height scale, and wrap style, then computes the layout using FontSystem. ```rust # use suzuri::{FontSystem, text::TextData}; use suzuri::text::{TextLayoutConfig, HorizontalAlign, VerticalAlign, WrapStyle}; # let font_system = FontSystem::new(); # let data = TextData::::new(); let config = TextLayoutConfig { max_width: Some(800.0), max_height: None, horizontal_align: HorizontalAlign::Left, vertical_align: VerticalAlign::Top, line_height_scale: 1.2, wrap_style: WrapStyle::WordWrap, ..Default::default() }; let layout = font_system.layout_text(&data, &config); ``` -------------------------------- ### Initialize FontSystem and query a font Source: https://github.com/helgev-in-arcana/suzuri/blob/main/README.md Initializes FontSystem, loads system fonts, and queries for a font by family, weight, stretch, and style. The query returns an Option of the font ID; the commented expect line shows how to handle a missing font. ```rust use suzuri::{FontSystem, fontdb::{self, Family, Query}}; let font_system = FontSystem::new(); font_system.load_system_fonts(); // Query a font let font_id = font_system .query(&Query { families: &[Family::Name("Arial"), Family::SansSerif], weight: fontdb::Weight::NORMAL, stretch: fontdb::Stretch::Normal, style: fontdb::Style::Normal, }) .map(|(id, _)| id); // .expect("Font not found"); // Handle error appropriately ``` -------------------------------- ### Enable wgpu feature in Cargo.toml Source: https://github.com/helgev-in-arcana/suzuri/blob/main/README.md Enables the wgpu feature for suzuri version 0.2.0. ```toml [dependencies] suzuri = { version = "0.2.0", features = ["wgpu"] } ``` -------------------------------- ### Prepare text data with custom color type Source: https://github.com/helgev-in-arcana/suzuri/blob/main/README.md Defines a user-defined color type and converts it to premultiplied alpha [f32; 4] for wgpu rendering. Appends a text element with content, font ID, size, and user data. ```rust # use suzuri::{FontSystem, fontdb}; # use suzuri::text::{TextData, TextElement}; # let font_system = FontSystem::new(); # let font_id = None; # // Color type is user-definable #[derive(Clone, Copy, Debug)] struct MyColor { r: f32, g: f32, b: f32, a: f32 } // For wgpu rendering, convert to [f32; 4] (Premultiplied Alpha) impl From for [f32; 4] { fn from(c: MyColor) -> Self { [c.r * c.a, c.g * c.a, c.b * c.a, c.a] } } let mut data = TextData::new(); if let Some(id) = font_id { data.append(TextElement { content: "Hello, Suzuri!".to_string(), font_id: id, font_size: 32.0, user_data: MyColor { r: 1.0, g: 1.0, b: 1.0, a: 1.0 }, }); } ``` -------------------------------- ### Add suzuri dependency to Cargo.toml Source: https://github.com/helgev-in-arcana/suzuri/blob/main/README.md Adds the suzuri crate version 0.2.0 as a dependency. ```toml [dependencies] suzuri = "0.2.0" ```