blob: 8a77b8f85579f8e69e11cd199a6a98c4c07e64bd (
plain) (
blame)
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
|
#include <stdio.h>
#include "microui.h"
#include "widget.h"
void
init_field(Field *f) {
f->buf[0] = '\0';
f->value = 0.0;
}
/* field draws a Field widget and updates its value.
* It returns MU_RES_CHANGE if the value has changed. */
int
field(mu_Context *ctx, Field *f) {
double value;
int changed = 0;
if (mu_textbox(ctx, f->buf, sizeof(f->buf)) & MU_RES_CHANGE) {
if (sscanf(f->buf, "%lf", &value) == 1) {
f->value = value;
changed = 1;
} else if (f->buf[0] == '\0') {
f->value = 0.0;
changed = 1;
}
}
return changed ? MU_RES_CHANGE : 0;
}
|