Add lv_ta_set_sel_mode/lv_ta_get_sel_mode

This commit is contained in:
Themba Dube
2019-03-27 19:17:48 -04:00
parent f5609b6bce
commit 97089da7f5
2 changed files with 39 additions and 1 deletions

View File

@@ -791,6 +791,18 @@ void lv_ta_set_style(lv_obj_t * ta, lv_ta_style_t type, lv_style_t * style)
}
}
/**
* Enable/disable selection mode.
* @param ta pointer to a text area object
* @param en true or false to enable/disable selection mode
*/
void lv_ta_set_sel_mode(lv_obj_t *ta, bool en) {
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
ext->sel_mode = en;
if(!en)
lv_ta_clear_selection(ta);
}
/*=====================
* Getter functions
*====================*/
@@ -981,6 +993,17 @@ bool lv_ta_text_is_selected(const lv_obj_t *ta) {
return (ext_label->selection_start == -1 || ext_label->selection_end == -1);
}
/**
* Find whether selection mode is enabled.
* @param ta pointer to a text area object
* @return true: selection mode is enabled, false: disabled
*/
bool lv_ta_get_sel_mode(lv_obj_t *ta, bool en) {
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
return ext->sel_mode;
}
/*=====================
* Other functions
*====================*/
@@ -1660,7 +1683,7 @@ static void update_cursor_position_on_click(lv_obj_t * ta, lv_signal_t sign, lv_
click_outside_label = !lv_label_is_char_under_pos(ext->label, &relative_position);
}
if(!ext->selecting && !click_outside_label && sign == LV_SIGNAL_PRESSED) {
if(ext->sel_mode && !ext->selecting && !click_outside_label && sign == LV_SIGNAL_PRESSED) {
/*Input device just went down. Store the selection start position*/
ext->tmp_sel_start = index_of_char_at_position;
ext->tmp_sel_end = -1;

View File

@@ -77,6 +77,7 @@ typedef struct
int tmp_sel_start; /*Temporary value*/
int tmp_sel_end; /*Temporary value*/
uint8_t selecting :1; /*User is in process of selecting */
uint8_t sel_mode :1; /*Text can be selected on this text area*/
} lv_ta_ext_t;
enum {
@@ -251,6 +252,13 @@ static inline void lv_ta_set_edge_flash(lv_obj_t * ta, bool en)
*/
void lv_ta_set_style(lv_obj_t *ta, lv_ta_style_t type, lv_style_t *style);
/**
* Enable/disable selection mode.
* @param ta pointer to a text area object
* @param en true or false to enable/disable selection mode
*/
void lv_ta_set_sel_mode(lv_obj_t *ta, bool en);
/*=====================
* Getter functions
*====================*/
@@ -382,6 +390,13 @@ void lv_ta_get_selection(lv_obj_t * ta, int * sel_start, int * sel_end);
*/
bool lv_ta_text_is_selected(const lv_obj_t *ta);
/**
* Find whether selection mode is enabled.
* @param ta pointer to a text area object
* @return true: selection mode is enabled, false: disabled
*/
bool lv_ta_get_sel_mode(lv_obj_t *ta, bool en);
/*=====================
* Other functions
*====================*/