-
Notifications
You must be signed in to change notification settings - Fork 1
/
athr_widget_bar.c
48 lines (41 loc) · 1.17 KB
/
athr_widget_bar.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
#include "athr_widget_bar.h"
#include "athr_widget.h"
#include "athr_widget_bar.h"
#include <string.h>
static void draw(struct athr_widget_bar *x, struct athr_canvas_view *canvas)
{
unsigned consumed = (unsigned)(x->consumed * (canvas->len - 1));
canvas->buff[0] = '|';
for (unsigned i = 1; i < consumed; ++i)
canvas->buff[i] = '=';
canvas->buff[canvas->len - 1] = '|';
}
static void update(struct athr_widget *x, double consumed, double speed)
{
(void)speed;
struct athr_widget_bar *bar = x->derived;
bar->consumed = consumed;
draw(bar, &x->canvas);
}
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)
{
(void)x;
return ATHR_WIDGET_BAR_MIN_LEN;
}
static unsigned max_len(struct athr_widget const *x)
{
(void)x;
return ATHR_WIDGET_BAR_MAX_LEN;
}
static struct athr_widget_vtable const vtable = {update, finish, min_len,
max_len};
void athr_widget_bar_create(struct athr_widget_bar *x)
{
widget_setup((struct athr_widget *)x, &vtable);
x->consumed = 0;
}