Spirik / GEM

Good Enough Menu for Arduino
GNU Lesser General Public License v3.0
239 stars 36 forks source link

Limiting float and integer variable #63

Closed HajmamadAgha closed 11 months ago

HajmamadAgha commented 1 year ago

When choosing a variable item I want it to be limited so the user won't be able to increase it more than a maximum or decrease it less than the minimum, how should I implement it? I used the constrain function but it doesn't work.

Spirik commented 1 year ago

Hi, HajmamadAgha!

The proper way to achieve this currently is through callback function, which will be called when menu item is saved. You can write validation routine there, comparing saved value to desired min and max thresholds and act accordingly (e.g. overwriting value that user just saved).

For more details. please, see corresponding section in wiki and Blink and Party Hard! examples (which features validation callbacks for interval variables).