1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/src/lv_objx/lv_slider.c

467 lines
17 KiB
C
Raw Normal View History

2018-02-24 11:26:06 +01:00
2017-04-11 10:51:31 +02:00
/**
* @file lv_slider.c
2018-06-19 09:49:58 +02:00
*
2017-04-11 10:51:31 +02:00
*/
/*********************
* INCLUDES
*********************/
#include "lv_slider.h"
#if LV_USE_SLIDER != 0
2017-04-11 10:51:31 +02:00
2019-09-24 16:30:38 +02:00
#include "../lv_core/lv_debug.h"
2017-11-30 11:35:33 +01:00
#include "../lv_core/lv_group.h"
#include "../lv_core/lv_indev.h"
2017-04-11 10:51:31 +02:00
#include "../lv_draw/lv_draw.h"
#include "../lv_themes/lv_theme.h"
2017-11-23 20:42:14 +01:00
#include "../lv_misc/lv_math.h"
#include "lv_img.h"
2017-04-11 10:51:31 +02:00
/*********************
* DEFINES
*********************/
#define LV_OBJX_NAME "lv_slider"
2017-04-11 10:51:31 +02:00
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
2019-09-06 19:53:39 +02:00
static lv_design_res_t lv_slider_design(lv_obj_t * slider, const lv_area_t * clip_area, lv_design_mode_t mode);
2017-11-08 11:37:01 +01:00
static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param);
static lv_style_list_t * lv_slider_get_style(lv_obj_t * slider, uint8_t part);
2019-12-02 07:37:33 -05:00
static void lv_slider_position_knob(lv_obj_t * slider, lv_area_t * knob_area, lv_coord_t knob_size, bool hor);
2019-12-16 07:46:33 -08:00
static void lv_slider_draw_knob(lv_obj_t * slider, const lv_area_t * knob_area, const lv_area_t * clip_area);
2017-04-11 10:51:31 +02:00
/**********************
* STATIC VARIABLES
**********************/
static lv_design_cb_t ancestor_design_f;
static lv_signal_cb_t ancestor_signal;
2017-04-11 10:51:31 +02:00
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Create a slider objects
* @param par pointer to an object, it will be the parent of the new slider
* @param copy pointer to a slider object, if not NULL then the new object will be copied from it
* @return pointer to the created slider
*/
lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy)
2017-04-11 10:51:31 +02:00
{
2018-10-05 17:22:49 +02:00
LV_LOG_TRACE("slider create started");
2018-07-25 17:57:08 +02:00
2017-04-11 10:51:31 +02:00
/*Create the ancestor slider*/
lv_obj_t * new_slider = lv_bar_create(par, copy);
2019-09-24 23:14:17 +02:00
LV_ASSERT_MEM(new_slider);
if(new_slider == NULL) return NULL;
2018-06-19 09:49:58 +02:00
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_cb(new_slider);
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(new_slider);
2017-11-08 11:07:29 +01:00
2017-04-11 10:51:31 +02:00
/*Allocate the slider type specific extended data*/
lv_slider_ext_t * ext = lv_obj_allocate_ext_attr(new_slider, sizeof(lv_slider_ext_t));
2019-09-24 23:14:17 +02:00
LV_ASSERT_MEM(ext);
if(ext == NULL) {
lv_obj_del(new_slider);
return NULL;
}
2017-04-11 10:51:31 +02:00
/*Initialize the allocated 'ext' */
2019-12-02 07:37:33 -05:00
ext->value_to_set = NULL;
2020-01-18 23:34:34 +01:00
ext->dragging = 0;
2017-04-11 10:51:31 +02:00
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_cb(new_slider, lv_slider_signal);
lv_obj_set_design_cb(new_slider, lv_slider_design);
2017-04-11 10:51:31 +02:00
/*Init the new slider slider*/
if(copy == NULL) {
lv_obj_set_click(new_slider, true);
2018-02-24 11:26:06 +01:00
lv_obj_set_protect(new_slider, LV_PROTECT_PRESS_LOST);
2020-01-18 23:34:34 +01:00
lv_style_list_init(&ext->style_knob);
lv_theme_apply(new_slider, LV_THEME_SLIDER);
2020-01-20 16:11:38 +01:00
lv_obj_set_height(new_slider, LV_DPI / 15);
2017-04-11 10:51:31 +02:00
}
/*Copy an existing slider*/
else {
2019-12-31 22:13:32 +01:00
// lv_slider_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
2017-04-11 10:51:31 +02:00
}
2018-06-19 09:49:58 +02:00
2018-10-05 17:22:49 +02:00
LV_LOG_INFO("slider created");
2018-07-25 20:39:24 +02:00
2017-04-11 10:51:31 +02:00
return new_slider;
}
/*=====================
* Setter functions
*====================*/
/*=====================
* Getter functions
*====================*/
2017-12-11 11:42:12 +01:00
/**
* Get the value of a slider
* @param slider pointer to a slider object
* @return the value of the slider
*/
int16_t lv_slider_get_value(const lv_obj_t * slider)
2017-12-11 11:42:12 +01:00
{
LV_ASSERT_OBJ(slider, LV_OBJX_NAME);
2019-09-16 10:58:28 +02:00
return lv_bar_get_value(slider);
2017-12-11 11:42:12 +01:00
}
2017-04-11 10:51:31 +02:00
/**
2017-12-11 11:42:12 +01:00
* Give the slider is being dragged or not
* @param slider pointer to a slider object
2017-12-11 11:42:12 +01:00
* @return true: drag in progress false: not dragged
2017-04-11 10:51:31 +02:00
*/
bool lv_slider_is_dragged(const lv_obj_t * slider)
2017-04-11 10:51:31 +02:00
{
LV_ASSERT_OBJ(slider, LV_OBJX_NAME);
lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
2019-09-16 10:58:28 +02:00
return ext->dragging ? true : false;
}
2017-04-11 10:51:31 +02:00
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Handle the drawing related tasks of the sliders
* @param slider pointer to an object
2019-09-06 19:53:39 +02:00
* @param clip_area the object will be drawn only in this area
2017-04-11 10:51:31 +02:00
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
* (return 'true' if yes)
* LV_DESIGN_DRAW: draw the object (always return 'true')
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
2019-09-06 19:53:39 +02:00
* @param return an element of `lv_design_res_t`
2017-04-11 10:51:31 +02:00
*/
2019-09-06 19:53:39 +02:00
static lv_design_res_t lv_slider_design(lv_obj_t * slider, const lv_area_t * clip_area, lv_design_mode_t mode)
2017-04-11 10:51:31 +02:00
{
/*Return false if the object is not covers the mask_p area*/
if(mode == LV_DESIGN_COVER_CHK) {
2019-09-06 19:53:39 +02:00
return LV_DESIGN_RES_NOT_COVER;
2017-04-11 10:51:31 +02:00
}
/*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) {
2019-09-16 10:58:28 +02:00
/*The ancestor design function will draw the background and the indicator.
* It also sets ext->bar.indic_area*/
ancestor_design_f(slider, clip_area, mode);
2017-04-21 09:15:39 +02:00
2019-09-16 10:58:28 +02:00
lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
2018-09-23 23:27:28 +02:00
2019-09-16 10:58:28 +02:00
lv_coord_t objw = lv_obj_get_width(slider);
lv_coord_t objh = lv_obj_get_height(slider);
bool hor = objw >= objh ? true : false;
lv_coord_t knob_size = hor ? objh : objw;
2019-09-12 15:25:42 +02:00
bool sym = false;
2019-12-02 07:37:33 -05:00
if(ext->bar.type == LV_BAR_TYPE_SYM && ext->bar.min_value < 0 && ext->bar.max_value > 0) sym = true;
2017-04-11 10:51:31 +02:00
2017-11-23 21:28:36 +01:00
lv_area_t knob_area;
2017-04-11 10:51:31 +02:00
2019-09-16 10:58:28 +02:00
/*Horizontal*/
if(hor) {
if(!sym) {
knob_area.x1 = ext->bar.indic_area.x2;
} else {
2019-09-16 10:58:28 +02:00
if(ext->bar.cur_value >= 0) {
knob_area.x1 = ext->bar.indic_area.x2;
} else {
knob_area.x1 = ext->bar.indic_area.x1;
2019-03-01 23:50:30 +01:00
}
}
2017-04-11 10:51:31 +02:00
}
2019-09-16 10:58:28 +02:00
/*Vertical*/
else {
2019-12-02 07:37:33 -05:00
if(!sym) {
2019-09-16 10:58:28 +02:00
knob_area.y1 = ext->bar.indic_area.y1;
} else {
if(ext->bar.cur_value >= 0) {
knob_area.y1 = ext->bar.indic_area.y1;
} else {
knob_area.y1 = ext->bar.indic_area.y2;
}
}
}
2019-12-02 07:37:33 -05:00
lv_slider_position_knob(slider, &knob_area, knob_size, hor);
2020-01-20 16:11:38 +01:00
lv_area_copy(&ext->right_knob_area, &knob_area);
2019-12-02 07:37:33 -05:00
lv_slider_draw_knob(slider, &knob_area, clip_area);
if(lv_slider_get_type(slider) == LV_SLIDER_TYPE_RANGE) {
/* Draw a second knob for the start_value side */
if(hor) {
knob_area.x1 = ext->bar.indic_area.x1;
} else {
knob_area.y1 = ext->bar.indic_area.y1;
}
lv_slider_position_knob(slider, &knob_area, knob_size, hor);
2020-01-20 16:11:38 +01:00
lv_area_copy(&ext->left_knob_area, &knob_area);
2019-12-02 07:37:33 -05:00
lv_slider_draw_knob(slider, &knob_area, clip_area);
}
2017-04-11 10:51:31 +02:00
}
/*Post draw when the children are drawn*/
else if(mode == LV_DESIGN_DRAW_POST) {
2019-11-16 11:22:23 +01:00
return ancestor_design_f(slider, clip_area, mode);
2017-04-11 10:51:31 +02:00
}
2019-09-06 19:53:39 +02:00
return LV_DESIGN_RES_OK;
2017-04-11 10:51:31 +02:00
}
2017-11-08 11:37:01 +01:00
/**
* Signal function of the slider
* @param slider pointer to a slider object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param)
{
lv_res_t res;
2019-12-31 22:13:32 +01:00
if(sign == LV_SIGNAL_GET_STYLE) {
2020-01-08 21:31:05 +01:00
lv_get_style_info_t * info = param;
info->result = lv_slider_get_style(slider, info->part);
if(info->result != NULL) return LV_RES_OK;
else return ancestor_signal(slider, sign, param);
2019-12-31 22:13:32 +01:00
}
2017-11-08 11:37:01 +01:00
/* Include the ancient signal function */
res = ancestor_signal(slider, sign, param);
if(res != LV_RES_OK) return res;
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
2017-11-08 11:37:01 +01:00
lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
2017-11-23 21:28:36 +01:00
lv_point_t p;
2017-11-08 11:37:01 +01:00
if(sign == LV_SIGNAL_PRESSED) {
2019-09-16 10:58:28 +02:00
ext->dragging = true;
2019-12-02 07:37:33 -05:00
if(lv_slider_get_type(slider) == LV_SLIDER_TYPE_RANGE) {
lv_indev_get_point(param, &p);
bool hor = lv_obj_get_width(slider) >= lv_obj_get_height(slider);
lv_coord_t dist_left, dist_right;
if(hor) {
2020-01-20 16:11:38 +01:00
if(p.x > ext->right_knob_area.x2) {
ext->value_to_set = &ext->bar.cur_value;
}
else if(p.x < ext->left_knob_area.x1) {
ext->value_to_set = &ext->bar.start_value;
} else {
/* Calculate the distance from each knob */
dist_left = LV_MATH_ABS((ext->left_knob_area.x1+(ext->left_knob_area.x2 - ext->left_knob_area.x1)/2) - p.x);
dist_right = LV_MATH_ABS((ext->right_knob_area.x1+(ext->right_knob_area.x2 - ext->right_knob_area.x1)/2) - p.x);
/* Use whichever one is closer */
if(dist_right < dist_left)ext->value_to_set = &ext->bar.cur_value;
else ext->value_to_set = &ext->bar.start_value;
}
2019-12-02 07:37:33 -05:00
} else {
dist_left = LV_MATH_ABS((ext->left_knob_area.y1+(ext->left_knob_area.y2 - ext->left_knob_area.y1)/2) - p.y);
dist_right = LV_MATH_ABS((ext->right_knob_area.y1+(ext->right_knob_area.y2 - ext->right_knob_area.y1)/2) - p.y);
}
} else
ext->value_to_set = &ext->bar.cur_value;
} else if(sign == LV_SIGNAL_PRESSING && ext->value_to_set != NULL) {
2017-11-08 11:37:01 +01:00
lv_indev_get_point(param, &p);
2019-09-16 10:58:28 +02:00
lv_coord_t w = lv_obj_get_width(slider);
lv_coord_t h = lv_obj_get_height(slider);
2019-12-31 22:13:32 +01:00
lv_style_int_t bg_left = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_BG);
lv_style_int_t bg_right = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_BG);
lv_style_int_t bg_top = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_BG);
lv_style_int_t bg_bottom = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_BG);
2019-12-31 22:13:32 +01:00
2019-09-16 10:58:28 +02:00
int32_t range = ext->bar.max_value - ext->bar.min_value;
2020-01-20 16:11:38 +01:00
int16_t new_value = 0;
int16_t real_max_value = ext->bar.max_value;
int16_t real_min_value = ext->bar.min_value;
2019-12-02 07:37:33 -05:00
if(w >= h) {
2019-12-31 22:13:32 +01:00
lv_coord_t indic_w = w - bg_left - bg_right;
new_value = p.x - (slider->coords.x1 + bg_left); /*Make the point relative to the indicator*/
2019-12-02 07:37:33 -05:00
new_value = (new_value * range) / indic_w;
new_value += ext->bar.min_value;
} else {
2019-12-31 22:13:32 +01:00
lv_coord_t indic_h = h - bg_bottom - bg_top;
new_value = p.y - (slider->coords.y2 + bg_bottom); /*Make the point relative to the indicator*/
2019-12-02 07:37:33 -05:00
new_value = (-new_value * range) / indic_h;
new_value += ext->bar.min_value;
}
2020-01-20 16:11:38 +01:00
/* Figure out the min. and max. for this mode */
if(ext->value_to_set == &ext->bar.start_value) {
real_max_value = ext->bar.cur_value;
} else {
real_min_value = ext->bar.start_value;
}
2019-12-02 07:37:33 -05:00
2020-01-20 16:11:38 +01:00
if(new_value < real_min_value) new_value = real_min_value;
2019-12-02 07:37:33 -05:00
else if(new_value > real_max_value) new_value = real_max_value;
2020-01-20 16:11:38 +01:00
if(*ext->value_to_set != new_value) {
*ext->value_to_set = new_value;
lv_obj_invalidate(slider);
res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RES_OK) return res;
2019-12-02 07:37:33 -05:00
}
2020-01-20 16:11:38 +01:00
2018-06-19 09:49:58 +02:00
} else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
2019-09-16 10:58:28 +02:00
ext->dragging = false;
2019-12-02 07:37:33 -05:00
ext->value_to_set = NULL;
#if LV_USE_GROUP
/*Leave edit mode if released. (No need to wait for LONG_PRESS) */
2019-04-04 07:15:40 +02:00
lv_group_t * g = lv_obj_get_group(slider);
bool editing = lv_group_get_editing(g);
2019-03-29 16:10:18 +01:00
lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
if(indev_type == LV_INDEV_TYPE_ENCODER) {
if(editing) lv_group_set_editing(g, false);
}
#endif
2020-01-05 01:16:13 +01:00
} else if(sign == LV_SIGNAL_COORD_CHG) {
2017-11-08 11:37:01 +01:00
/* The knob size depends on slider size.
* During the drawing method the ext. size is used by the knob so refresh the ext. size.*/
2017-11-28 16:15:13 +01:00
if(lv_obj_get_width(slider) != lv_area_get_width(param) ||
2019-04-04 07:15:40 +02:00
lv_obj_get_height(slider) != lv_area_get_height(param)) {
slider->signal_cb(slider, LV_SIGNAL_REFR_EXT_DRAW_PAD, NULL);
2017-11-08 11:37:01 +01:00
}
} else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
lv_style_int_t knob_left = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_KNOB);
lv_style_int_t knob_right = lv_obj_get_style_pad_right(slider, LV_SLIDER_PART_KNOB);
lv_style_int_t knob_top = lv_obj_get_style_pad_top(slider, LV_SLIDER_PART_KNOB);
lv_style_int_t knob_bottom = lv_obj_get_style_pad_bottom(slider, LV_SLIDER_PART_KNOB);
2019-04-14 16:01:48 +02:00
2019-09-16 10:58:28 +02:00
/* The smaller size is the knob diameter*/
lv_coord_t knob_size = LV_MATH_MIN(lv_obj_get_width(slider), lv_obj_get_height(slider)) >> 1;
2019-12-31 22:13:32 +01:00
knob_size += LV_MATH_MAX(LV_MATH_MAX(knob_left, knob_right), LV_MATH_MAX(knob_bottom,knob_top));
2020-01-18 23:34:34 +01:00
knob_size += 2; /*For rounding error*/
2019-12-31 22:13:32 +01:00
lv_style_int_t knob_sh_width = lv_obj_get_style_shadow_width(slider, LV_SLIDER_PART_KNOB);
lv_style_int_t knob_sh_spread = lv_obj_get_style_shadow_spread(slider, LV_SLIDER_PART_KNOB);
lv_style_int_t knob_sh_ox = lv_obj_get_style_shadow_offset_x(slider, LV_SLIDER_PART_KNOB);
lv_style_int_t knob_sh_oy = lv_obj_get_style_shadow_offset_y(slider, LV_SLIDER_PART_KNOB);
2019-09-16 10:58:28 +02:00
2019-12-31 22:13:32 +01:00
knob_size += knob_sh_width + knob_sh_spread;
knob_size += LV_MATH_MAX(LV_MATH_ABS(knob_sh_ox), LV_MATH_ABS(knob_sh_oy));
2019-09-16 10:58:28 +02:00
lv_style_int_t bg_sh_width = lv_obj_get_style_shadow_width(slider, LV_SLIDER_PART_BG);
lv_style_int_t bg_sh_spread = lv_obj_get_style_shadow_spread(slider, LV_SLIDER_PART_BG);
lv_style_int_t bg_sh_ox = lv_obj_get_style_shadow_offset_x(slider, LV_SLIDER_PART_BG);
lv_style_int_t bg_sh_oy = lv_obj_get_style_shadow_offset_y(slider, LV_SLIDER_PART_BG);
2019-12-31 22:13:32 +01:00
lv_coord_t bg_size = bg_sh_width + bg_sh_spread;
bg_size += LV_MATH_MAX(LV_MATH_ABS(bg_sh_ox), LV_MATH_ABS(bg_sh_oy));
lv_style_int_t indic_sh_width = lv_obj_get_style_shadow_width(slider, LV_SLIDER_PART_INDIC);
lv_style_int_t indic_sh_spread = lv_obj_get_style_shadow_spread(slider, LV_SLIDER_PART_INDIC);
lv_style_int_t indic_sh_ox = lv_obj_get_style_shadow_offset_x(slider, LV_SLIDER_PART_INDIC);
lv_style_int_t indic_sh_oy = lv_obj_get_style_shadow_offset_y(slider, LV_SLIDER_PART_INDIC);
2019-09-16 10:58:28 +02:00
2019-12-31 22:13:32 +01:00
lv_coord_t indic_size = indic_sh_width + indic_sh_spread;
indic_size += LV_MATH_MAX(LV_MATH_ABS(indic_sh_ox), LV_MATH_ABS(indic_sh_oy));
2019-09-16 10:58:28 +02:00
slider->ext_draw_pad = LV_MATH_MAX(slider->ext_draw_pad, knob_size);
slider->ext_draw_pad = LV_MATH_MAX(slider->ext_draw_pad, indic_size);
slider->ext_draw_pad = LV_MATH_MAX(slider->ext_draw_pad, bg_size);
} else if(sign == LV_SIGNAL_CONTROL) {
2018-06-19 09:49:58 +02:00
char c = *((char *)param);
2019-04-08 14:36:20 +02:00
if(c == LV_KEY_RIGHT || c == LV_KEY_UP) {
2019-03-01 23:50:30 +01:00
lv_slider_set_value(slider, lv_slider_get_value(slider) + 1, true);
res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL);
2019-03-07 00:42:08 +01:00
if(res != LV_RES_OK) return res;
2019-04-08 14:36:20 +02:00
} else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) {
2019-03-01 23:50:30 +01:00
lv_slider_set_value(slider, lv_slider_get_value(slider) - 1, true);
res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL);
2019-03-07 00:42:08 +01:00
if(res != LV_RES_OK) return res;
2017-11-08 11:37:01 +01:00
}
} else if(sign == LV_SIGNAL_GET_EDITABLE) {
2018-10-05 17:22:49 +02:00
bool * editable = (bool *)param;
2019-04-04 07:15:40 +02:00
*editable = true;
2018-02-28 15:37:41 +01:00
}
2017-11-08 11:37:01 +01:00
return res;
2017-11-08 11:37:01 +01:00
}
2019-12-02 07:37:33 -05:00
2019-12-31 22:13:32 +01:00
static lv_style_list_t * lv_slider_get_style(lv_obj_t * slider, uint8_t part)
2019-12-31 22:13:32 +01:00
{
LV_ASSERT_OBJ(slider, LV_OBJX_NAME);
lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
lv_style_list_t * style_dsc_p;
2019-12-31 22:13:32 +01:00
switch(part) {
case LV_SLIDER_PART_BG:
2020-01-16 21:25:11 +01:00
style_dsc_p = &slider->style_list;
2019-12-31 22:13:32 +01:00
break;
case LV_SLIDER_PART_INDIC:
style_dsc_p = &ext->bar.style_indic;
break;
case LV_SLIDER_PART_KNOB:
style_dsc_p = &ext->style_knob;
break;
default:
style_dsc_p = NULL;
}
return style_dsc_p;
}
2019-12-02 07:37:33 -05:00
static void lv_slider_position_knob(lv_obj_t * slider, lv_area_t * knob_area, lv_coord_t knob_size, bool hor)
{
if(hor) {
knob_area->x1 -= (knob_size >> 1);
knob_area->x2 = knob_area->x1 + knob_size;
knob_area->y1 = slider->coords.y1;
knob_area->y2 = slider->coords.y2;
} else {
knob_area->y1 -= (knob_size >> 1);
knob_area->y2 = knob_area->y1 + knob_size;
knob_area->x1 = slider->coords.x1;
knob_area->x2 = slider->coords.x2;
}
lv_style_int_t knob_left = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_KNOB);
lv_style_int_t knob_right = lv_obj_get_style_pad_right(slider, LV_SLIDER_PART_KNOB);
lv_style_int_t knob_top = lv_obj_get_style_pad_top(slider, LV_SLIDER_PART_KNOB);
lv_style_int_t knob_bottom = lv_obj_get_style_pad_bottom(slider, LV_SLIDER_PART_KNOB);
2019-12-31 22:13:32 +01:00
2019-12-02 07:37:33 -05:00
/*Apply the paddings on the knob area*/
2019-12-31 22:13:32 +01:00
knob_area->x1 -= knob_left;
knob_area->x2 += knob_right;
knob_area->y1 -= knob_top;
knob_area->y2 += knob_bottom;
2019-12-02 07:37:33 -05:00
}
2019-12-31 22:13:32 +01:00
static void lv_slider_draw_knob(lv_obj_t * slider, const lv_area_t * knob_area, const lv_area_t * clip_area)
{
lv_draw_rect_dsc_t knob_rect_dsc;
lv_draw_rect_dsc_init(&knob_rect_dsc);
lv_obj_init_draw_rect_dsc(slider, LV_SLIDER_PART_KNOB, &knob_rect_dsc);
lv_draw_rect(knob_area, clip_area, &knob_rect_dsc);
2019-12-02 07:37:33 -05:00
}
2017-04-11 10:51:31 +02:00
#endif