livesplit-core 0.13.0

livesplit-core is a library that provides a lot of functionality for creating a speedrun timer.
Documentation
use core::marker::PhantomData;

use crate::{
    component::key_value::State,
    layout::{LayoutDirection, LayoutState},
    rendering::{
        font::{AbbreviatedLabel, CachedLabel},
        resource::ResourceAllocator,
        RenderContext,
    },
};

pub struct Cache<I, L> {
    key: AbbreviatedLabel<L>,
    value: CachedLabel<L>,
    _image: PhantomData<I>,
}

impl<I, L> Cache<I, L> {
    pub const fn new() -> Self {
        Self {
            key: AbbreviatedLabel::new(),
            value: CachedLabel::new(),
            _image: PhantomData,
        }
    }
}

pub(in crate::rendering) fn render<A: ResourceAllocator>(
    cache: &mut Cache<A::Image, A::Label>,
    context: &mut RenderContext<'_, A>,
    dim: [f32; 2],
    component: &State,
    layout_state: &LayoutState,
) {
    context.render_background(dim, &component.background);
    context.render_key_value_component(
        &component.key,
        &component.key_abbreviations,
        &mut cache.key,
        &component.value,
        &mut cache.value,
        component.updates_frequently,
        dim,
        component.key_color.unwrap_or(layout_state.text_color),
        component.value_color.unwrap_or(layout_state.text_color),
        component.display_two_rows || layout_state.direction == LayoutDirection::Horizontal,
    );
}