Files
fn_registry/cpp/functions/viz/graph_icons.md
T
egutierrez ac11300335 feat(viz): renderer shapes/iconos/flechas/edge-styles (issue 0049f)
graph_renderer 1.5.0:
- 6 shapes SDF (circle, square, diamond, hex, triangle, rounded square)
  con dispatch en fragment shader y AA via fwidth.
- Atlas opcional de iconos Tabler bakeado por graph_icons; el shader
  compone overlay desde un uniform vec4 u_icon_uvs[256]. Setter publico
  graph_renderer_set_icon_atlas(r, tex, uv_table, count).
- Aristas direccionales: 6 vertices por arista (line + chevron de la
  flecha) en una sola draw call; segmento principal acortado por el
  radio del nodo target.
- Edge styles solid/dashed/dotted via descarte por arc_length en el
  fragment shader; las lineas del chevron son siempre solidas.

graph_icons 1.0.0 (nuevo):
- Atlas RGBA8 512x512 = grid 16x16 (256 iconos max) bakeado con
  stb_truetype desde tabler-icons.ttf.
- API: graph_icons_build/texture/region/uv_table/destroy. icon_id es
  1-based; 0 reservado para "sin icono".
- Hook FN_GRAPH_ICONS_SKIP_GL=1 para tests sin contexto GL.

Demo demos_graph_styles en primitives_gallery: 6 EntityTypes (uno por
shape) con icono Tabler representativo + 3 RelationTypes (knows/uses/
owns) con flechas direccionales y los 3 estilos.

test_graph_icons: 6 casos cubriendo bake, regiones 1-indexed, uv_table
consistente, layout en grid 16x16, validacion de count fuera de rango,
y verificacion de alpha != 0 en las celdas tras bake.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 23:01:49 +02:00

83 lines
3.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
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).