Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions grid_common/grid_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,9 @@
#define GRID_LUA_FNC_EP_BUTTON_MODE_short "bmo"
#define GRID_LUA_FNC_EP_BUTTON_MODE_human "button_mode"

#define GRID_LUA_FNC_EP_BUTTON_STEP_short "bstp"
#define GRID_LUA_FNC_EP_BUTTON_STEP_human "button_step"

#define GRID_LUA_FNC_EP_BUTTON_ELAPSED_index 6
#define GRID_LUA_FNC_EP_BUTTON_ELAPSED_short "bel"
#define GRID_LUA_FNC_EP_BUTTON_ELAPSED_human "button_elapsed_time"
Expand Down
16 changes: 10 additions & 6 deletions grid_common/grid_ui_button.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,18 @@ void grid_ui_button_store_input(struct grid_ui_button_state* state, uint16_t val

last = clampi32(last, min, max);

int32_t new_value = last + (tmax - tmin) / steps;

if (new_value > max) {
new_value = min;
int32_t step_size = (tmax - tmin) / steps;
int32_t new_value;

if (step_size != 0) {
int32_t k = (last - tmin) / step_size;
new_value = tmin + (k + 1) * step_size;
} else {
new_value = last;
}

if (new_value < min) {
new_value = max;
if (new_value > max || new_value < min) {
new_value = tmin;
}

int32_t value_range = tmax - tmin;
Expand Down
4 changes: 2 additions & 2 deletions grid_common/grid_ui_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ extern const luaL_Reg GRID_LUA_E_INDEX_META[];
GRID_LUA_FNC_ASSIGN_META_PAR1_RET("gen", GRID_LUA_FNC_G_ELEMENTNAME_short) "," \
\
GRID_LUA_FNC_E_BUTTON_STEP_short " =function (self) " \
"local steps, min, max, value = self:" GRID_LUA_FNC_B_BUTTON_MODE_short "(), self:" GRID_LUA_FNC_B_BUTTON_MIN_short "(), self:" GRID_LUA_FNC_B_BUTTON_MAX_short \
"(), self:" GRID_LUA_FNC_B_BUTTON_VALUE_short "() " \
"local steps, min, max, value = self:" GRID_LUA_FNC_E_BUTTON_MODE_short "(), self:" GRID_LUA_FNC_E_BUTTON_MIN_short "(), self:" GRID_LUA_FNC_E_BUTTON_MAX_short \
"(), self:" GRID_LUA_FNC_E_BUTTON_VALUE_short "() " \
"if steps == 0 then return false end " \
"return value // ((max - min) // steps) " \
"end," \
Expand Down
7 changes: 7 additions & 0 deletions grid_common/grid_ui_endless.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ extern const luaL_Reg GRID_LUA_EP_INDEX_META[];
\
GRID_LUA_FNC_ASSIGN_META_PAR1_RET("gen", GRID_LUA_FNC_G_ELEMENTNAME_short) "," \
\
GRID_LUA_FNC_EP_BUTTON_STEP_short " =function (self) " \
"local steps, min, max, value = self:" GRID_LUA_FNC_EP_BUTTON_MODE_short "(), self:" GRID_LUA_FNC_EP_BUTTON_MIN_short "(), self:" GRID_LUA_FNC_EP_BUTTON_MAX_short \
"(), self:" GRID_LUA_FNC_EP_BUTTON_VALUE_short "() " \
"if steps == 0 then return false end " \
"return value // ((max - min) // steps) " \
"end," \
\
"}}"

#define GRID_ACTIONSTRING_ENDLESS_INIT "<?lua --[[@cb]] --[[Endless Init]] ?>"
Expand Down