#include #include #include "liquid.h" #include "graphics/drawing.h" #include "scene_number.h" #include "graphics/display_spec.h" struct NumberScene { struct Scene base; struct NumberSceneOpts *opts; }; static struct SceneEvent onInput(struct NumberScene *self, struct InputEvent event) { struct NumberSceneOpts *opts = self->opts; switch (event.kind) { case InputEventKind_Wheel: opts->value += event.wheel.delta; if (opts->value < opts->min) { opts->value = opts->min; } else if (opts->value > opts->max) { opts->value = opts->max; } return SceneEvent_Repaint(); case InputEventKind_Button: if (event.button.state) { return SceneEvent_Close(opts->value, NULL); } // fall through default: return SceneEvent_None(); } } static void paint(struct NumberScene *self) { struct NumberSceneOpts *opts = self->opts; LCD_clearDisplay(0); LCD_setStrEx(opts->label, LCD_WIDTH/2, 1, BLACK, (struct TextStyle) {.size = FONT_BOLD, .align=ALIGN_CENTER}); char buf[10]; snprintf(buf, 10, "%d%s", opts->value, opts->unit); LCD_setStrEx(buf, LCD_WIDTH/2, 14, BLACK, (struct TextStyle) {.size = FONT_DOUBLE, .align=ALIGN_CENTER}); } static void deinit(struct NumberScene *self) { free(self->opts); self->opts = NULL; } struct Scene *NewScene_Number(struct NumberSceneOpts *opts) { struct NumberScene *scene = calloc(1, sizeof(struct NumberScene)); if (!scene) return NULL; scene->opts = opts; scene->base.onInput = (Scene_onInput_t) onInput; scene->base.paint = (Scene_paint_t) paint; scene->base.deinit = (Scene_deinit_t) deinit; return (struct Scene *) scene; }