BigW Consortium Gitlab

Commit 61c5777a by Gabor

lv_slider: knob_in + handle negative hpad/vpad to make bigger bg. then knob

parent 6852f6ee
...@@ -65,6 +65,7 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy) ...@@ -65,6 +65,7 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy)
ext->cb = NULL; ext->cb = NULL;
ext->tmp_value = ext->bar.min_value; ext->tmp_value = ext->bar.min_value;
ext->style_knob = lv_style_get(LV_STYLE_PRETTY, NULL); ext->style_knob = lv_style_get(LV_STYLE_PRETTY, NULL);
ext->knob_in = 0;
/* Save the bar design function. /* Save the bar design function.
* It will be used in the sllider design function*/ * It will be used in the sllider design function*/
...@@ -84,6 +85,7 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy) ...@@ -84,6 +85,7 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy)
lv_slider_ext_t * copy_ext = lv_obj_get_ext(copy); lv_slider_ext_t * copy_ext = lv_obj_get_ext(copy);
ext->style_knob = copy_ext->style_knob; ext->style_knob = copy_ext->style_knob;
ext->cb = copy_ext->cb; ext->cb = copy_ext->cb;
ext->knob_in = copy_ext->knob_in;
/*Refresh the style with new signal function*/ /*Refresh the style with new signal function*/
lv_obj_refr_style(new_slider); lv_obj_refr_style(new_slider);
} }
...@@ -120,11 +122,13 @@ bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param) ...@@ -120,11 +122,13 @@ bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param)
else if(sign == LV_SIGNAL_PRESSING) { else if(sign == LV_SIGNAL_PRESSING) {
lv_dispi_get_point(param, &p); lv_dispi_get_point(param, &p);
if(w > h) { if(w > h) {
cord_t knob_w = h;
p.x -= slider->cords.x1 + h / 2; /*Modify the point to shift with half knob (important on the start and end)*/ p.x -= slider->cords.x1 + h / 2; /*Modify the point to shift with half knob (important on the start and end)*/
tmp = (int32_t) ((int32_t) p.x * (ext->bar.max_value - ext->bar.min_value + 1)) / (w - h); tmp = (int32_t) ((int32_t) p.x * (ext->bar.max_value - ext->bar.min_value + 1)) / (w - knob_w);
} else { } else {
cord_t knob_h = w;
p.y -= slider->cords.y1 + w / 2; /*Modify the point to shift with half knob (important on the start and end)*/ p.y -= slider->cords.y1 + w / 2; /*Modify the point to shift with half knob (important on the start and end)*/
tmp = (int32_t) ((int32_t) p.y * (ext->bar.max_value - ext->bar.min_value + 1)) / (h - w); tmp = (int32_t) ((int32_t) p.y * (ext->bar.max_value - ext->bar.min_value + 1)) / (h - knob_h);
tmp = ext->bar.max_value - tmp; /*Invert he value: small value means higher y*/ tmp = ext->bar.max_value - tmp; /*Invert he value: small value means higher y*/
} }
...@@ -146,8 +150,18 @@ bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param) ...@@ -146,8 +150,18 @@ bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param)
slider->signal_f(slider, LV_SIGNAL_REFR_EXT_SIZE, NULL); slider->signal_f(slider, LV_SIGNAL_REFR_EXT_SIZE, NULL);
} }
} else if(sign == LV_SIGNAL_REFR_EXT_SIZE) { } else if(sign == LV_SIGNAL_REFR_EXT_SIZE) {
cord_t x = MATH_MIN(w, h); if(ext->knob_in == 0) {
cord_t x = MATH_MIN(w, h); /*The smaller size is the knob diameter*/
if(slider->ext_size < x) slider->ext_size = x; if(slider->ext_size < x) slider->ext_size = x;
} else {
lv_style_t * style = lv_obj_get_style(slider);
cord_t pad = MATH_MIN(style->hpad, style->vpad);
if(pad < 0) {
pad = -pad;
if(slider->ext_size < pad) slider->ext_size = pad;
}
}
} else if(sign == LV_SIGNAL_CONTROLL) { } else if(sign == LV_SIGNAL_CONTROLL) {
lv_slider_ext_t * ext = lv_obj_get_ext(slider); lv_slider_ext_t * ext = lv_obj_get_ext(slider);
char c = *((char*)param); char c = *((char*)param);
...@@ -194,6 +208,17 @@ void lv_slider_set_style_knob(lv_obj_t * slider, lv_style_t * style) ...@@ -194,6 +208,17 @@ void lv_slider_set_style_knob(lv_obj_t * slider, lv_style_t * style)
lv_obj_inv(slider); lv_obj_inv(slider);
} }
/**
* Set the 'knob in' attribute of a slider
* @param slider pointer to slider object
* @param in true: the knob is drawn always in the slider;
* false: the knob can be out on the edges
*/
void lv_slider_set_knob_in(lv_obj_t * slider, bool in)
{
lv_slider_ext_t * ext = lv_obj_get_ext(slider);
ext->knob_in = in == false ? 0 : 1;
}
/*===================== /*=====================
* Getter functions * Getter functions
...@@ -220,6 +245,18 @@ lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider) ...@@ -220,6 +245,18 @@ lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider)
return ext->style_knob; return ext->style_knob;
} }
/**
* Get the 'knob in' attribute of a slider
* @param slider pointer to slider object
* @return true: the knob is drawn always in the slider;
* false: the knob can be out on the edges
*/
bool lv_slider_get_knob_in(lv_obj_t * slider)
{
lv_slider_ext_t * ext = lv_obj_get_ext(slider);
return ext->knob_in == 0 ? false : true;
}
/********************** /**********************
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
...@@ -243,6 +280,8 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m ...@@ -243,6 +280,8 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m
} }
/*Draw the object*/ /*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) { else if(mode == LV_DESIGN_DRAW_MAIN) {
lv_slider_ext_t * ext = lv_obj_get_ext(slider);
lv_style_t * style_slider = lv_obj_get_style(slider); lv_style_t * style_slider = lv_obj_get_style(slider);
lv_style_t * style_knob = lv_slider_get_style_knob(slider); lv_style_t * style_knob = lv_slider_get_style_knob(slider);
lv_style_t * style_indic = lv_bar_get_style_indic(slider); lv_style_t * style_indic = lv_bar_get_style_indic(slider);
...@@ -251,8 +290,8 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m ...@@ -251,8 +290,8 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m
area_t area_bar; area_t area_bar;
area_cpy(&area_bar, &slider->cords); area_cpy(&area_bar, &slider->cords);
/*Be sure at least vpad/hpad width bar will remain*/ /*Be sure at least vpad/hpad width bar will remain*/
cord_t vpad_bar = style_indic->vpad; cord_t vpad_bar = style_slider->vpad;
cord_t hpad_bar = style_indic->hpad; cord_t hpad_bar = style_slider->hpad;
if(vpad_bar * 2 + LV_SLIDER_SIZE_MIN > area_get_height(&area_bar)) { if(vpad_bar * 2 + LV_SLIDER_SIZE_MIN > area_get_height(&area_bar)) {
vpad_bar = (area_get_height(&area_bar) - LV_SLIDER_SIZE_MIN) >> 1; vpad_bar = (area_get_height(&area_bar) - LV_SLIDER_SIZE_MIN) >> 1;
} }
...@@ -295,27 +334,39 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m ...@@ -295,27 +334,39 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m
if(slider_w >= slider_h) { if(slider_w >= slider_h) {
area_indic.x2 = (int32_t) ((int32_t)area_get_width(&area_indic) * act_value) / (max_value - min_value); area_indic.x2 = (int32_t) ((int32_t)area_get_width(&area_indic) * act_value) / (max_value - min_value);
area_indic.x2 += area_indic.x1; area_indic.x2 += area_indic.x1;
} else { } else {
area_indic.y1 = (int32_t) ((int32_t)area_get_height(&area_indic) * act_value) / (max_value - min_value); area_indic.y1 = (int32_t) ((int32_t)area_get_height(&area_indic) * act_value) / (max_value - min_value);
area_indic.y1 = area_indic.y2 - area_indic.y1; area_indic.y1 = area_indic.y2 - area_indic.y1;
} }
/*Draw the indicator*/ /*Draw the indicator*/
lv_draw_rect(&area_indic, mask, style_indic); if(act_value != min_value) lv_draw_rect(&area_indic, mask, style_indic);
area_t knob_area; area_t knob_area;
area_cpy(&knob_area, &slider->cords); area_cpy(&knob_area, &slider->cords);
if(slider_w >= slider_h) { if(slider_w >= slider_h) {
if(ext->knob_in == 0) {
knob_area.x1 = area_indic.x2 - slider_h / 2; knob_area.x1 = area_indic.x2 - slider_h / 2;
knob_area.x2 = knob_area.x1 + slider_h; knob_area.x2 = knob_area.x1 + slider_h;
} else {
knob_area.x1 = (int32_t) ((int32_t)(slider_w - slider_h) * act_value) / (max_value - min_value);
knob_area.x1 += slider->cords.x1;
knob_area.x2 = knob_area.x1 + slider_h;
}
knob_area.y1 = slider->cords.y1; knob_area.y1 = slider->cords.y1;
knob_area.y2 = slider->cords.y2; knob_area.y2 = slider->cords.y2;
} else { } else {
if(ext->knob_in == 0) {
knob_area.y1 = area_indic.y1 - slider_w / 2; knob_area.y1 = area_indic.y1 - slider_w / 2;
knob_area.y2 = knob_area.y1 + slider_w; knob_area.y2 = knob_area.y1 + slider_w;
} else {
knob_area.y2 = (int32_t) ((int32_t)(slider_h - slider_w) * act_value) / (max_value - min_value);
knob_area.y2 = slider->cords.y2 - knob_area.y2;
knob_area.y1 = knob_area.y2 - slider_w;
}
knob_area.x1 = slider->cords.x1; knob_area.x1 = slider->cords.x1;
knob_area.x2 = slider->cords.x2; knob_area.x2 = slider->cords.x2;
......
...@@ -34,6 +34,7 @@ typedef struct ...@@ -34,6 +34,7 @@ typedef struct
lv_action_t cb; /*Function to call when a new value is set*/ lv_action_t cb; /*Function to call when a new value is set*/
lv_style_t * style_knob; /*Style of the knob*/ lv_style_t * style_knob; /*Style of the knob*/
int16_t tmp_value; /*Store a temporal value during press until release (Handled by the library)*/ int16_t tmp_value; /*Store a temporal value during press until release (Handled by the library)*/
uint8_t knob_in :1; /*1: Draw the knob inside the bar*/
}lv_slider_ext_t; }lv_slider_ext_t;
/*Built-in styles of slider*/ /*Built-in styles of slider*/
...@@ -78,6 +79,14 @@ void lv_slider_set_action(lv_obj_t * slider, lv_action_t cb); ...@@ -78,6 +79,14 @@ void lv_slider_set_action(lv_obj_t * slider, lv_action_t cb);
void lv_slider_set_style_knob(lv_obj_t * slider, lv_style_t * style); void lv_slider_set_style_knob(lv_obj_t * slider, lv_style_t * style);
/** /**
* Set the 'knob in' attribute of a slider
* @param slider pointer to slider object
* @param in true: the knob is drawn always in the slider;
* false: the knob can be out on the edges
*/
void lv_slider_set_knob_in(lv_obj_t * slider, bool in);
/**
* Get the slider callback function * Get the slider callback function
* @param slider pointer to slider object * @param slider pointer to slider object
* @return the callback function * @return the callback function
...@@ -91,6 +100,14 @@ lv_action_t lv_slider_get_action(lv_obj_t * slider); ...@@ -91,6 +100,14 @@ lv_action_t lv_slider_get_action(lv_obj_t * slider);
*/ */
lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider); lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider);
/**
* Get the 'knob in' attribute of a slider
* @param slider pointer to slider object
* @return true: the knob is drawn always in the slider;
* false: the knob can be out on the edges
*/
bool lv_slider_get_knob_in(lv_obj_t * slider);
/********************** /**********************
* MACROS * MACROS
**********************/ **********************/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment