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
a2ab0cde
Commit
a2ab0cde
authored
Nov 08, 2017
by
Gabor Kiss-Vamosi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mbox: add btn width attribute
parent
d6739192
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
150 additions
and
63 deletions
+150
-63
lv_bar.c
lv_objx/lv_bar.c
+29
-30
lv_bar.h
lv_objx/lv_bar.h
+0
-8
lv_mbox.c
lv_objx/lv_mbox.c
+77
-4
lv_mbox.h
lv_objx/lv_mbox.h
+35
-14
lv_slider.c
lv_objx/lv_slider.c
+5
-5
lv_slider.h
lv_objx/lv_slider.h
+0
-1
lv_sw.c
lv_objx/lv_sw.c
+4
-1
No files found.
lv_objx/lv_bar.c
View file @
a2ab0cde
...
...
@@ -28,11 +28,13 @@
* STATIC PROTOTYPES
**********************/
static
bool
lv_bar_design
(
lv_obj_t
*
bar
,
const
area_t
*
mask
,
lv_design_mode_t
mode
);
static
lv_res_t
lv_bar_signal
(
lv_obj_t
*
bar
,
lv_signal_t
sign
,
void
*
param
);
/**********************
* STATIC VARIABLES
**********************/
static
lv_design_func_t
ancestor_design_f
;
static
lv_signal_func_t
ancestor_signal
;
/**********************
* MACROS
...
...
@@ -58,6 +60,9 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy)
lv_obj_t
*
new_bar
=
lv_obj_create
(
par
,
copy
);
dm_assert
(
new_bar
);
if
(
ancestor_signal
==
NULL
)
ancestor_signal
=
lv_obj_get_signal_func
(
new_bar
);
if
(
ancestor_design_f
==
NULL
)
ancestor_design_f
=
lv_obj_get_design_func
(
new_bar
);
/*Allocate the object type specific extended data*/
lv_bar_ext_t
*
ext
=
lv_obj_allocate_ext_attr
(
new_bar
,
sizeof
(
lv_bar_ext_t
));
dm_assert
(
ext
);
...
...
@@ -66,10 +71,6 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy)
ext
->
cur_value
=
0
;
ext
->
style_inicator
=
&
lv_style_pretty_color
;
/* Save the ancient design function.
* It will be used in the bar design function*/
if
(
ancestor_design_f
==
NULL
)
ancestor_design_f
=
lv_obj_get_design_func
(
new_bar
);
lv_obj_set_signal_func
(
new_bar
,
lv_bar_signal
);
lv_obj_set_design_func
(
new_bar
,
lv_bar_design
);
...
...
@@ -93,32 +94,6 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy)
return
new_bar
;
}
/**
* Signal function of the bar
* @param bar pointer to a bar object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
*/
bool
lv_bar_signal
(
lv_obj_t
*
bar
,
lv_signal_t
sign
,
void
*
param
)
{
bool
valid
;
/* Include the ancient signal function */
valid
=
lv_obj_signal
(
bar
,
sign
,
param
);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if
(
valid
!=
false
)
{
if
(
sign
==
LV_SIGNAL_REFR_EXT_SIZE
)
{
lv_style_t
*
style_indic
=
lv_bar_get_style_indicator
(
bar
);
if
(
style_indic
->
body
.
shadow
.
width
>
bar
->
ext_size
)
bar
->
ext_size
=
style_indic
->
body
.
shadow
.
width
;
}
}
return
valid
;
}
/*=====================
* Setter functions
*====================*/
...
...
@@ -311,4 +286,28 @@ static bool lv_bar_design(lv_obj_t * bar, const area_t * mask, lv_design_mode_t
return
true
;
}
/**
* Signal function of the bar
* @param bar pointer to a bar 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_bar_signal
(
lv_obj_t
*
bar
,
lv_signal_t
sign
,
void
*
param
)
{
lv_res_t
res
;
/* Include the ancient signal function */
res
=
ancestor_signal
(
bar
,
sign
,
param
);
if
(
res
!=
LV_RES_OK
)
return
res
;
if
(
sign
==
LV_SIGNAL_REFR_EXT_SIZE
)
{
lv_style_t
*
style_indic
=
lv_bar_get_style_indicator
(
bar
);
if
(
style_indic
->
body
.
shadow
.
width
>
bar
->
ext_size
)
bar
->
ext_size
=
style_indic
->
body
.
shadow
.
width
;
}
return
LV_RES_OK
;
}
#endif
lv_objx/lv_bar.h
View file @
a2ab0cde
...
...
@@ -53,14 +53,6 @@ typedef struct
lv_obj_t
*
lv_bar_create
(
lv_obj_t
*
par
,
lv_obj_t
*
copy
);
/**
* Signal function of the bar
* @param bar pointer to a bar object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
*/
bool
lv_bar_signal
(
lv_obj_t
*
bar
,
lv_signal_t
sign
,
void
*
param
);
/**
* Set a new value on the bar
* @param bar pointer to a bar object
* @param value new value
...
...
lv_objx/lv_mbox.c
View file @
a2ab0cde
...
...
@@ -68,6 +68,7 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy)
ext
->
style_btn_rel
=
&
lv_style_btn_off_released
;
ext
->
style_btn_pr
=
&
lv_style_btn_off_pressed
;
ext
->
anim_time
=
LV_MBOX_CLOSE_ANIM_TIME
;
ext
->
btn_width
=
0
;
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_func
(
new_mbox
,
lv_mbox_signal
);
...
...
@@ -78,6 +79,7 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy)
lv_cont_set_fit
(
new_mbox
,
true
,
true
);
ext
->
txt
=
lv_label_create
(
new_mbox
,
NULL
);
lv_label_set_align
(
ext
->
txt
,
LV_LABEL_ALIGN_CENTER
);
lv_label_set_text
(
ext
->
txt
,
"Message"
);
lv_obj_set_style
(
new_mbox
,
&
lv_style_pretty
);
...
...
@@ -87,6 +89,7 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy)
lv_mbox_ext_t
*
copy_ext
=
lv_obj_get_ext_attr
(
copy
);
ext
->
txt
=
lv_label_create
(
new_mbox
,
copy_ext
->
txt
);
ext
->
btn_width
=
copy_ext
->
btn_width
;
/*Copy the buttons and the label on them*/
if
(
copy_ext
->
btnh
!=
NULL
)
{
...
...
@@ -97,6 +100,10 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy)
lv_mbox_add_btn
(
new_mbox
,
btn_txt_copy
,
lv_btn_get_action
(
btn_copy
,
LV_BTN_ACTION_RELEASE
));
}
}
lv_mbox_set_style
(
new_mbox
,
lv_mbox_get_style_bg
(
copy
),
lv_mbox_get_style_btnh
(
copy
));
lv_mbox_set_style_btn
(
new_mbox
,
copy_ext
->
style_btn_rel
,
copy_ext
->
style_btn_pr
);
/*Refresh the style with new signal function*/
lv_obj_refresh_style
(
new_mbox
);
}
...
...
@@ -133,7 +140,7 @@ lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_action_t re
/*Create a button holder if it is not existed yet*/
if
(
ext
->
btnh
==
NULL
)
{
ext
->
btnh
=
lv_cont_create
(
mbox
,
NULL
);
lv_obj_set_style
(
ext
->
btnh
,
&
lv_style_
plain_color
);
lv_obj_set_style
(
ext
->
btnh
,
&
lv_style_
transp_fit
);
lv_obj_set_click
(
ext
->
btnh
,
false
);
lv_cont_set_fit
(
ext
->
btnh
,
false
,
true
);
lv_cont_set_layout
(
ext
->
btnh
,
LV_CONT_LAYOUT_PRETTY
);
...
...
@@ -142,7 +149,13 @@ lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_action_t re
lv_obj_t
*
btn
=
lv_btn_create
(
ext
->
btnh
,
NULL
);
lv_btn_set_action
(
btn
,
LV_BTN_ACTION_RELEASE
,
rel_action
);
lv_btn_set_style
(
btn
,
ext
->
style_btn_rel
,
ext
->
style_btn_pr
,
NULL
,
NULL
,
NULL
);
lv_cont_set_fit
(
btn
,
true
,
true
);
if
(
ext
->
btn_width
)
{
lv_btn_set_fit
(
btn
,
false
,
true
);
lv_obj_set_width
(
btn
,
ext
->
btn_width
);
}
else
{
lv_btn_set_fit
(
btn
,
true
,
true
);
}
lv_obj_t
*
label
=
lv_label_create
(
btn
,
NULL
);
lv_label_set_text
(
label
,
btn_txt
);
...
...
@@ -170,6 +183,44 @@ void lv_mbox_set_text(lv_obj_t * mbox, const char * txt)
}
/**
* Set the width of the buttons
* @param mbox pointer to message box object
* @param w width of the buttons or 0 to use auto fit
*/
void
lv_mbox_set_btn_width
(
lv_obj_t
*
mbox
,
cord_t
w
)
{
lv_mbox_ext_t
*
ext
=
lv_obj_get_ext_attr
(
mbox
);
ext
->
btn_width
=
w
;
if
(
ext
->
btnh
==
NULL
)
return
;
lv_obj_t
*
btn
=
lv_obj_get_child
(
ext
->
btnh
,
NULL
);
while
(
btn
!=
NULL
)
{
if
(
w
)
{
lv_btn_set_fit
(
btn
,
false
,
true
);
lv_obj_set_width
(
btn
,
w
);
}
else
{
lv_btn_set_fit
(
btn
,
true
,
true
);
}
btn
=
lv_obj_get_child
(
ext
->
btnh
,
btn
);
}
btnh_resize
(
mbox
);
}
/**
* Set the styles of a message box
* @param mbox pointer to a message box object
* @param bg pointer to the new background style
* @param btnh pointer to the new button holder style
*/
void
lv_mbox_set_style
(
lv_obj_t
*
mbox
,
lv_style_t
*
bg
,
lv_style_t
*
btnh
)
{
lv_mbox_ext_t
*
ext
=
lv_obj_get_ext_attr
(
mbox
);
lv_obj_set_style
(
ext
->
btnh
,
btnh
);
lv_obj_set_style
(
mbox
,
bg
);
}
/**
* Set styles of the buttons of a message box in each state
* @param mbox pointer to a message box object
* @param rel pointer to a style for releases state
...
...
@@ -252,6 +303,17 @@ const char * lv_mbox_get_text(lv_obj_t * mbox)
}
/**
* Get width of the buttons
* @param mbox pointer to a message box object
* @return width of the buttons (0: auto fit enabled)
*/
cord_t
lv_mbox_get_text
(
lv_obj_t
*
mbox
)
{
lv_mbox_ext_t
*
ext
=
lv_obj_get_ext_attr
(
mbox
);
return
ext
->
btn_width
;
}
/**
* Get the message box object from one of its button.
* It is useful in the button release actions where only the button is known
* @param btn pointer to a button of a message box
...
...
@@ -277,6 +339,18 @@ uint16_t lv_mbox_get_anim_time(lv_obj_t * mbox )
}
/**
* Get the style of a message box's button holder
* @param mbox pointer to a message box object
* @return pointer to the message box's background style
*/
lv_style_t
*
lv_mbox_get_style_btnh
(
lv_obj_t
*
mbox
)
{
lv_mbox_ext_t
*
ext
=
lv_obj_get_ext_attr
(
mbox
);
return
lv_obj_get_style
(
ext
->
btnh
);
}
/**
* Get the style of the buttons on a message box
* @param mbox pointer to a message box object
* @param state a state from 'lv_btn_state_t' in which style should be get
...
...
@@ -435,8 +509,7 @@ static void btnh_resize(lv_obj_t *mbox)
lv_mbox_ext_t
*
ext
=
lv_obj_get_ext_attr
(
mbox
);
if
(
ext
->
btnh
==
NULL
)
return
;
lv_style_t
*
bg_style
=
lv_mbox_get_style
(
mbox
);
lv_style_t
*
btnh_style
=
lv_mbox_get_style
(
ext
->
btnh
);
lv_style_t
*
btnh_style
=
lv_mbox_get_style_bg
(
ext
->
btnh
);
cord_t
btnh_req_w
=
2
*
btnh_style
->
body
.
padding
.
hor
;
lv_obj_t
*
btn
=
lv_obj_get_child
(
ext
->
btnh
,
NULL
);
...
...
lv_objx/lv_mbox.h
View file @
a2ab0cde
...
...
@@ -52,7 +52,8 @@ typedef struct
lv_obj_t
*
btnh
;
/*Holder of the buttons*/
lv_style_t
*
style_btn_rel
;
/*Style of the released buttons*/
lv_style_t
*
style_btn_pr
;
/*Style of the pressed buttons*/
uint16_t
anim_time
;
/*Duration of close animation [ms] (0: no animation)*/
uint16_t
anim_time
;
/*Duration of close animation [ms] (0: no animation)*/
cord_t
btn_width
;
/*Button width (0: to auto fit)*/
}
lv_mbox_ext_t
;
/**********************
...
...
@@ -91,6 +92,21 @@ lv_obj_t * lv_mbox_add_btn(lv_obj_t * mbox, const char * btn_txt, lv_action_t re
void
lv_mbox_set_text
(
lv_obj_t
*
mbox
,
const
char
*
txt
);
/**
* Set the width of the buttons
* @param mbox pointer to message box object
* @param w width of the buttons or 0 to use auto fit
*/
void
lv_mbox_set_btn_width
(
lv_obj_t
*
mbox
,
cord_t
w
);
/**
* Set the styles of a message box
* @param mbox pointer to a message box object
* @param bg pointer to the new background style
* @param btnh pointer to the new button holder style
*/
void
lv_mbox_set_style
(
lv_obj_t
*
mbox
,
lv_style_t
*
bg
,
lv_style_t
*
btnh
);
/**
* Set styles of the buttons of a message box in each state
* @param mbox pointer to a message box object
* @param rel pointer to a style for releases state
...
...
@@ -126,6 +142,13 @@ void lv_mbox_stop_auto_close(lv_obj_t * mbox);
const
char
*
lv_mbox_get_text
(
lv_obj_t
*
mbox
);
/**
* Get width of the buttons
* @param mbox pointer to a message box object
* @return width of the buttons (0: auto fit enabled)
*/
cord_t
lv_mbox_get_text
(
lv_obj_t
*
mbox
);
/**
* Get the message box object from one of its button.
* It is useful in the button release actions where only the button is known
* @param btn pointer to a button of a message box
...
...
@@ -148,30 +171,28 @@ uint16_t lv_mbox_get_anim_time(lv_obj_t * mbox );
*/
lv_style_t
*
lv_mbox_get_style_btn
(
lv_obj_t
*
mbox
,
lv_btn_state_t
state
);
/****************************
* TRANSPARENT API FUNCTIONS
***************************/
/**
*
Set the style of a message box
*
Get the style of a message box's button holder
* @param mbox pointer to a message box object
* @
param style pointer to the new
style
* @
return pointer to the message box's background
style
*/
static
inline
void
lv_mbox_set_style
(
lv_obj_t
*
mbox
,
lv_style_t
*
style
)
{
lv_obj_set_style
(
mbox
,
style
);
}
lv_style_t
*
lv_mbox_get_style_btnh
(
lv_obj_t
*
mbox
);
/******************************
* TRANSPARENT API FUNCTIONS
******************************/
/**
* Get the style of a message box
* Get the style of a message box
's background
* @param mbox pointer to a message box object
* @return pointer to the message box's style
* @return pointer to the message box's
background
style
*/
static
inline
lv_style_t
*
lv_mbox_get_style
(
lv_obj_t
*
mbox
)
static
inline
lv_style_t
*
lv_mbox_get_style
_bg
(
lv_obj_t
*
mbox
)
{
return
lv_obj_get_style
(
mbox
);
}
/**********************
* MACROS
**********************/
...
...
lv_objx/lv_slider.c
View file @
a2ab0cde
...
...
@@ -32,6 +32,7 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m
* STATIC VARIABLES
**********************/
static
lv_design_func_t
ancestor_design_f
;
static
lv_signal_func_t
ancestor_signal
;
/**********************
* MACROS
...
...
@@ -57,6 +58,9 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy)
lv_obj_t
*
new_slider
=
lv_bar_create
(
par
,
copy
);
dm_assert
(
new_slider
);
if
(
ancestor_design_f
==
NULL
)
ancestor_design_f
=
lv_obj_get_design_func
(
new_slider
);
if
(
ancestor_signal
==
NULL
)
ancestor_signal
=
lv_obj_get_signal_func
(
new_slider
);
/*Allocate the slider type specific extended data*/
lv_slider_ext_t
*
ext
=
lv_obj_allocate_ext_attr
(
new_slider
,
sizeof
(
lv_slider_ext_t
));
dm_assert
(
ext
);
...
...
@@ -67,10 +71,6 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy)
ext
->
style_knob
=
&
lv_style_pretty
;
ext
->
knob_in
=
0
;
/* Save the bar design function.
* It will be used in the sllider design function*/
if
(
ancestor_design_f
==
NULL
)
ancestor_design_f
=
lv_obj_get_design_func
(
new_slider
);
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_func
(
new_slider
,
lv_slider_signal
);
lv_obj_set_design_func
(
new_slider
,
lv_slider_design
);
...
...
@@ -105,7 +105,7 @@ bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param)
bool
valid
;
/* Include the ancient signal function */
valid
=
lv_ba
r_signal
(
slider
,
sign
,
param
);
valid
=
ancesto
r_signal
(
slider
,
sign
,
param
);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
...
...
lv_objx/lv_slider.h
View file @
a2ab0cde
...
...
@@ -111,7 +111,6 @@ lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider);
*/
bool
lv_slider_get_knob_in
(
lv_obj_t
*
slider
);
/******************************
* TRANSPARENT API FUNCTIONS
******************************/
...
...
lv_objx/lv_sw.c
View file @
a2ab0cde
...
...
@@ -25,6 +25,7 @@
#if 0 /*Slider design is used*/
static bool lv_sw_design(lv_obj_t * sw, const area_t * mask, lv_design_mode_t mode);
#endif
static
lv_signal_func_t
ancestor_signal
;
/**********************
* STATIC VARIABLES
**********************/
...
...
@@ -52,6 +53,8 @@ lv_obj_t * lv_sw_create(lv_obj_t * par, lv_obj_t * copy)
/*Create the ancestor of switch*/
lv_obj_t
*
new_sw
=
lv_slider_create
(
par
,
copy
);
dm_assert
(
new_sw
);
if
(
ancestor_signal
==
NULL
)
ancestor_signal
=
lv_obj_get_signal_func
(
new_sw
);
/*Allocate the switch type specific extended data*/
lv_sw_ext_t
*
ext
=
lv_obj_allocate_ext_attr
(
new_sw
,
sizeof
(
lv_sw_ext_t
));
...
...
@@ -98,7 +101,7 @@ bool lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
ext
->
slider
.
action
=
NULL
;
/*Do not let the slider to call the callback. The Switch will do it*/
/* Include the ancient signal function */
valid
=
lv_slide
r_signal
(
sw
,
sign
,
param
);
valid
=
ancesto
r_signal
(
sw
,
sign
,
param
);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
...
...
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