laytext.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #ifndef laytext_H_INCLUDED
  2. #define laytext_H_INCLUDED
  3. #include "dynar.h"
  4. /* Type of the callback that should calulate the dimensions of an
  5. * arbitrary text string encoded in utf-8. It should only take into consideration up to bytes bytes of that string */
  6. typedef int laytext_callback(char * str, int bytes, void * extra, float * w, float * h);
  7. Dynar * laytext_layout(char * str, float max_width, laytext_callback * callback, void * extra);
  8. /** Laytext lays out texts using shards. A shard is a reference to an individual segment of text that
  9. * has a single consistent one-line position, style, color, font and font scaling.
  10. * The text layout is prepared and rendered through callbacks.
  11. */
  12. typedef struct LaytextShard_ LaytextShard;
  13. /** Text layout information. */
  14. typedef struct Laytext_ Laytext;
  15. /** Text layout fragment information. */
  16. struct LaytextShard_ {
  17. struct LaytextShard_ * next;
  18. struct LaytextShard_ * previous;
  19. char * text;
  20. int bytes;
  21. float x;
  22. float y;
  23. float r;
  24. float g;
  25. float b;
  26. float a;
  27. void * font;
  28. };
  29. /* Type of the callback that should calulate the dimensions of an
  30. * arbitrary text string encoded in utf-8. It should only take into consideration up to bytes bytes of that string */
  31. typedef int laytext_size_getter(char * str, int bytes, void * font_data, float * w, float * h);
  32. /* Type of the callback that will be used to draw a shard n arbitrary text string encoded in utf-8 at a given position
  33. * It should only take into consideration up to bytes bytes of that string.
  34. * r, g, b, and a are color values ranging from 0.0 to 1.0
  35. */
  36. typedef int laytextshard_drawer(LaytextShard * shard);
  37. struct Laytext_ {
  38. LaytextShard * first;
  39. LaytextShard * last;
  40. char * text;
  41. int start_line;
  42. int end_line;
  43. int start_pos;
  44. int end_pos;
  45. int animation;
  46. int lines_per_page;
  47. int page;
  48. float speed;
  49. laytext_size_getter * get_size;
  50. laytextshard_drawer * draw;
  51. };
  52. /* Laytext * laytext_new(char * text, int x, int y, int w, int h, void * font_data, */
  53. Laytext * laytext_init(Laytext * self, char * text, laytext_size_getter * get_size, laytextshard_drawer * draw);
  54. Laytext * laytext_update(Laytext * self, char * text);
  55. void laytext_done(Laytext * self);
  56. #endif