### Defining Text Effect Structure in Rust Source: https://github.com/kas-gui/kas-text/blob/master/design/text-effects.md This Rust `struct` defines the basic internal representation for a text effect. It includes `start` (character index), `colour` (sRGB color), and `flags` (effect properties). This structure is fundamental for applying various text effects and managing their state within the `kas-text` library. ```Rust struct Effect { start: u32, colour: Srgb, flags: EffectFlags, } ``` -------------------------------- ### Defining Generic EffectToken Structure (Rust) Source: https://github.com/kas-gui/kas-text/blob/master/design/text-effects.md The `EffectToken` struct represents a text effect, parameterized by a generic type `X` for auxiliary data. It contains `start` (the starting index of the effect), `flags` (effect-specific flags), and `aux` (additional data specific to the effect type). This structure is generated by the `effect_tokens` method. ```Rust struct EffectToken { start: u32, flags: EffectFlags, aux: X, } ``` -------------------------------- ### Defining FontToken Structure (Rust) Source: https://github.com/kas-gui/kas-text/blob/master/design/text-effects.md The `FontToken` struct represents properties associated with a font segment. It includes `start` (the starting index), `face` (the font face ID), `dpem` (dots per em), and an optional `tag` for consumption by the draw-stage resolver. This structure is yielded by the `font_tokens` iterator. ```Rust struct FontToken { start: u32, face: FaceId, dpem: f32, // And maybe this, for consumption by draw-stage resolver: tag: u32, } ``` -------------------------------- ### Managing Text Glyphs and Effects in Rust Source: https://github.com/kas-gui/kas-text/blob/master/design/text-effects.md This Rust `impl` block defines methods for the `Text` struct to retrieve positioned glyphs, with or without applying text effects. `glyphs` provides raw glyph positioning, `glyphs_and_effects` returns glyphs along with associated effects, and `glyphs_with_effects` allows applying additional effects dynamically. These methods are crucial for efficient text rendering and effect combination. ```Rust impl Text { /// Returns a Vec of positioned glyphs, ignoring all effects pub fn glyphs(&self, mut f: F) { .. } /// Returns a Vec of positioned glyphs and a Vec of effects pub fn glyphs_and_effects G>(&self) -> (Vec, Vec) { if self.text_effects.is_empty() { (self.glyphs(f), vec![]) } else { self.glyphs_with_effects_impl(&self.text_effects, f) } } /// Same as `glyphs_and_effects` but applies extra text-effects on-the-fly pub fn glyphs_with_effects(&self, effects: &[Effect], mut f: F) -> Vec where U: Copy + Default, F: FnMut(FontId, f32, f32, Glyph, U), { if !self.text_effects.is_empty() { effects = combine(&self.text_effects, effects); } self.glyphs_with_effects_impl(effects, f) } } ``` -------------------------------- ### Defining the KAS GUI Theme Trait in Rust Source: https://github.com/kas-gui/kas-text/blob/master/design/text-effects.md This Rust trait defines the interface for a KAS GUI theme, responsible for providing font selection, font sizing, and auxiliary data (like colors) for glyphs. It includes methods for selecting fonts based on a `FontSelector` and auxiliary data based on an `AuxSelector`, as well as providing default values. ```Rust /// Trait object provided by downstream; may include default impl // TODO: separate ThemeFont and ThemeAux? pub trait Theme { /// Auxilliary data associated with glyphs; typically used for colour type Aux: Clone; /// Allow downcast as an extension mechanism fn as_any(&self) -> &Any; fn default_font(&self) -> FontId; fn select_font(&self, selector: &FontSelector) -> FontId; /// Provides default font size as `(dpp, pt_size)` fn font_size(&self) -> (f32, f32); /// Provides default instance of `Aux` type fn default_aux(&self) -> Aux; /// Provides `Aux` instance fn select_aux(&self, selector: AuxSelector) -> Aux; } ``` -------------------------------- ### Generating Raw Effect Tokens (Rust) Source: https://github.com/kas-gui/kas-text/blob/master/design/text-effects.md This is an overloaded version of the `effect_tokens` method, also run during drawing. It takes `storage` (initialized by `font_tokens`) and `state` as input, returning a vector of raw `Self::EffectToken` items without an explicit translation closure. This variant is suitable when direct `EffectToken` generation is sufficient. ```Rust fn effect_tokens<'a, Aux>(&'a self, storage: &mut Self::Storage, state: &DrawState, ) -> Vec; ``` -------------------------------- ### Defining Core Text Structures and Traits in Rust Source: https://github.com/kas-gui/kas-text/blob/master/design/text-effects.md This snippet defines the core `Text` struct, parameterized by `TextRep`, which encapsulates the text content and derived properties. It also introduces `TextDerived` for environmental and derived data, and two traits, `TextDerivedApi` and `TextApi`, to provide read-only and update functionalities respectively, promoting a clear separation of concerns for text manipulation and access. ```rust struct Text { text: T, derived: TextDerived, } struct TextDerived { // env and all derived } trait TextDerivedApi { // all read-env and read-derived fns } trait TextApi: TextDerivedApi { // update env, prepare // read text (fns independent of T) // access as &TextDerived } ``` -------------------------------- ### Generating Effect Tokens with Translation (Rust) Source: https://github.com/kas-gui/kas-text/blob/master/design/text-effects.md This method provides an iterator yielding `EffectToken` items, primarily executed during the drawing phase. It utilizes the `storage` which must have been previously initialized by `font_tokens`. The `translate` closure allows for custom transformation of `Self::EffectToken` into `EffectToken` and can force generation of additional tokens at a given index. ```Rust fn effect_tokens<'a, Aux>(&'a self, storage: &mut Self::Storage, state: &DrawState, translate: &mut FnMut(u32, Self::EffectToken) -> (u32, EffectToken), ) -> Vec>; ``` -------------------------------- ### Updating Storage and Yielding Font Tokens (Rust) Source: https://github.com/kas-gui/kas-text/blob/master/design/text-effects.md This function updates the provided `storage` and returns an iterator yielding `FontToken` items. It is specifically used during the run-breaking phase to initialize `storage` for subsequent use by `effect_tokens`. Key parameters include `dpp` (dots per pixel) and `pt_size` (point size) which influence font metrics. ```Rust fn font_tokens<'a>(&'a self, storage: &mut Self::Storage, dpp: f32, pt_size: f32) -> Self::FontTokenIter<'a>; ``` -------------------------------- ### Defining KAS GUI AuxSelector and FormattableText Traits in Rust Source: https://github.com/kas-gui/kas-text/blob/master/design/text-effects.md This Rust code defines the `AuxSelector` enum, used to specify different types of auxiliary data (e.g., for selected text), and the `FormattableText` trait. The `FormattableText` trait is implemented by rich-text parsers to provide text content, font tokens, and effect tokens, enabling the rendering engine to process and display formatted text. ```Rust #[non_exhaustive] pub enum AuxSelector { Default, Selected, // selected text } /// Trait impls provided by rich-text parsers, both provided and downstream impls pub trait FormattableText: std::fmt::Debug { type FontTokenIter<'a>: Iterator; /// Storage available type Storage: Clone + Default + Debug; /// State used to generate effect tokens type DrawState: ?Sized; /// Effect tokens as generated by this object type EffectToken; fn clone_boxed(&self) -> Box; fn str_len(&self) -> usize; fn as_str(&self) -> &str; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.