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

ref: 49dca4f647ac7a2aac685e0a1a983adda1fbbfb9 CTU-FEE-B0B35APO-Semestral-project/lib-gui/src/gui_component.c -rw-r--r-- 1.7 KiB
49dca4f6 — František Boháček feat: add gui container info to store container create data 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "gui.h"

component_t gui_component_create(int16_t x, int16_t y, uint16_t w, uint16_t h,
                                 render_function render,
                                 update_function update) {
  component_t component = {
    .x = x,
    .y = y,
    .width = w,
    .height = h,
    .render = render,
    .update = update,
    .focused = false,
    .focusable = false,
    .state = NULL
  };

  return component;
}

bool gui_is_component_visible(gui_t *gui, container_t *container,
                              component_t *component) {
  coords_t pos = gui_component_get_screen_position(container, component);

  bool visible_x = (pos.x >= 0 && pos.x < gui->size.x) ||
                   (pos.x < 0 && pos.x + component->width > 0);
  bool visible_y = (pos.y >= 0 && pos.y < gui->size.y) ||
                   (pos.y < 0 && pos.y + component->height > 0);

  return visible_x && visible_y;
}

void gui_component_render(gui_t *gui, container_t *container,
                          component_t *component) {
  component->render(container, component, gui);
}

void gui_component_update(gui_t *gui, container_t *container,
                          component_t *component) {
  component->update(container, component, gui);
}

coords_t gui_component_get_absolute_position(container_t *container,
                                             component_t *component) {
  coords_t pos = {
    .x = container->x + component->x,
    .y = container->y + component->y
  };

  return pos;
}

coords_t gui_component_get_screen_position(container_t *container,
                                          component_t *component) {
  return gui_component_get_absolute_position(container, component);
}
Do not follow this link