BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lvgl
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
lvgl
Commits
61c5777a
Commit
61c5777a
authored
Aug 18, 2017
by
Gabor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lv_slider: knob_in + handle negative hpad/vpad to make bigger bg. then knob
parent
6852f6ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
12 deletions
+80
-12
lv_slider.c
lv_objx/lv_slider.c
+63
-12
lv_slider.h
lv_objx/lv_slider.h
+17
-0
No files found.
lv_objx/lv_slider.c
View file @
61c5777a
...
...
@@ -65,6 +65,7 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy)
ext
->
cb
=
NULL
;
ext
->
tmp_value
=
ext
->
bar
.
min_value
;
ext
->
style_knob
=
lv_style_get
(
LV_STYLE_PRETTY
,
NULL
);
ext
->
knob_in
=
0
;
/* Save the bar 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)
lv_slider_ext_t
*
copy_ext
=
lv_obj_get_ext
(
copy
);
ext
->
style_knob
=
copy_ext
->
style_knob
;
ext
->
cb
=
copy_ext
->
cb
;
ext
->
knob_in
=
copy_ext
->
knob_in
;
/*Refresh the style with new signal function*/
lv_obj_refr_style
(
new_slider
);
}
...
...
@@ -120,11 +122,13 @@ bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param)
else
if
(
sign
==
LV_SIGNAL_PRESSING
)
{
lv_dispi_get_point
(
param
,
&
p
);
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)*/
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
{
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)*/
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*/
}
...
...
@@ -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
);
}
}
else
if
(
sign
==
LV_SIGNAL_REFR_EXT_SIZE
)
{
cord_t
x
=
MATH_MIN
(
w
,
h
);
if
(
slider
->
ext_size
<
x
)
slider
->
ext_size
=
x
;
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
;
}
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
)
{
lv_slider_ext_t
*
ext
=
lv_obj_get_ext
(
slider
);
char
c
=
*
((
char
*
)
param
);
...
...
@@ -194,6 +208,17 @@ void lv_slider_set_style_knob(lv_obj_t * slider, lv_style_t * style)
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
...
...
@@ -220,6 +245,18 @@ lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider)
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
**********************/
...
...
@@ -243,6 +280,8 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m
}
/*Draw the object*/
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_knob
=
lv_slider_get_style_knob
(
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
area_t
area_bar
;
area_cpy
(
&
area_bar
,
&
slider
->
cords
);
/*Be sure at least vpad/hpad width bar will remain*/
cord_t
vpad_bar
=
style_
indic
->
vpad
;
cord_t
hpad_bar
=
style_
indic
->
hpad
;
cord_t
vpad_bar
=
style_
slider
->
vpad
;
cord_t
hpad_bar
=
style_
slider
->
hpad
;
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
;
}
...
...
@@ -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
)
{
area_indic
.
x2
=
(
int32_t
)
((
int32_t
)
area_get_width
(
&
area_indic
)
*
act_value
)
/
(
max_value
-
min_value
);
area_indic
.
x2
+=
area_indic
.
x1
;
}
else
{
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
;
}
/*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_cpy
(
&
knob_area
,
&
slider
->
cords
);
if
(
slider_w
>=
slider_h
)
{
knob_area
.
x1
=
area_indic
.
x2
-
slider_h
/
2
;
knob_area
.
x2
=
knob_area
.
x1
+
slider_h
;
if
(
ext
->
knob_in
==
0
)
{
knob_area
.
x1
=
area_indic
.
x2
-
slider_h
/
2
;
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
.
y2
=
slider
->
cords
.
y2
;
}
else
{
knob_area
.
y1
=
area_indic
.
y1
-
slider_w
/
2
;
knob_area
.
y2
=
knob_area
.
y1
+
slider_w
;
if
(
ext
->
knob_in
==
0
)
{
knob_area
.
y1
=
area_indic
.
y1
-
slider_w
/
2
;
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
.
x2
=
slider
->
cords
.
x2
;
...
...
lv_objx/lv_slider.h
View file @
61c5777a
...
...
@@ -34,6 +34,7 @@ typedef struct
lv_action_t
cb
;
/*Function to call when a new value is set*/
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)*/
uint8_t
knob_in
:
1
;
/*1: Draw the knob inside the bar*/
}
lv_slider_ext_t
;
/*Built-in styles of slider*/
...
...
@@ -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
);
/**
* 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
* @param slider pointer to slider object
* @return the callback function
...
...
@@ -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
);
/**
* 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
**********************/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment