aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.c4
-rw-r--r--ui.c5
-rw-r--r--ui.h2
-rw-r--r--widget.c18
-rw-r--r--widget.h9
5 files changed, 23 insertions, 15 deletions
diff --git a/main.c b/main.c
index 8baa172..e31e7ab 100644
--- a/main.c
+++ b/main.c
@@ -243,14 +243,14 @@ volume_flow_rate_row(mu_Context *ctx, UI *ui) {
mu_layout_row(ctx, 0, NULL, 0);
mu_layout_width(ctx, LABEL_WIDTH);
- mu_label(ctx, "volume flow rate");
+ mu_label(ctx, "Volume flow rate:");
mu_layout_width(ctx, UNIT_WIDTH);
if (w_select(ctx, &ui->volume_flow_rate_unit) & MU_RES_CHANGE) {
set_all_volume_flow_rate(ui);
}
mu_layout_width(ctx, FIELD_WIDTH);
for (i = 0; i < ui->npoints; i++) {
- w_label(ctx, ui->volume_flow_rate[i]);
+ w_number(ctx, ui->volume_flow_rate[i]);
}
}
diff --git a/ui.c b/ui.c
index e3e729f..1591901 100644
--- a/ui.c
+++ b/ui.c
@@ -1,5 +1,4 @@
#include <assert.h>
-#include <stdio.h>
#include <string.h>
#include "microui.h"
@@ -51,7 +50,7 @@ init_ui(UI *ui) {
init_engine(&ui->points[0]);
w_init_select(&ui->volume_flow_rate_unit, nelem(volume_flow_rate_units), volume_flow_rate_units);
- w_init_label(ui->volume_flow_rate[0]);
+ w_init_number(ui->volume_flow_rate[0]);
}
void
@@ -128,7 +127,7 @@ set_volume_flow_rate(UI *ui, int idx) {
convert = volume_flow_rate_readers[unit_idx];
v = convert(volume_flow_rate(&ui->points[idx]));
- snprintf(ui->volume_flow_rate[idx], sizeof(ui->volume_flow_rate[idx]), "%f", v);
+ w_set_number(ui->volume_flow_rate[idx], v);
}
void
diff --git a/ui.h b/ui.h
index 02baee6..cc985ae 100644
--- a/ui.h
+++ b/ui.h
@@ -16,7 +16,7 @@ typedef struct {
Engine points[MAX_POINTS];
w_Select volume_flow_rate_unit;
- w_Label volume_flow_rate[MAX_POINTS];
+ w_Number volume_flow_rate[MAX_POINTS];
} UI;
void init_ui(UI *ui);
diff --git a/widget.c b/widget.c
index ae41e89..e195e55 100644
--- a/widget.c
+++ b/widget.c
@@ -7,6 +7,9 @@
#define nelem(arr) (sizeof(arr)/sizeof(arr[0]))
+
+#define FORMAT "%.5g"
+
static const mu_Color RED = {255, 0, 0, 255};
@@ -55,7 +58,7 @@ w_field(mu_Context *ctx, w_Field *f) {
void
w_set_field(w_Field *f, double val) {
f->value = val;
- snprintf(f->buf, sizeof(f->buf), "%.5f", val);
+ snprintf(f->buf, sizeof(f->buf), FORMAT, val);
}
void
@@ -106,11 +109,16 @@ w_select(mu_Context *ctx, w_Select *select) {
}
void
-w_init_label(w_Label label) {
- label[0] = '\0';
+w_init_number(w_Number num) {
+ num[0] = '\0';
+}
+
+void
+w_set_number(w_Number num, double val) {
+ snprintf(num, sizeof(w_Number), FORMAT, val);
}
void
-w_label(mu_Context *ctx, const w_Label label) {
- mu_label(ctx, label);
+w_number(mu_Context *ctx, const w_Number num) {
+ mu_label(ctx, num);
}
diff --git a/widget.h b/widget.h
index e60ffe7..1237e29 100644
--- a/widget.h
+++ b/widget.h
@@ -1,6 +1,6 @@
enum {
FIELD_SIZE = 64,
- LABEL_SIZE = 128,
+ NUMBER_SIZE = 128,
};
@@ -28,7 +28,8 @@ void w_init_select(w_Select *select, int nopts, const char *const opts[]);
int w_select(mu_Context *ctx, w_Select *select);
-typedef char w_Label[LABEL_SIZE];
+typedef char w_Number[NUMBER_SIZE];
-void w_init_label(w_Label label);
-void w_label(mu_Context *ctx, const w_Label label);
+void w_init_number(w_Number num);
+void w_set_number(w_Number num, double val);
+void w_number(mu_Context *ctx, const w_Number num);