Spinbox (lv_spinbox)

Overview

The Spinbox contains a number as text which can be increased or decreased by Keys or API functions. Under the hood the Spinbox is a modified Text area.

Parts and Styles

The parts of the Spinbox are identical to the Text area.

Value, range and step

lv_spinbox_set_value(spinbox, 1234) sets a new value on the Spinbox.

lv_spinbox_increment(spinbox) and lv_spinbox_decrement(spinbox) increments/decrements the value of the Spinbox according to the currently selected digit.

lv_spinbox_set_range(spinbox, -1000, 2500) sets a range. If the value is changed by lv_spinbox_set_value, by Keys,lv_spinbox_increment/decrement this range will be respected.

lv_spinbox_set_step(spinbox, 100) sets which digits to change on increment/decrement. Only multiples of ten can be set, and not for example 3.

Format

lv_spinbox_set_digit_format(spinbox, digit_count, separator_position) sets the number format. digit_count is the number of digits excluding the decimal separator and the sign. separator_position is the number of digits before the decimal point. If 0, no decimal point is displayed.

Rollover

lv_spinbox_set_rollover(spinbox, true/false) enables/disabled rollover mode. If either the minimum or maximum value is reached with rollover enabled, the value will change to the other limit. If rollover is disabled the value will be remain at the minimum or maximum value.

Events

  • LV_EVENT_VALUE_CHANGED Sent when the value has changed.

Learn more about Events.

Keys

  • LV_KEY_LEFT/RIGHT With Keypad move the cursor left/right. With Encoder decrement/increment the selected digit.

  • LV_KEY_UP/DOWN With Keypad and Encoder increment/decrement the value.

  • LV_KEY_ENTER With Encoder got the net digit. Jump to the first after the last.

Example

C

Simple Spinbox

#include "../../lv_examples.h"
#if LV_USE_SPINBOX && LV_BUILD_EXAMPLES

static lv_obj_t * spinbox;


static void lv_spinbox_increment_event_cb(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    if(code == LV_EVENT_SHORT_CLICKED || code  == LV_EVENT_LONG_PRESSED_REPEAT) {
        lv_spinbox_increment(spinbox);
    }
}

static void lv_spinbox_decrement_event_cb(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    if(code == LV_EVENT_SHORT_CLICKED || code == LV_EVENT_LONG_PRESSED_REPEAT) {
        lv_spinbox_decrement(spinbox);
    }
}


void lv_example_spinbox_1(void)
{
    spinbox = lv_spinbox_create(lv_scr_act());
    lv_spinbox_set_range(spinbox, -1000, 25000);
    lv_spinbox_set_digit_format(spinbox, 5, 2);
    lv_spinbox_step_prev(spinbox);
    lv_obj_set_width(spinbox, 100);
    lv_obj_center(spinbox);

    lv_coord_t h = lv_obj_get_height(spinbox);

    lv_obj_t * btn = lv_btn_create(lv_scr_act());
    lv_obj_set_size(btn, h, h);
    lv_obj_align_to(btn, spinbox, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
    lv_obj_set_style_bg_img_src(btn, LV_SYMBOL_PLUS, 0);
    lv_obj_add_event_cb(btn, lv_spinbox_increment_event_cb, LV_EVENT_ALL,  NULL);

    btn = lv_btn_create(lv_scr_act());
    lv_obj_set_size(btn, h, h);
    lv_obj_align_to(btn, spinbox, LV_ALIGN_OUT_LEFT_MID, -5, 0);
    lv_obj_set_style_bg_img_src(btn, LV_SYMBOL_MINUS, 0);
    lv_obj_add_event_cb(btn, lv_spinbox_decrement_event_cb, LV_EVENT_ALL, NULL);
}

#endif

MicroPython

No examples yet.

API

Functions

lv_obj_t *lv_spinbox_create(lv_obj_t *parent)

Create a spinbox objects

Parameters

par -- pointer to an object, it will be the parent of the new spinbox

Returns

pointer to the created spinbox

void lv_spinbox_set_value(lv_obj_t *obj, int32_t i)

Set spinbox value

Parameters
  • spinbox -- pointer to spinbox

  • i -- value to be set

void lv_spinbox_set_rollover(lv_obj_t *obj, bool b)

Set spinbox rollover function

Parameters
  • spinbox -- pointer to spinbox

  • b -- true or false to enable or disable (default)

void lv_spinbox_set_digit_format(lv_obj_t *obj, uint8_t digit_count, uint8_t separator_position)

Set spinbox digit format (digit count and decimal format)

Parameters
  • spinbox -- pointer to spinbox

  • digit_count -- number of digit excluding the decimal separator and the sign

  • separator_position -- number of digit before the decimal point. If 0, decimal point is not shown

void lv_spinbox_set_step(lv_obj_t *obj, uint32_t step)

Set spinbox step

Parameters
  • spinbox -- pointer to spinbox

  • step -- steps on increment/decrement. Can be 1, 10, 100, 1000, etc the digit that will change.

void lv_spinbox_set_range(lv_obj_t *obj, int32_t range_min, int32_t range_max)

Set spinbox value range

Parameters
  • spinbox -- pointer to spinbox

  • range_min -- maximum value, inclusive

  • range_max -- minimum value, inclusive

bool lv_spinbox_get_rollover(lv_obj_t *obj)

Get spinbox rollover function status

Parameters

spinbox -- pointer to spinbox

int32_t lv_spinbox_get_value(lv_obj_t *obj)

Get the spinbox numeral value (user has to convert to float according to its digit format)

Parameters

spinbox -- pointer to spinbox

Returns

value integer value of the spinbox

int32_t lv_spinbox_get_step(lv_obj_t *obj)

Get the spinbox step value (user has to convert to float according to its digit format)

Parameters

spinbox -- pointer to spinbox

Returns

value integer step value of the spinbox

void lv_spinbox_step_next(lv_obj_t *obj)

Select next lower digit for edition by dividing the step by 10

Parameters

spinbox -- pointer to spinbox

void lv_spinbox_step_prev(lv_obj_t *obj)

Select next higher digit for edition by multiplying the step by 10

Parameters

spinbox -- pointer to spinbox

void lv_spinbox_increment(lv_obj_t *obj)

Increment spinbox value by one step

Parameters

spinbox -- pointer to spinbox

void lv_spinbox_decrement(lv_obj_t *obj)

Decrement spinbox value by one step

Parameters

spinbox -- pointer to spinbox

Variables

const lv_obj_class_t lv_spinbox_class
struct lv_spinbox_t

Public Members

lv_textarea_t ta
int32_t value
int32_t range_max
int32_t range_min
int32_t step
uint16_t digit_count
uint16_t dec_point_pos
uint16_t rollover

Example