~ruther/CTU-FEE-B0B35APO-Semestral-project

ref: 120c16db845c6be7d839d128f9dcab24c97bd7bf CTU-FEE-B0B35APO-Semestral-project/lib-gui/src/gui_component_text.c -rw-r--r-- 1.0 KiB
120c16db — František Boháček feat: add support for larger fonts 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "gui_component_text.h"
#include "font.h"
#include "renderer.h"

component_t gui_text_create(text_t *text, int16_t x, int16_t y, int16_t w,
                            int16_t h) {
  component_t comp =
      gui_component_create(x, y, w, h, gui_text_render, gui_text_update);
  comp.state = text;

  if (w == 0 || h == 0) {
    size2d_t measured = font_measure_text(text->font, text->line);

    comp.width = comp.width != 0 ? comp.width : measured.x;
    comp.height = comp.height != 0 ? comp.height : measured.y;
  }

  return comp;
}

void gui_text_render(container_t *container, component_t *component,
                     gui_t *gui) {
  if (gui_is_component_visible(gui, container, component)) {
    text_t *state = (text_t*)component->state;
    renderer_write_string(gui->renderer, component->x, component->y, 0, state->font, state->line, state->color);
  }
}

void gui_text_update(container_t *container, component_t *component,
                     gui_t *gui) {
  // do nothing -- maybe horizontal scroll?
}
Do not follow this link