Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dhardy
Copy link
Contributor

@dhardy dhardy commented Sep 1, 2025

fn runs now supports an offset.

Comment on lines 18 to -31
/// Effect formatting marker
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Effect<X> {
pub struct Effect {
/// Index in text at which formatting becomes active
///
/// (Note that we use `u32` not `usize` since it can be assumed text length
/// will never exceed `u32::MAX`.)
pub start: u32,
/// User-specified value, e.g. index into a colour palette
pub e: u16,
/// Effect flags
pub flags: EffectFlags,
/// User payload
pub aux: X,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new Effect struct.

Comment on lines 541 to 558
/// Iterate over runs of positioned glyphs
///
/// This method is just sugar for `self.runs_with_effects(&[], ())`.
/// All glyphs are translated by the given `offset` (this is practically
/// free).
///
/// Runs are yielded in undefined order. The total number of
/// glyphs yielded will equal [`TextDisplay::num_glyphs`].
pub fn runs(&self) -> Result<impl Iterator<Item = GlyphRun<'_, ()>>, NotReady> {
Ok(self.display()?.runs())
}

/// Iterate over runs of positioned glyphs with effects
///
/// The passed `effects` do not have to equal those associated with the text
/// `T`; it is fine to use an empty list instead (i.e. [`Self::runs`]) or
/// even synthesize a new list of effects.
///
/// If the list `effects` is empty or has first entry with `start > 0`, the
/// result of `Effect::default(default_aux)` is used. The user payload of
/// type `X` is simply passed through to `f` and `g` calls and may be useful
/// for color information.
///
/// This method is significantly more computationally expensive than [`Self::runs`].
/// An [`Effect`] sequence supports underline, strikethrough and custom
/// indexing (e.g. for a color palette). Pass `&[]` if effects are not
/// required. (The default effect is always [`Effect::default()`].)
///
/// Runs are yielded in undefined order. The total number of
/// glyphs yielded will equal [`TextDisplay::num_glyphs`].
pub fn runs_with_effects<'a, X: Copy>(
pub fn runs<'a>(
&'a self,
effects: &'a [Effect<X>],
default_aux: X,
) -> Result<impl Iterator<Item = GlyphRun<'a, X>> + 'a, NotReady> {
Ok(self.display()?.runs_with_effects(effects, default_aux))
offset: Vec2,
effects: &'a [Effect],
) -> Result<impl Iterator<Item = GlyphRun<'a>> + 'a, NotReady> {
Ok(self.display()?.runs(offset, effects))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged fn runs takes an offset and effects in all cases.

@dhardy dhardy merged commit 0bc2629 into master Sep 1, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants