[English]

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.


旋转框包含一个数字作为文本,可以增加或 减少 Keys 或 API 函数。在引擎盖下,Spinbox 是一个 修改了 文本区域

Parts and Styles(零件和样式)

显示原文

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


旋转框的各个部分与 文本区域 相同。

Value, range and step(值、范围和步长)

显示原文

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. - lv_spinbox_set_cursor_pos(spinbox, 1) sets the cursor to a specific digit to change on increment/decrement. For example position '0' sets the cursor to the least significant digit.

If an encoder is used as input device, the selected digit is shifted to the right by default whenever the encoder button is clicked. To change this behaviour to shifting to the left, the lv_spinbox_set_digit_step_direction(spinbox, LV_DIR_LEFT) can be used


如果将编码器用作输入设备,则所选数字将移至默认情况下,每当单击编码器按钮时,该键都是右键。将此行为更改为转移 在左侧,可以使用 lv_spinbox_set_digit_step_direction(spinbox, LV_DIR_LEFT)

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. is the number of digits before the decimal point. If 0, no decimal point is displayed.


lv_spinbox_set_digit_format(spinbox, digit_count, separator_position) 设置数字格式。 digit_count 是位不包括小数点分隔符和符号。 separator_position 是小数点前的位数。如果为 0,则不显示小数点。

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 remain at the minimum or maximum value.


lv_spinbox_set_rollover(spinbox, true / false) 启用/禁用 翻转模式。如果达到最小值或最大值启用展期时,该值将更改为其他限制。如果展期禁用时,该值将保持在最小值或最大值。

Events(事件)

显示原文

See the events of the Text area too.

Learn more about Events(事件).


另请参阅 文本区域 的事件。

详细了解更多 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.


  • LV_KEY_LEFT/RIGHT 使用 键盘 向左/向右移动光标。使用编码器递减/递增所选数字。

  • LV_KEY_UP/DOWN键盘编码器 递增/递减值。

  • LV_KEY_ENTER编码器 得到净数字。跳转到第一个之后在最后一个。

Example

[English]

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_screen_active());
    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);

    int32_t h = lv_obj_get_height(spinbox);

    lv_obj_t * btn = lv_button_create(lv_screen_active());
    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_image_src(btn, LV_SYMBOL_PLUS, 0);
    lv_obj_add_event_cb(btn, lv_spinbox_increment_event_cb, LV_EVENT_ALL,  NULL);

    btn = lv_button_create(lv_screen_active());
    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_image_src(btn, LV_SYMBOL_MINUS, 0);
    lv_obj_add_event_cb(btn, lv_spinbox_decrement_event_cb, LV_EVENT_ALL, NULL);
}

#endif

API

lv_spinbox.h