---
name: graph_icons
kind: function
lang: cpp
domain: viz
version: "1.0.0"
purity: impure
signature: "IconAtlas* graph_icons_build(const uint16_t* codepoints, int count, int icon_px)"
description: "Atlas RGBA 512x512 con iconos Tabler bakeados via stb_truetype, consumido por graph_renderer para overlay de iconos en nodos del grafo"
tags: [graph, atlas, icons, tabler, opengl, gpu, stb_truetype]
uses_functions: ["gl_loader_cpp_gfx"]
uses_types: []
returns: []
returns_optional: false
error_type: "error_go_core"
imports: [imgui]
tested: true
tests: ["build with 6 codepoints produces non-empty regions", "icon_id=0 returns nullptr", "icon_id out of range returns nullptr", "atlas dimensions are 512x512"]
test_file_path: "cpp/tests/test_graph_icons.cpp"
file_path: "cpp/functions/viz/graph_icons.cpp"
framework: imgui
params:
  - name: codepoints
    desc: "Array de codepoints Unicode (uint16_t) en el rango Tabler 0xE000-0xFCFF — los TI_* del header icons_tabler.h apuntan a estos codepoints"
  - name: count
    desc: "Numero de iconos a bakear. Limite 256 (grid 16x16 dentro del atlas 512x512)"
  - name: icon_px
    desc: "Tamano de rasterizacion en pixels. 32 por defecto — coincide con el tamano de celda y evita re-escalado"
output: "Handle opaco al atlas. Texture id GL_RGBA8 accesible via graph_icons_texture(); regiones por icon_id (1-based) via graph_icons_region(). icon_id=0 reservado para significar 'sin icono'"
---

# graph_icons

Builder de atlas de iconos Tabler para `graph_renderer`. Bakea hasta 256 codepoints en una textura RGBA8 de 512×512 organizada como grid 16×16 de celdas de 32 px.

## API

```cpp
struct IconAtlas;
struct IconRegion {
    uint16_t id;             // 1-based; 0 = "sin icono"
    uint16_t codepoint;
    float    u0, v0, u1, v1; // UVs en [0,1]
};

IconAtlas* graph_icons_build(const uint16_t* codepoints, int count, int icon_px = 32);
unsigned int graph_icons_texture(const IconAtlas*);
const IconRegion* graph_icons_region(const IconAtlas*, uint16_t icon_id);
int graph_icons_count(const IconAtlas*);
int graph_icons_width(const IconAtlas*);
int graph_icons_height(const IconAtlas*);
const unsigned char* graph_icons_pixels(const IconAtlas*); // CPU copy para tests
void graph_icons_destroy(IconAtlas*);
```

## Ejemplo

```cpp
const uint16_t cps[] = {
    0xEB4Du,  // TI_USER
    0xEAE5u,  // TI_MAIL
    0xEAB9u,  // TI_GLOBE
    0xEB09u,  // TI_PHONE
    0xEA4Fu,  // TI_BUILDING
    0xEA88u,  // TI_DATABASE
};
IconAtlas* atlas = graph_icons_build(cps, 6);

// EntityType refiere por icon_id (1-based):
EntityType person = entity_type(0xFF4CAF50, SHAPE_CIRCLE, 12.0f, "Person", 1);
EntityType email  = entity_type(0xFFF44336, SHAPE_SQUARE, 12.0f, "Email",  2);

// Pasar el atlas al renderer:
graph_renderer_set_icon_atlas(renderer, atlas);
```

## Notas

- Requiere `tabler-icons.ttf` en `./assets/`, `$FN_ASSETS_DIR/`, o `${FN_CPP_ROOT}/vendor/tabler-icons/`.
- Cada celda lleva 1 px de padding interior para evitar bleed entre iconos al filtrar linealmente.
- Los pixels CPU se retienen para que tests verifiquen la presencia de glifos en las regiones esperadas sin GPU.
- `stb_truetype` se incluye con `STB_TRUETYPE_IMPLEMENTATION` local (cada TU tiene `STBTT_DEF static`, no colisiona con la copia de ImGui).
