add elapsed time to tick handler params, add generic scrollable menu
This commit is contained in:
+4
-2
@@ -52,14 +52,17 @@ static void __attribute__((noreturn)) gui_thread(void *arg) {
|
||||
|
||||
uint32_t last_wheel_time = 0;
|
||||
|
||||
uint32_t last_time = xTaskGetTickCount();
|
||||
while (1) {
|
||||
bool want_repaint = false;
|
||||
uint32_t value = 0;
|
||||
xTaskNotifyWait(0, ULONG_MAX, &value, pdMS_TO_TICKS(10));
|
||||
uint32_t time = xTaskGetTickCount();
|
||||
|
||||
if (value & 0b10000) {
|
||||
// TICK
|
||||
want_repaint |= Liquid_handleTick(liquid);
|
||||
want_repaint |= Liquid_handleTick(liquid, time - last_time);
|
||||
last_time = time;
|
||||
}
|
||||
|
||||
if (value & 0b1000) {
|
||||
@@ -69,7 +72,6 @@ static void __attribute__((noreturn)) gui_thread(void *arg) {
|
||||
}
|
||||
|
||||
if (value & 0b11) {
|
||||
uint32_t time = xTaskGetTickCount();
|
||||
uint32_t increment = 1;
|
||||
// wheel delta changes with speed
|
||||
if (last_wheel_time != 0) {
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#ifndef LIQUID_INPUT_EVENT_H
|
||||
#define LIQUID_INPUT_EVENT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
enum InputEvent_Kind {
|
||||
InputEventKind_Wheel,
|
||||
InputEventKind_Button,
|
||||
@@ -18,6 +20,7 @@ struct InputEvent {
|
||||
struct {
|
||||
// Wheel delta
|
||||
int32_t delta;
|
||||
int8_t direction;
|
||||
} wheel;
|
||||
struct {
|
||||
// Button state
|
||||
@@ -30,7 +33,10 @@ static inline struct InputEvent InputEvent_Wheel(int32_t delta)
|
||||
{
|
||||
return (struct InputEvent) {
|
||||
.kind = InputEventKind_Wheel,
|
||||
.wheel = {.delta = delta}
|
||||
.wheel = {
|
||||
.delta = delta,
|
||||
.direction = delta > 0 ? 1 : -1,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -119,12 +119,12 @@ bool Liquid_handleInput(struct Liquid *container, struct InputEvent event) {
|
||||
}
|
||||
}
|
||||
|
||||
bool Liquid_handleTick(struct Liquid *container) {
|
||||
bool Liquid_handleTick(struct Liquid *container, uint32_t elapsed_millis) {
|
||||
struct RunningScene *topmost = SLIST_FIRST(&container->stack);
|
||||
assert(topmost != NULL);
|
||||
assert(topmost->scene != NULL);
|
||||
if (topmost->scene->onTick) {
|
||||
struct SceneEvent result = topmost->scene->onTick(topmost->scene);
|
||||
struct SceneEvent result = topmost->scene->onTick(topmost->scene, elapsed_millis);
|
||||
return processReturnValue(container, result);
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -19,7 +19,7 @@ struct Liquid;
|
||||
bool Liquid_handleInput(struct Liquid *container, struct InputEvent event);
|
||||
|
||||
/** return 1 if repaint requested */
|
||||
bool Liquid_handleTick(struct Liquid *container);
|
||||
bool Liquid_handleTick(struct Liquid *container, uint32_t elapsed_millis);
|
||||
|
||||
/** render the active scene */
|
||||
void Liquid_paint(struct Liquid *container);
|
||||
|
||||
@@ -38,7 +38,7 @@ typedef struct SceneEvent (*Scene_onChildReturn_t)(struct Scene *scene, uint32_t
|
||||
* @param scene - self
|
||||
* @return follow-up scene event, can be SceneEvent_None() if not used.
|
||||
*/
|
||||
typedef struct SceneEvent (*Scene_onTick_t)(struct Scene *scene);
|
||||
typedef struct SceneEvent (*Scene_onTick_t)(struct Scene *scene, uint32_t millis);
|
||||
|
||||
/**
|
||||
* Scene::init fp type
|
||||
|
||||
Reference in New Issue
Block a user