pub struct MetricLifecycle { /* private fields */ }Expand description
Stateful tracker for font metric changes and cache invalidation.
Maintains the current cell metrics, generation counter, and pending invalidations. The lifecycle ensures a deterministic sequence:
- Invalidation event arrives (font load, DPR change, etc.)
- Generation is bumped, pending flag is set
- Caller calls
MetricLifecycle::refitwith new metrics - If grid dimensions changed, resize propagates through the pipeline
This prevents stale glyph metrics and geometry jumps by enforcing that all consumers see consistent metric state.
Implementations§
Source§impl MetricLifecycle
impl MetricLifecycle
Sourcepub fn new(cell_metrics: CellMetrics, policy: FitPolicy) -> Self
pub fn new(cell_metrics: CellMetrics, policy: FitPolicy) -> Self
Create a new lifecycle with default cell metrics and no viewport.
Sourcepub fn cell_metrics(&self) -> &CellMetrics
pub fn cell_metrics(&self) -> &CellMetrics
Current cell metrics.
Sourcepub fn generation(&self) -> MetricGeneration
pub fn generation(&self) -> MetricGeneration
Current metric generation.
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Whether a refit is pending.
Sourcepub fn total_invalidations(&self) -> u64
pub fn total_invalidations(&self) -> u64
Total invalidation count.
Sourcepub fn total_refits(&self) -> u64
pub fn total_refits(&self) -> u64
Total refit count.
Sourcepub fn invalidate(
&mut self,
reason: MetricInvalidation,
new_metrics: Option<CellMetrics>,
)
pub fn invalidate( &mut self, reason: MetricInvalidation, new_metrics: Option<CellMetrics>, )
Record an invalidation event.
Bumps the generation and marks a refit as pending. If cell metrics changed, the new metrics are stored immediately.
Sourcepub fn set_viewport(&mut self, viewport: ContainerViewport)
pub fn set_viewport(&mut self, viewport: ContainerViewport)
Update the container viewport.
If the viewport changed, marks a refit as pending.
Sourcepub fn set_policy(&mut self, policy: FitPolicy)
pub fn set_policy(&mut self, policy: FitPolicy)
Update the fit policy.
Sourcepub fn refit(&mut self) -> Option<FitResult>
pub fn refit(&mut self) -> Option<FitResult>
Perform the pending refit computation.
Returns Some(FitResult) if the grid dimensions changed, None if
no refit was needed or dimensions are unchanged.
Clears the pending flag regardless of outcome.
Sourcepub fn snapshot(&self) -> MetricSnapshot
pub fn snapshot(&self) -> MetricSnapshot
Diagnostic snapshot for JSONL evidence logging.
Trait Implementations§
Source§impl Clone for MetricLifecycle
impl Clone for MetricLifecycle
Source§fn clone(&self) -> MetricLifecycle
fn clone(&self) -> MetricLifecycle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more