#pragma once
#include <cstddef>
#include <cstdint>

namespace wearable {
// Horizontal glyph metrics are independent of the caller's baseline/height.
// Caller owns storage, allowing the device to allocate it exclusively in PSRAM.
template<class Font> struct GlyphMetricEntry {
    const Font* font;
    uint16_t code;
    int16_t width,advance,offset;
    bool valid;
};
template<class Font> class GlyphMetricsCache {
public:
    using Entry=GlyphMetricEntry<Font>;
    static constexpr size_t slots=256;
    static const Entry* find(const Entry* storage,uint16_t code) {
        if(!storage)return nullptr;
        const auto& e=storage[code%slots];return e.valid && e.code==code?&e:nullptr;
    }
    static void put(Entry* storage,uint16_t code,const Font* font,int16_t width,int16_t advance,int16_t offset) {
        if(storage)storage[code%slots]={font,code,width,advance,offset,true};
    }
};
}
