-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathathr_widget_text.c
57 lines (49 loc) · 1.48 KB
/
athr_widget_text.c
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
57
#include "athr_widget_text.h"
#include "athr_widget.h"
#include "athr_widget_text.h"
#include <assert.h>
#include <string.h>
static void update(struct athr_widget *x, double consumed, double speed)
{
(void)consumed;
(void)speed;
struct athr_widget_text *text = x->derived;
assert(x->canvas.len >= text->len);
memcpy(x->canvas.buff, text->buff, text->len);
}
static void finish(struct athr_widget *x, double total_elapsed)
{
(void)total_elapsed;
update(x, 1.0f, 0.0f);
}
static unsigned min_len(struct athr_widget const *x)
{
return ((struct athr_widget_text *)x->derived)->len;
}
static unsigned max_len(struct athr_widget const *x)
{
return ((struct athr_widget_text *)x->derived)->len;
}
static void *__memccpy(void *restrict dest, const void *restrict src, int c,
size_t n)
{
unsigned char *d = dest;
const unsigned char *s = src;
c = (unsigned char)c;
for (; n && (*d = *s) != c; n--, s++, d++)
;
return n ? d + 1 : 0;
if (n) return d + 1;
return 0;
}
static struct athr_widget_vtable const vtable = {update, finish, min_len,
max_len};
void athr_widget_text_create(struct athr_widget_text *x, char const *buff)
{
char const *ptr = __memccpy(x->buff, buff, 0, ATHR_WIDGET_TEXT_MAX_LEN);
if (ptr)
x->len = (unsigned)(ptr - x->buff - 1);
else
x->len = ATHR_WIDGET_TEXT_MAX_LEN;
widget_setup((struct athr_widget *)x, &vtable);
}