diff options
| -rw-r--r-- | main.c | 4 | ||||
| -rw-r--r-- | ui.c | 5 | ||||
| -rw-r--r-- | ui.h | 2 | ||||
| -rw-r--r-- | widget.c | 18 | ||||
| -rw-r--r-- | widget.h | 9 |
5 files changed, 23 insertions, 15 deletions
@@ -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]); } } @@ -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 @@ -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); @@ -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); } @@ -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); |