You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.7 KiB
93 lines
2.7 KiB
#include <malloc.h>
|
|
#include <graphics/bitmaps.h>
|
|
#include <sys/param.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
#include "liquid.h"
|
|
#include "graphics/drawing.h"
|
|
|
|
#include "scenes.h"
|
|
#include "scene_menu.h"
|
|
|
|
struct Priv {
|
|
int32_t number;
|
|
};
|
|
|
|
static struct SceneEvent onSelect(struct MenuScene *self) {
|
|
struct Priv *priv = self->extra;
|
|
|
|
if (self->selected == 0) {
|
|
return SceneEvent_Close(0, NULL);
|
|
}
|
|
|
|
if (self->selected == 8) {
|
|
return SceneEvent_OpenChild(NewScene_Car(), 0);
|
|
}
|
|
if (self->selected == 9) {
|
|
return SceneEvent_OpenChild(NewScene_Demo(), 0);
|
|
}
|
|
if (self->selected == 2) {
|
|
struct NumberSceneOpts *opts = calloc(1, sizeof(struct NumberSceneOpts));
|
|
strcpy(opts->unit, "°C");
|
|
strcpy(opts->label, "Setpoint");
|
|
opts->value = priv->number;
|
|
opts->min = 0;
|
|
opts->max = 350;
|
|
return SceneEvent_OpenChild(NewScene_Number(opts), 99);
|
|
}
|
|
if (self->selected == 5) {
|
|
self->items[5].tag++;
|
|
snprintf(self->items[5].label, MENUITEM_LABEL_LEN, "Clicked %dx", self->items[5].tag);
|
|
return SceneEvent_Repaint();
|
|
}
|
|
|
|
return SceneEvent_None();
|
|
}
|
|
|
|
static void priv_deinit(struct MenuScene *self)
|
|
{
|
|
free(self->extra);
|
|
self->extra = NULL;
|
|
}
|
|
|
|
static struct SceneEvent onChildReturn(struct MenuScene *self, uint32_t tag, int32_t status, void *data)
|
|
{
|
|
struct Priv *priv = self->extra;
|
|
if (tag == 99) {
|
|
priv->number = status;
|
|
snprintf(self->items[2].label, MENUITEM_LABEL_LEN, "Set=%d°C", priv->number);
|
|
}
|
|
|
|
// this should be unreachable
|
|
return SceneEvent_None();
|
|
}
|
|
|
|
struct Scene *NewScene_MenuTest() {
|
|
struct MenuItem *items = calloc(10, sizeof(struct MenuItem));
|
|
|
|
strncpy(items[0].label, "🔙Back", MENUITEM_LABEL_LEN);
|
|
strncpy(items[1].label, "▶#1", MENUITEM_LABEL_LEN);
|
|
strncpy(items[2].label, "Set=0°C", MENUITEM_LABEL_LEN);
|
|
strncpy(items[3].label, "▶#3", MENUITEM_LABEL_LEN);
|
|
strncpy(items[4].label, "▶#4", MENUITEM_LABEL_LEN);
|
|
strncpy(items[5].label, "Clicked 0x", MENUITEM_LABEL_LEN);
|
|
strncpy(items[6].label, "▶#6", MENUITEM_LABEL_LEN);
|
|
strncpy(items[7].label, "▶#7", MENUITEM_LABEL_LEN);
|
|
strncpy(items[8].label, "Car", MENUITEM_LABEL_LEN);
|
|
strncpy(items[9].label, "Demo Scene", MENUITEM_LABEL_LEN);
|
|
|
|
struct MenuScene * scene = NewScene_Menu(items, 10);
|
|
scene->onSelect = onSelect;
|
|
|
|
// private data added by the subclass
|
|
struct Priv *priv = calloc(1, sizeof(struct Priv));
|
|
priv->number = 0;
|
|
scene->extra = priv;
|
|
scene->extra_deinit = (Scene_deinit_t) priv_deinit;
|
|
|
|
// add a child return handler (base does not use this)
|
|
scene->base.onChildReturn = (Scene_onChildReturn_t) onChildReturn;
|
|
|
|
return (struct Scene *) scene;
|
|
}
|
|
|