1 
2 /**
3  * @file lv_slider.c
4  *
5  */
6 
7 /*********************
8  *      INCLUDES
9  *********************/
10 #include "lv_slider.h"
11 #if LV_USE_SLIDER != 0
12 
13 #include "../lv_core/lv_group.h"
14 #include "../lv_draw/lv_draw.h"
15 #include "../lv_themes/lv_theme.h"
16 #include "../lv_misc/lv_math.h"
17 
18 /*********************
19  *      DEFINES
20  *********************/
21 #define LV_SLIDER_SIZE_MIN 4 /*hor. pad and ver. pad cannot make the bar or indicator smaller then this [px]*/
22 #define LV_SLIDER_NOT_PRESSED INT16_MIN
23 
24 /**********************
25  *      TYPEDEFS
26  **********************/
27 
28 /**********************
29  *  STATIC PROTOTYPES
30  **********************/
31 static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_design_mode_t mode);
32 static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param);
33 
34 /**********************
35  *  STATIC VARIABLES
36  **********************/
37 static lv_design_cb_t ancestor_design_f;
38 static lv_signal_cb_t ancestor_signal;
39 
40 /**********************
41  *      MACROS
42  **********************/
43 
44 /**********************
45  *   GLOBAL FUNCTIONS
46  **********************/
47 
48 /**
49  * Create a slider objects
50  * @param par pointer to an object, it will be the parent of the new slider
51  * @param copy pointer to a slider object, if not NULL then the new object will be copied from it
52  * @return pointer to the created slider
53  */
lv_slider_create(lv_obj_t * par,const lv_obj_t * copy)54 lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy)
55 {
56     LV_LOG_TRACE("slider create started");
57 
58     /*Create the ancestor slider*/
59     lv_obj_t * new_slider = lv_bar_create(par, copy);
60     lv_mem_assert(new_slider);
61     if(new_slider == NULL) return NULL;
62 
63     if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_cb(new_slider);
64     if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(new_slider);
65 
66     /*Allocate the slider type specific extended data*/
67     lv_slider_ext_t * ext = lv_obj_allocate_ext_attr(new_slider, sizeof(lv_slider_ext_t));
68     lv_mem_assert(ext);
69     if(ext == NULL) return NULL;
70 
71     /*Initialize the allocated 'ext' */
72     ext->drag_value = LV_SLIDER_NOT_PRESSED;
73     ext->style_knob = &lv_style_pretty;
74     ext->knob_in    = 0;
75 
76     /*The signal and design functions are not copied so set them here*/
77     lv_obj_set_signal_cb(new_slider, lv_slider_signal);
78     lv_obj_set_design_cb(new_slider, lv_slider_design);
79 
80     /*Init the new slider slider*/
81     if(copy == NULL) {
82         lv_obj_set_click(new_slider, true);
83         lv_obj_set_protect(new_slider, LV_PROTECT_PRESS_LOST);
84 
85         /*Set the default styles*/
86         lv_theme_t * th = lv_theme_get_current();
87         if(th) {
88             lv_slider_set_style(new_slider, LV_SLIDER_STYLE_BG, th->style.slider.bg);
89             lv_slider_set_style(new_slider, LV_SLIDER_STYLE_INDIC, th->style.slider.indic);
90             lv_slider_set_style(new_slider, LV_SLIDER_STYLE_KNOB, th->style.slider.knob);
91         } else {
92             lv_slider_set_style(new_slider, LV_SLIDER_STYLE_KNOB, ext->style_knob);
93         }
94     }
95     /*Copy an existing slider*/
96     else {
97         lv_slider_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
98         ext->style_knob            = copy_ext->style_knob;
99         ext->knob_in               = copy_ext->knob_in;
100         /*Refresh the style with new signal function*/
101         lv_obj_refresh_style(new_slider);
102     }
103 
104     LV_LOG_INFO("slider created");
105 
106     return new_slider;
107 }
108 
109 /*=====================
110  * Setter functions
111  *====================*/
112 
113 /**
114  * Set the 'knob in' attribute of a slider
115  * @param slider pointer to slider object
116  * @param in true: the knob is drawn always in the slider;
117  *           false: the knob can be out on the edges
118  */
lv_slider_set_knob_in(lv_obj_t * slider,bool in)119 void lv_slider_set_knob_in(lv_obj_t * slider, bool in)
120 {
121     lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
122     if(ext->knob_in == in) return;
123 
124     ext->knob_in = in == false ? 0 : 1;
125     lv_obj_invalidate(slider);
126 }
127 
128 /**
129  * Set a style of a slider
130  * @param slider pointer to a slider object
131  * @param type which style should be set
132  * @param style pointer to a style
133  */
lv_slider_set_style(lv_obj_t * slider,lv_slider_style_t type,const lv_style_t * style)134 void lv_slider_set_style(lv_obj_t * slider, lv_slider_style_t type, const lv_style_t * style)
135 {
136     lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
137 
138     switch(type) {
139         case LV_SLIDER_STYLE_BG: lv_bar_set_style(slider, LV_BAR_STYLE_BG, style); break;
140         case LV_SLIDER_STYLE_INDIC: lv_bar_set_style(slider, LV_BAR_STYLE_INDIC, style); break;
141         case LV_SLIDER_STYLE_KNOB:
142             ext->style_knob = style;
143             lv_obj_refresh_ext_draw_pad(slider);
144             break;
145     }
146 }
147 
148 /*=====================
149  * Getter functions
150  *====================*/
151 
152 /**
153  * Get the value of a slider
154  * @param slider pointer to a slider object
155  * @return the value of the slider
156  */
lv_slider_get_value(const lv_obj_t * slider)157 int16_t lv_slider_get_value(const lv_obj_t * slider)
158 {
159     lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
160 
161     if(ext->drag_value != LV_SLIDER_NOT_PRESSED)
162         return ext->drag_value;
163     else
164         return lv_bar_get_value(slider);
165 }
166 
167 /**
168  * Give the slider is being dragged or not
169  * @param slider pointer to a slider object
170  * @return true: drag in progress false: not dragged
171  */
lv_slider_is_dragged(const lv_obj_t * slider)172 bool lv_slider_is_dragged(const lv_obj_t * slider)
173 {
174     lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
175     return ext->drag_value == LV_SLIDER_NOT_PRESSED ? false : true;
176 }
177 
178 /**
179  * Get the 'knob in' attribute of a slider
180  * @param slider pointer to slider object
181  * @return true: the knob is drawn always in the slider;
182  *         false: the knob can be out on the edges
183  */
lv_slider_get_knob_in(const lv_obj_t * slider)184 bool lv_slider_get_knob_in(const lv_obj_t * slider)
185 {
186     lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
187     return ext->knob_in == 0 ? false : true;
188 }
189 
190 /**
191  * Get a style of a slider
192  * @param slider pointer to a slider object
193  * @param type which style should be get
194  * @return style pointer to a style
195  */
lv_slider_get_style(const lv_obj_t * slider,lv_slider_style_t type)196 const lv_style_t * lv_slider_get_style(const lv_obj_t * slider, lv_slider_style_t type)
197 {
198     const lv_style_t * style = NULL;
199     lv_slider_ext_t * ext    = lv_obj_get_ext_attr(slider);
200 
201     switch(type) {
202         case LV_SLIDER_STYLE_BG: style = lv_bar_get_style(slider, LV_BAR_STYLE_BG); break;
203         case LV_SLIDER_STYLE_INDIC: style = lv_bar_get_style(slider, LV_BAR_STYLE_INDIC); break;
204         case LV_SLIDER_STYLE_KNOB: style = ext->style_knob; break;
205         default: style = NULL; break;
206     }
207 
208     return style;
209 }
210 
211 /**********************
212  *   STATIC FUNCTIONS
213  **********************/
214 
215 /**
216  * Handle the drawing related tasks of the sliders
217  * @param slider pointer to an object
218  * @param mask the object will be drawn only in this area
219  * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
220  *                                  (return 'true' if yes)
221  *             LV_DESIGN_DRAW: draw the object (always return 'true')
222  *             LV_DESIGN_DRAW_POST: drawing after every children are drawn
223  * @param return true/false, depends on 'mode'
224  */
lv_slider_design(lv_obj_t * slider,const lv_area_t * mask,lv_design_mode_t mode)225 static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_design_mode_t mode)
226 {
227     /*Return false if the object is not covers the mask_p area*/
228     if(mode == LV_DESIGN_COVER_CHK) {
229         return false;
230     }
231     /*Draw the object*/
232     else if(mode == LV_DESIGN_DRAW_MAIN) {
233         lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
234 
235         const lv_style_t * style_bg    = lv_slider_get_style(slider, LV_SLIDER_STYLE_BG);
236         const lv_style_t * style_knob  = lv_slider_get_style(slider, LV_SLIDER_STYLE_KNOB);
237         const lv_style_t * style_indic = lv_slider_get_style(slider, LV_SLIDER_STYLE_INDIC);
238 
239         lv_opa_t opa_scale = lv_obj_get_opa_scale(slider);
240 
241         lv_coord_t slider_w = lv_area_get_width(&slider->coords);
242         lv_coord_t slider_h = lv_area_get_height(&slider->coords);
243 
244         /*Draw the bar*/
245         lv_area_t area_bg;
246         lv_area_copy(&area_bg, &slider->coords);
247 
248         /*Be sure at least LV_SLIDER_SIZE_MIN  size will remain*/
249         lv_coord_t pad_top_bg    = style_bg->body.padding.top;
250         lv_coord_t pad_bottom_bg = style_bg->body.padding.bottom;
251         lv_coord_t pad_left_bg   = style_bg->body.padding.left;
252         lv_coord_t pad_right_bg  = style_bg->body.padding.right;
253         if(pad_top_bg + pad_bottom_bg + LV_SLIDER_SIZE_MIN > lv_area_get_height(&area_bg)) {
254             pad_top_bg    = (lv_area_get_height(&area_bg) - LV_SLIDER_SIZE_MIN) >> 1;
255             pad_bottom_bg = pad_top_bg;
256         }
257         if(pad_left_bg + pad_right_bg + LV_SLIDER_SIZE_MIN > lv_area_get_width(&area_bg)) {
258             pad_left_bg  = (lv_area_get_width(&area_bg) - LV_SLIDER_SIZE_MIN) >> 1;
259             pad_right_bg = (lv_area_get_width(&area_bg) - LV_SLIDER_SIZE_MIN) >> 1;
260         }
261 
262         if(ext->knob_in) { /*Enable extra size if the knob is inside */
263             area_bg.x1 += pad_left_bg;
264             area_bg.x2 -= pad_right_bg;
265             area_bg.y1 += pad_top_bg;
266             area_bg.y2 -= pad_bottom_bg;
267         } else {                                                   /*Let space only in the perpendicular directions*/
268             area_bg.x1 += slider_w < slider_h ? pad_left_bg : 0;   /*Pad only for vertical slider*/
269             area_bg.x2 -= slider_w < slider_h ? pad_right_bg : 0;  /*Pad only for vertical slider*/
270             area_bg.y1 += slider_w > slider_h ? pad_top_bg : 0;    /*Pad only for horizontal slider*/
271             area_bg.y2 -= slider_w > slider_h ? pad_bottom_bg : 0; /*Pad only for horizontal slider*/
272         }
273 
274 #if LV_USE_GROUP == 0
275         lv_draw_rect(&area_bg, mask, style_bg, lv_obj_get_opa_scale(slider));
276 #else
277         /* Draw the borders later if the slider is focused.
278          * At value = 100% the indicator can cover to whole background and the focused style won't
279          * be visible*/
280         if(lv_obj_is_focused(slider)) {
281             lv_style_t style_tmp;
282             lv_style_copy(&style_tmp, style_bg);
283             style_tmp.body.border.width = 0;
284             lv_draw_rect(&area_bg, mask, &style_tmp, opa_scale);
285         } else {
286             lv_draw_rect(&area_bg, mask, style_bg, opa_scale);
287         }
288 #endif
289 
290         /*Draw the indicator*/
291         lv_area_t area_indic;
292         lv_area_copy(&area_indic, &area_bg);
293 
294         /*Be sure at least ver pad/hor pad width indicator will remain*/
295         lv_coord_t pad_top_indic    = style_indic->body.padding.top;
296         lv_coord_t pad_bottom_indic = style_indic->body.padding.bottom;
297         lv_coord_t pad_left_indic   = style_indic->body.padding.left;
298         lv_coord_t pad_right_indic  = style_indic->body.padding.right;
299         if(pad_top_indic + pad_bottom_indic + LV_SLIDER_SIZE_MIN > lv_area_get_height(&area_bg)) {
300             pad_top_indic    = (lv_area_get_height(&area_bg) - LV_SLIDER_SIZE_MIN) >> 1;
301             pad_bottom_indic = pad_top_indic;
302         }
303         if(pad_left_indic + pad_right_indic + LV_SLIDER_SIZE_MIN > lv_area_get_width(&area_bg)) {
304             pad_left_indic  = (lv_area_get_width(&area_bg) - LV_SLIDER_SIZE_MIN) >> 1;
305             pad_right_indic = pad_left_indic;
306         }
307 
308         area_indic.x1 += pad_left_indic;
309         area_indic.x2 -= pad_right_indic;
310         area_indic.y1 += pad_top_indic;
311         area_indic.y2 -= pad_bottom_indic;
312 
313         lv_coord_t cur_value = lv_slider_get_value(slider);
314         lv_coord_t min_value = lv_slider_get_min_value(slider);
315         lv_coord_t max_value = lv_slider_get_max_value(slider);
316 
317         /*If dragged draw to the drag position*/
318         if(ext->drag_value != LV_SLIDER_NOT_PRESSED) cur_value = ext->drag_value;
319 
320         if(slider_w >= slider_h) {
321             lv_coord_t indic_w = lv_area_get_width(&area_indic);
322 #if LV_USE_ANIMATION
323             if(ext->bar.anim_state != LV_BAR_ANIM_STATE_INV) {
324                 /*Calculate the coordinates of anim. start and end*/
325                 lv_coord_t anim_start_x =
326                     (int32_t)((int32_t)indic_w * (ext->bar.anim_start - min_value)) / (max_value - min_value);
327                 lv_coord_t anim_end_x =
328                     (int32_t)((int32_t)indic_w * (ext->bar.anim_end - min_value)) / (max_value - min_value);
329 
330                 /*Calculate the real position based on `anim_state` (between `anim_start` and
331                  * `anim_end`)*/
332                 area_indic.x2 = anim_start_x + (((anim_end_x - anim_start_x) * ext->bar.anim_state) >> 8);
333             } else
334 #endif
335             {
336                 area_indic.x2 = (int32_t)((int32_t)indic_w * (cur_value - min_value)) / (max_value - min_value);
337             }
338             area_indic.x2 = area_indic.x1 + area_indic.x2 - 1;
339 
340             /*Draw the indicator but don't draw an ugly 1px wide rectangle on the left on min.
341              * value*/
342             if(area_indic.x1 != area_indic.x2) lv_draw_rect(&area_indic, mask, style_indic, opa_scale);
343 
344         } else {
345             lv_coord_t indic_h = lv_area_get_height(&area_indic);
346 #if LV_USE_ANIMATION
347             if(ext->bar.anim_state != LV_BAR_ANIM_STATE_INV) {
348                 /*Calculate the coordinates of anim. start and end*/
349                 lv_coord_t anim_start_y =
350                     (int32_t)((int32_t)indic_h * (ext->bar.anim_start - min_value)) / (max_value - min_value);
351                 lv_coord_t anim_end_y =
352                     (int32_t)((int32_t)indic_h * (ext->bar.anim_end - min_value)) / (max_value - min_value);
353 
354                 /*Calculate the real position based on `anim_state` (between `anim_start` and
355                  * `anim_end`)*/
356                 area_indic.y1 = anim_start_y + (((anim_end_y - anim_start_y) * ext->bar.anim_state) >> 8);
357             } else
358 #endif
359             {
360                 area_indic.y1 = (int32_t)((int32_t)indic_h * (cur_value - min_value)) / (max_value - min_value);
361             }
362             area_indic.y1 = area_indic.y2 - area_indic.y1 + 1;
363 
364             /*Draw the indicator but don't draw an ugly 1px height rectangle on the bottom on min.
365              * value*/
366             if(area_indic.x1 != area_indic.x2) lv_draw_rect(&area_indic, mask, style_indic, opa_scale);
367         }
368 
369         /*Before the knob add the border if required*/
370 #if LV_USE_GROUP
371         /* Draw the borders later if the bar is focused.
372          * At value = 100% the indicator can cover to whole background and the focused style won't
373          * be visible*/
374         if(lv_obj_is_focused(slider)) {
375             lv_style_t style_tmp;
376             lv_style_copy(&style_tmp, style_bg);
377             style_tmp.body.opa          = LV_OPA_TRANSP;
378             style_tmp.body.shadow.width = 0;
379             lv_draw_rect(&area_bg, mask, &style_tmp, opa_scale);
380         }
381 #endif
382 
383         /*Draw the knob*/
384         lv_area_t knob_area;
385         lv_area_copy(&knob_area, &slider->coords);
386 
387         if(slider_w >= slider_h) {
388             if(ext->knob_in == 0) {
389                 knob_area.x1 = area_indic.x2 - slider_h / 2;
390                 knob_area.x2 = knob_area.x1 + slider_h - 1;
391             } else {
392 #if LV_USE_ANIMATION
393                 if(ext->bar.anim_state != LV_BAR_ANIM_STATE_INV) {
394                     lv_coord_t w = slider_w - slider_h - 1;
395                     lv_coord_t anim_start_x =
396                         (int32_t)((int32_t)w * (ext->bar.anim_start - min_value)) / (max_value - min_value);
397                     lv_coord_t anim_end_x =
398                         (int32_t)((int32_t)w * (ext->bar.anim_end - min_value)) / (max_value - min_value);
399 
400                     /*Calculate the real position based on `anim_state` (between `anim_start` and
401                      * `anim_end`)*/
402                     knob_area.x1 = anim_start_x + (((anim_end_x - anim_start_x) * ext->bar.anim_state) >> 8);
403                 } else
404 #endif
405                 {
406                     knob_area.x1 = (int32_t)((int32_t)(slider_w - slider_h - 1) * (cur_value - min_value)) /
407                                    (max_value - min_value);
408                 }
409 
410                 knob_area.x1 += slider->coords.x1;
411                 knob_area.x2 = knob_area.x1 + slider_h - 1;
412             }
413 
414             knob_area.y1 = slider->coords.y1;
415             knob_area.y2 = slider->coords.y2;
416         } else {
417             if(ext->knob_in == 0) {
418                 knob_area.y1 = area_indic.y1 - slider_w / 2;
419                 knob_area.y2 = knob_area.y1 + slider_w - 1;
420             } else {
421 #if LV_USE_ANIMATION
422                 if(ext->bar.anim_state != LV_BAR_ANIM_STATE_INV) {
423                     lv_coord_t h = slider_h - slider_w - 1;
424                     lv_coord_t anim_start_x =
425                         (int32_t)((int32_t)h * (ext->bar.anim_start - min_value)) / (max_value - min_value);
426                     lv_coord_t anim_end_x =
427                         (int32_t)((int32_t)h * (ext->bar.anim_end - min_value)) / (max_value - min_value);
428 
429                     /*Calculate the real position based on `anim_state` (between `anim_start` and
430                      * `anim_end`)*/
431                     knob_area.y2 = anim_start_x + (((anim_end_x - anim_start_x) * ext->bar.anim_state) >> 8);
432                 } else
433 #endif
434                 {
435                     knob_area.y2 = (int32_t)((int32_t)(slider_h - slider_w - 1) * (cur_value - min_value)) /
436                                    (max_value - min_value);
437                 }
438 
439                 knob_area.y2 = slider->coords.y2 - knob_area.y2;
440                 knob_area.y1 = knob_area.y2 - slider_w - 1;
441             }
442             knob_area.x1 = slider->coords.x1;
443             knob_area.x2 = slider->coords.x2;
444         }
445         lv_draw_rect(&knob_area, mask, style_knob, opa_scale);
446     }
447     /*Post draw when the children are drawn*/
448     else if(mode == LV_DESIGN_DRAW_POST) {
449     }
450 
451     return true;
452 }
453 
454 /**
455  * Signal function of the slider
456  * @param slider pointer to a slider object
457  * @param sign a signal type from lv_signal_t enum
458  * @param param pointer to a signal specific variable
459  * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
460  */
lv_slider_signal(lv_obj_t * slider,lv_signal_t sign,void * param)461 static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param)
462 {
463     lv_res_t res;
464 
465     /* Include the ancient signal function */
466     res = ancestor_signal(slider, sign, param);
467     if(res != LV_RES_OK) return res;
468 
469     lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
470     lv_point_t p;
471     lv_coord_t w = lv_obj_get_width(slider);
472     lv_coord_t h = lv_obj_get_height(slider);
473 
474     if(sign == LV_SIGNAL_PRESSED) {
475         ext->drag_value = lv_slider_get_value(slider);
476     } else if(sign == LV_SIGNAL_PRESSING) {
477         lv_indev_get_point(param, &p);
478         int16_t tmp = 0;
479         if(w > h) {
480             lv_coord_t knob_w = h;
481             p.x -=
482                 slider->coords.x1 + h / 2; /*Modify the point to shift with half knob (important on the start and end)*/
483             tmp = (int32_t)((int32_t)p.x * (ext->bar.max_value - ext->bar.min_value + 1)) / (w - knob_w);
484             tmp += ext->bar.min_value;
485         } else {
486             lv_coord_t knob_h = w;
487             p.y -=
488                 slider->coords.y1 + w / 2; /*Modify the point to shift with half knob (important on the start and end)*/
489             tmp = (int32_t)((int32_t)p.y * (ext->bar.max_value - ext->bar.min_value + 1)) / (h - knob_h);
490             tmp = ext->bar.max_value - tmp; /*Invert the value: smaller value means higher y*/
491         }
492 
493         if(tmp < ext->bar.min_value)
494             tmp = ext->bar.min_value;
495         else if(tmp > ext->bar.max_value)
496             tmp = ext->bar.max_value;
497 
498         if(tmp != ext->drag_value) {
499             ext->drag_value = tmp;
500             lv_obj_invalidate(slider);
501             res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL);
502             if(res != LV_RES_OK) return res;
503         }
504     } else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
505         if(ext->drag_value != LV_SLIDER_NOT_PRESSED) lv_slider_set_value(slider, ext->drag_value, false);
506         ext->drag_value = LV_SLIDER_NOT_PRESSED;
507 
508 #if LV_USE_GROUP
509         /*Leave edit mode if released. (No need to wait for LONG_PRESS) */
510         lv_group_t * g             = lv_obj_get_group(slider);
511         bool editing               = lv_group_get_editing(g);
512         lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
513         if(indev_type == LV_INDEV_TYPE_ENCODER) {
514             if(editing) lv_group_set_editing(g, false);
515         }
516 #endif
517 
518     } else if(sign == LV_SIGNAL_CORD_CHG) {
519         /* The knob size depends on slider size.
520          * During the drawing method the ext. size is used by the knob so refresh the ext. size.*/
521         if(lv_obj_get_width(slider) != lv_area_get_width(param) ||
522            lv_obj_get_height(slider) != lv_area_get_height(param)) {
523             slider->signal_cb(slider, LV_SIGNAL_REFR_EXT_DRAW_PAD, NULL);
524         }
525     } else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
526         const lv_style_t * style      = lv_slider_get_style(slider, LV_SLIDER_STYLE_BG);
527         const lv_style_t * knob_style = lv_slider_get_style(slider, LV_SLIDER_STYLE_KNOB);
528 
529         lv_coord_t shadow_w = knob_style->body.shadow.width;
530         if(ext->knob_in == 0) {
531             /* The smaller size is the knob diameter*/
532             lv_coord_t x = LV_MATH_MIN(w / 2 + 1 + shadow_w, h / 2 + 1 + shadow_w);
533             if(slider->ext_draw_pad < x) slider->ext_draw_pad = x;
534         } else {
535             lv_coord_t pad = 0;
536             pad            = LV_MATH_MIN(pad, style->body.padding.top);
537             pad            = LV_MATH_MIN(pad, style->body.padding.bottom);
538             pad            = LV_MATH_MIN(pad, style->body.padding.left);
539             pad            = LV_MATH_MIN(pad, style->body.padding.right);
540             if(pad < 0) pad = -pad;
541             if(slider->ext_draw_pad < pad) slider->ext_draw_pad = pad;
542 
543             if(slider->ext_draw_pad < shadow_w) slider->ext_draw_pad = shadow_w;
544         }
545     } else if(sign == LV_SIGNAL_CONTROL) {
546         char c = *((char *)param);
547 
548         ext->drag_value = LV_SLIDER_NOT_PRESSED;
549 
550         if(c == LV_KEY_RIGHT || c == LV_KEY_UP) {
551             lv_slider_set_value(slider, lv_slider_get_value(slider) + 1, true);
552             res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL);
553             if(res != LV_RES_OK) return res;
554         } else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) {
555             lv_slider_set_value(slider, lv_slider_get_value(slider) - 1, true);
556             res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL);
557             if(res != LV_RES_OK) return res;
558         }
559     } else if(sign == LV_SIGNAL_GET_EDITABLE) {
560         bool * editable = (bool *)param;
561         *editable       = true;
562     } else if(sign == LV_SIGNAL_GET_TYPE) {
563         lv_obj_type_t * buf = param;
564         uint8_t i;
565         for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
566             if(buf->type[i] == NULL) break;
567         }
568         buf->type[i] = "lv_slider";
569     }
570 
571     return res;
572 }
573 #endif
574