2018-11-01 18:48:13 +01:00
|
|
|
/**
|
2018-11-03 18:41:06 +01:00
|
|
|
* @file lv_spinbox.h
|
2018-11-01 18:48:13 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LV_SPINBOX_H
|
|
|
|
#define LV_SPINBOX_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2019-12-26 02:49:30 +01:00
|
|
|
#include "../lv_conf_internal.h"
|
2018-11-01 18:48:13 +01:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_SPINBOX != 0
|
2018-11-01 18:48:13 +01:00
|
|
|
|
2018-12-20 00:01:05 +01:00
|
|
|
/*Testing of dependencies*/
|
2020-02-14 12:36:44 +01:00
|
|
|
#if LV_USE_TEXTAREA == 0
|
|
|
|
#error "lv_spinbox: lv_ta is required. Enable it in lv_conf.h (LV_USE_TEXTAREA 1) "
|
2018-12-20 00:01:05 +01:00
|
|
|
#endif
|
|
|
|
|
2018-11-01 18:48:13 +01:00
|
|
|
#include "../lv_core/lv_obj.h"
|
2020-02-15 00:33:26 +01:00
|
|
|
#include "../lv_widgets/lv_textarea.h"
|
2018-11-01 18:48:13 +01:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2020-04-29 13:24:07 +02:00
|
|
|
#define LV_SPINBOX_MAX_DIGIT_COUNT 10
|
2018-11-01 18:48:13 +01:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
2018-11-05 14:02:13 +01:00
|
|
|
|
2018-11-03 18:41:06 +01:00
|
|
|
/*Data of spinbox*/
|
2020-02-26 19:48:27 +01:00
|
|
|
typedef struct {
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_textarea_ext_t ta; /*Ext. of ancestor*/
|
2018-11-01 18:48:13 +01:00
|
|
|
/*New data for this type */
|
2018-11-03 18:26:59 +01:00
|
|
|
int32_t value;
|
2018-11-04 20:21:51 +01:00
|
|
|
int32_t range_max;
|
|
|
|
int32_t range_min;
|
2018-11-01 18:48:13 +01:00
|
|
|
int32_t step;
|
2020-05-01 11:17:43 +02:00
|
|
|
uint8_t rollover : 1; // Set to true for rollover functionality
|
2019-04-04 07:15:40 +02:00
|
|
|
uint16_t digit_count : 4;
|
|
|
|
uint16_t dec_point_pos : 4; /*if 0, there is no separator and the number is an integer*/
|
|
|
|
uint16_t digit_padding_left : 4;
|
2018-11-01 18:48:13 +01:00
|
|
|
} lv_spinbox_ext_t;
|
|
|
|
|
|
|
|
/*Styles*/
|
|
|
|
enum {
|
2020-02-14 12:36:44 +01:00
|
|
|
LV_SPINBOX_PART_BG = LV_TEXTAREA_PART_BG,
|
|
|
|
LV_SPINBOX_PART_CURSOR = LV_TEXTAREA_PART_CURSOR,
|
|
|
|
_LV_SPINBOX_PART_VIRTUAL_LAST = _LV_TEXTAREA_PART_VIRTUAL_LAST,
|
|
|
|
_LV_SPINBOX_PART_REAL_LAST = _LV_TEXTAREA_PART_REAL_LAST,
|
2018-11-01 18:48:13 +01:00
|
|
|
};
|
2020-01-07 23:43:57 +01:00
|
|
|
typedef uint8_t lv_spinbox_part_t;
|
2018-11-01 18:48:13 +01:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL PROTOTYPES
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
2018-11-03 18:41:06 +01:00
|
|
|
* Create a spinbox objects
|
|
|
|
* @param par pointer to an object, it will be the parent of the new spinbox
|
|
|
|
* @param copy pointer to a spinbox object, if not NULL then the new object will be copied from it
|
|
|
|
* @return pointer to the created spinbox
|
2018-11-01 18:48:13 +01:00
|
|
|
*/
|
|
|
|
lv_obj_t * lv_spinbox_create(lv_obj_t * par, const lv_obj_t * copy);
|
|
|
|
|
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
|
|
|
|
2020-03-25 16:17:01 +01:00
|
|
|
/**
|
|
|
|
* Set spinbox rollover function
|
|
|
|
* @param spinbox pointer to spinbox
|
|
|
|
* @param b true or false to enable or disable (default)
|
|
|
|
*/
|
|
|
|
void lv_spinbox_set_rollover(lv_obj_t * spinbox, bool b);
|
|
|
|
|
2018-11-03 18:41:06 +01:00
|
|
|
/**
|
|
|
|
* Set spinbox value
|
|
|
|
* @param spinbox pointer to spinbox
|
|
|
|
* @param i value to be set
|
|
|
|
*/
|
2018-12-20 00:01:05 +01:00
|
|
|
void lv_spinbox_set_value(lv_obj_t * spinbox, int32_t i);
|
2018-11-03 18:41:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set spinbox digit format (digit count and decimal format)
|
|
|
|
* @param spinbox pointer to spinbox
|
|
|
|
* @param digit_count number of digit excluding the decimal separator and the sign
|
2019-04-04 07:15:40 +02:00
|
|
|
* @param separator_position number of digit before the decimal point. If 0, decimal point is not
|
|
|
|
* shown
|
2018-11-03 18:41:06 +01:00
|
|
|
*/
|
2019-06-06 06:05:40 +02:00
|
|
|
void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_t separator_position);
|
2018-11-03 18:41:06 +01:00
|
|
|
|
|
|
|
/**
|
2018-11-04 20:21:51 +01:00
|
|
|
* Set spinbox step
|
2018-11-03 18:41:06 +01:00
|
|
|
* @param spinbox pointer to spinbox
|
2018-11-04 20:21:51 +01:00
|
|
|
* @param step steps on increment/decrement
|
2018-11-03 18:41:06 +01:00
|
|
|
*/
|
2018-12-20 00:01:05 +01:00
|
|
|
void lv_spinbox_set_step(lv_obj_t * spinbox, uint32_t step);
|
2018-11-01 18:48:13 +01:00
|
|
|
|
2018-11-03 18:41:06 +01:00
|
|
|
/**
|
|
|
|
* Set spinbox value range
|
|
|
|
* @param spinbox pointer to spinbox
|
2018-11-04 20:21:51 +01:00
|
|
|
* @param range_min maximum value, inclusive
|
|
|
|
* @param range_max minimum value, inclusive
|
|
|
|
*/
|
2018-12-20 00:01:05 +01:00
|
|
|
void lv_spinbox_set_range(lv_obj_t * spinbox, int32_t range_min, int32_t range_max);
|
2018-11-01 18:48:13 +01:00
|
|
|
|
2018-11-05 14:48:33 +01:00
|
|
|
/**
|
|
|
|
* Set spinbox left padding in digits count (added between sign and first digit)
|
|
|
|
* @param spinbox pointer to spinbox
|
|
|
|
* @param cb Callback function called on value change event
|
|
|
|
*/
|
2018-12-20 00:01:05 +01:00
|
|
|
void lv_spinbox_set_padding_left(lv_obj_t * spinbox, uint8_t padding);
|
2018-11-01 18:48:13 +01:00
|
|
|
|
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
|
|
|
|
2020-03-25 16:17:01 +01:00
|
|
|
/**
|
|
|
|
* Get spinbox rollover function status
|
|
|
|
* @param spinbox pointer to spinbox
|
|
|
|
*/
|
|
|
|
bool lv_spinbox_get_rollover(lv_obj_t * spinbox);
|
|
|
|
|
2018-11-03 18:41:06 +01:00
|
|
|
/**
|
|
|
|
* Get the spinbox numeral value (user has to convert to float according to its digit format)
|
|
|
|
* @param spinbox pointer to spinbox
|
|
|
|
* @return value integer value of the spinbox
|
|
|
|
*/
|
2018-12-20 00:01:05 +01:00
|
|
|
int32_t lv_spinbox_get_value(lv_obj_t * spinbox);
|
2018-11-01 18:48:13 +01:00
|
|
|
|
|
|
|
/*=====================
|
|
|
|
* Other functions
|
|
|
|
*====================*/
|
|
|
|
|
2018-11-04 20:21:51 +01:00
|
|
|
/**
|
|
|
|
* Select next lower digit for edition by dividing the step by 10
|
|
|
|
* @param spinbox pointer to spinbox
|
|
|
|
*/
|
|
|
|
void lv_spinbox_step_next(lv_obj_t * spinbox);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Select next higher digit for edition by multiplying the step by 10
|
|
|
|
* @param spinbox pointer to spinbox
|
|
|
|
*/
|
2019-06-25 15:14:47 +02:00
|
|
|
void lv_spinbox_step_prev(lv_obj_t * spinbox);
|
2018-11-04 20:21:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Increment spinbox value by one step
|
|
|
|
* @param spinbox pointer to spinbox
|
|
|
|
*/
|
|
|
|
void lv_spinbox_increment(lv_obj_t * spinbox);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrement spinbox value by one step
|
|
|
|
* @param spinbox pointer to spinbox
|
|
|
|
*/
|
|
|
|
void lv_spinbox_decrement(lv_obj_t * spinbox);
|
|
|
|
|
2018-11-01 18:48:13 +01:00
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
#endif /*LV_USE_SPINBOX*/
|
2018-11-01 18:48:13 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
#endif /*LV_SPINBOX_H*/
|