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
f189307b
Commit
f189307b
authored
Feb 01, 2017
by
Gabor
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into beta
parents
a0c35464
014d0a38
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
259 additions
and
47 deletions
+259
-47
lv_app_sysmon.c
lv_appx/lv_app_sysmon.c
+11
-4
lv_draw.c
lv_draw/lv_draw.c
+64
-13
lv_draw.h
lv_draw/lv_draw.h
+3
-1
text.c
lv_misc/text.c
+59
-6
text.h
lv_misc/text.h
+29
-4
lv_btnm.c
lv_objx/lv_btnm.c
+3
-2
lv_gauge.c
lv_objx/lv_gauge.c
+6
-4
lv_img.c
lv_objx/lv_img.c
+2
-2
lv_label.c
lv_objx/lv_label.c
+63
-9
lv_label.h
lv_objx/lv_label.h
+19
-2
No files found.
lv_appx/lv_app_sysmon.c
View file @
f189307b
...
...
@@ -19,6 +19,8 @@
/*********************
* DEFINES
*********************/
#define CPU_LABEL_COLOR "FF0000"
#define MEM_LABEL_COLOR "008000"
/**********************
* TYPEDEFS
...
...
@@ -244,9 +246,11 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
/*Create a label for the details of Memory and CPU usage*/
cord_t
opad
=
app_style
->
win_style
.
pages
.
scrl_rects
.
opad
;
win_data
->
label
=
lv_label_create
(
win
,
NULL
);
lv_label_set_recolor
(
win_data
->
label
,
true
);
lv_obj_align
(
win_data
->
label
,
win_data
->
chart
,
LV_ALIGN_OUT_RIGHT_MID
,
opad
,
0
);
lv_obj_set_style
(
win_data
->
label
,
&
app_style
->
win_txt_style
);
lv_app_sysmon_refr
();
}
...
...
@@ -341,24 +345,27 @@ static void lv_app_sysmon_refr(void)
char
buf_long
[
256
];
char
buf_short
[
128
];
#if USE_IDLE != 0
sprintf
(
buf_long
,
"
CPU: %d %%
\n\n
"
,
cpu_pct
[
LV_APP_SYSMON_PNUM
-
1
]
);
sprintf
(
buf_long
,
"
%c%s CPU: %d %%%c
\n\n
"
,
TXT_RECOLOR_CMD
,
CPU_LABEL_COLOR
,
cpu_pct
[
LV_APP_SYSMON_PNUM
-
1
],
TXT_RECOLOR_CMD
);
sprintf
(
buf_short
,
"CPU: %d %%
\n
"
,
cpu_pct
[
LV_APP_SYSMON_PNUM
-
1
]);
#else
s
trcpy
(
buf_long
,
"CPU: N/A
\n\n
"
);
s
printf
(
buf_long
,
"%c%s CPU: N/A%c
\n\n
"
,
TXT_RECOLOR_CMD
,
CPU_LABEL_COLOR
,
TXT_RECOLOR_CMD
);
strcpy
(
buf_short
,
"CPU: N/A
\n
"
);
#endif
#if USE_DYN_MEM != 0 && DM_CUSTOM == 0
sprintf
(
buf_long
,
"%s
MEMORY: %d %%
\n
Total: %d bytes
\n
Used: %d bytes
\n
Free: %d bytes
\n
Frag: %d %%"
,
sprintf
(
buf_long
,
"%s
%c%s MEMORY: %d %%%c
\n
Total: %d bytes
\n
Used: %d bytes
\n
Free: %d bytes
\n
Frag: %d %%"
,
buf_long
,
TXT_RECOLOR_CMD
,
MEM_LABEL_COLOR
,
mem_pct
[
LV_APP_SYSMON_PNUM
-
1
],
TXT_RECOLOR_CMD
,
mem_mon
.
size_total
,
mem_mon
.
size_total
-
mem_mon
.
size_free
,
mem_mon
.
size_free
,
mem_mon
.
pct_frag
);
sprintf
(
buf_short
,
"%sMem: %d %%
\n
Frag: %d %%
\n
"
,
buf_short
,
mem_pct
[
LV_APP_SYSMON_PNUM
-
1
],
mem_mon
.
pct_frag
);
#else
sprintf
(
buf_long
,
"%s
MEMORY: N/A"
,
buf_long
);
sprintf
(
buf_long
,
"%s
%c%s MEMORY: N/A%c"
,
buf_long
,
TXT_RECOLOR_CMD
,
MEM_LABEL_COLOR
,
TXT_RECOLOR_CMD
);
sprintf
(
buf_short
,
"%sMem: N/A
\n
Frag: N/A"
,
buf_short
);
#endif
lv_app_style_t
*
app_style
=
lv_app_style_get
();
...
...
lv_draw/lv_draw.c
View file @
f189307b
...
...
@@ -24,9 +24,18 @@
#define LINE_WIDTH_CORR_BASE 64
#define LINE_WIDTH_CORR_SHIFT 6
#define LABEL_RECOLOR_PAR_LENGTH 6
/**********************
* TYPEDEFS
**********************/
typedef
enum
{
CMD_STATE_WAIT
,
CMD_STATE_PAR
,
CMD_STATE_IN
,
}
cmd_state_t
;
/**********************
* STATIC PROTOTYPES
...
...
@@ -114,53 +123,95 @@ void lv_draw_rect(const area_t * cords_p, const area_t * mask_p,
* @param labels_p pointer to a label style
* @param opa opacity of the text (0..255)
* @param txt 0 terminated text to write
* @param flag settings for the text from 'txt_flag_t' enum
*/
void
lv_draw_label
(
const
area_t
*
cords_p
,
const
area_t
*
mask_p
,
const
lv_labels_t
*
labels_p
,
opa_t
opa
,
const
char
*
txt
)
const
lv_labels_t
*
style
,
opa_t
opa
,
const
char
*
txt
,
txt_flag_t
flag
)
{
const
font_t
*
font_p
=
font_get
(
labels_p
->
font
);
const
font_t
*
font_p
=
font_get
(
style
->
font
);
cord_t
w
=
area_get_width
(
cords_p
);
/*Init variables for the first line*/
cord_t
line_length
=
0
;
uint32_t
line_start
=
0
;
uint32_t
line_end
=
txt_get_next_line
(
txt
,
font_p
,
labels_p
->
letter_space
,
w
);
uint32_t
line_end
=
txt_get_next_line
(
txt
,
font_p
,
style
->
letter_space
,
w
,
flag
);
point_t
pos
;
pos
.
x
=
cords_p
->
x1
;
pos
.
y
=
cords_p
->
y1
;
/*Align the line to middle if enabled*/
if
(
labels_p
->
mid
!=
0
)
{
if
(
style
->
mid
!=
0
)
{
line_length
=
txt_get_width
(
&
txt
[
line_start
],
line_end
-
line_start
,
font_p
,
labels_p
->
letter_space
);
font_p
,
style
->
letter_space
,
flag
);
pos
.
x
+=
(
w
-
line_length
)
/
2
;
}
cmd_state_t
cmd_state
=
CMD_STATE_WAIT
;
uint32_t
i
;
uint16_t
par_start
;
color_t
recolor
;
/*Write out all lines*/
while
(
txt
[
line_start
]
!=
'\0'
)
{
/*Write all letter of a line*/
cmd_state
=
CMD_STATE_WAIT
;
for
(
i
=
line_start
;
i
<
line_end
;
i
++
)
{
letter_fp
(
&
pos
,
mask_p
,
font_p
,
txt
[
i
],
labels_p
->
objs
.
color
,
opa
);
pos
.
x
+=
font_get_width
(
font_p
,
txt
[
i
])
+
labels_p
->
letter_space
;
/*Handle the recolor command*/
if
((
flag
&
TXT_FLAG_RECOLOR
)
!=
0
)
{
if
(
txt
[
i
]
==
TXT_RECOLOR_CMD
)
{
if
(
cmd_state
==
CMD_STATE_WAIT
)
{
/*Start char*/
par_start
=
i
+
1
;
cmd_state
=
CMD_STATE_PAR
;
continue
;
}
else
if
(
cmd_state
==
CMD_STATE_PAR
)
{
/*Other start char in parameter escaped cmd. char */
cmd_state
=
CMD_STATE_WAIT
;
}
else
if
(
cmd_state
==
CMD_STATE_IN
)
{
/*Command end */
cmd_state
=
CMD_STATE_WAIT
;
continue
;
}
}
/*Skip the color parameter and wait the space after it*/
if
(
cmd_state
==
CMD_STATE_PAR
)
{
if
(
txt
[
i
]
==
' '
)
{
/*Get the parameter*/
if
(
i
-
par_start
==
LABEL_RECOLOR_PAR_LENGTH
)
{
char
buf
[
LABEL_RECOLOR_PAR_LENGTH
];
memcpy
(
buf
,
&
txt
[
par_start
],
LABEL_RECOLOR_PAR_LENGTH
);
buf
[
LABEL_RECOLOR_PAR_LENGTH
]
=
'\0'
;
int
r
,
g
,
b
;
sscanf
(
buf
,
"%02x%02x%02x"
,
&
r
,
&
g
,
&
b
);
recolor
=
COLOR_MAKE
(
r
,
g
,
b
);
}
else
{
recolor
.
full
=
style
->
objs
.
color
.
full
;
}
cmd_state
=
CMD_STATE_IN
;
/*After the parameter the text is in the command*/
}
continue
;
}
}
if
(
cmd_state
==
CMD_STATE_IN
)
letter_fp
(
&
pos
,
mask_p
,
font_p
,
txt
[
i
],
recolor
,
opa
);
else
letter_fp
(
&
pos
,
mask_p
,
font_p
,
txt
[
i
],
style
->
objs
.
color
,
opa
);
pos
.
x
+=
font_get_width
(
font_p
,
txt
[
i
])
+
style
->
letter_space
;
}
/*Go to next line*/
line_start
=
line_end
;
line_end
+=
txt_get_next_line
(
&
txt
[
line_start
],
font_p
,
labels_p
->
letter_space
,
w
);
line_end
+=
txt_get_next_line
(
&
txt
[
line_start
],
font_p
,
style
->
letter_space
,
w
,
flag
);
pos
.
x
=
cords_p
->
x1
;
/*Align to middle*/
if
(
labels_p
->
mid
!=
0
)
{
if
(
style
->
mid
!=
0
)
{
line_length
=
txt_get_width
(
&
txt
[
line_start
],
line_end
-
line_start
,
font_p
,
labels_p
->
letter_space
);
font_p
,
style
->
letter_space
,
flag
);
pos
.
x
+=
(
w
-
line_length
)
/
2
;
}
/*Go the next line position*/
pos
.
y
+=
font_get_height
(
font_p
);
pos
.
y
+=
labels_p
->
line_space
;
pos
.
y
+=
style
->
line_space
;
}
}
...
...
@@ -179,7 +230,7 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p,
{
if
(
fn
==
NULL
)
{
lv_draw_rect
(
cords_p
,
mask_p
,
&
lv_img_no_pic_rects
,
opa
);
lv_draw_label
(
cords_p
,
mask_p
,
&
lv_img_no_pic_labels
,
opa
,
"No data"
);
lv_draw_label
(
cords_p
,
mask_p
,
&
lv_img_no_pic_labels
,
opa
,
"No data"
,
TXT_FLAG_NONE
);
}
else
{
fs_file_t
file
;
fs_res_t
res
=
fs_open
(
&
file
,
fn
,
FS_MODE_RD
);
...
...
@@ -251,7 +302,7 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p,
if
(
res
!=
FS_RES_OK
)
{
lv_draw_rect
(
cords_p
,
mask_p
,
&
lv_img_no_pic_rects
,
opa
);
lv_draw_label
(
cords_p
,
mask_p
,
&
lv_img_no_pic_labels
,
opa
,
fn
);
lv_draw_label
(
cords_p
,
mask_p
,
&
lv_img_no_pic_labels
,
opa
,
fn
,
TXT_FLAG_NONE
);
}
}
}
...
...
lv_draw/lv_draw.h
View file @
f189307b
...
...
@@ -16,6 +16,7 @@
#include "../lv_objx/lv_label.h"
#include "misc_conf.h"
#include "../lv_misc/text.h"
/*********************
* DEFINES
...
...
@@ -48,10 +49,11 @@ void lv_draw_rect(const area_t * cords_p, const area_t * mask_p,
* @param labels_p pointer to a label style
* @param opa opacity of the text (0..255)
* @param txt 0 terminated text to write
* @param flags settings for the text from 'txt_flag_t' enum
*/
#if USE_LV_LABEL != 0
void
lv_draw_label
(
const
area_t
*
cords_p
,
const
area_t
*
mask_p
,
const
lv_labels_t
*
labels_p
,
opa_t
opa
,
const
char
*
txt
);
const
lv_labels_t
*
labels_p
,
opa_t
opa
,
const
char
*
txt
,
txt_flag_t
flag
);
#endif
/**
...
...
lv_misc/text.c
View file @
f189307b
...
...
@@ -42,10 +42,11 @@ static bool txt_is_break_char(char letter);
* @param font pinter to font of the text
* @param letter_space letter space of the text
* @param line_space line space of the text
* @param flags settings for the text from 'txt_flag_t' enum
* @param max_width max with of the text (break the lines to fit this size) Set LV_CORD_MAX to avoid line breaks
*/
void
txt_get_size
(
point_t
*
size_res
,
const
char
*
text
,
const
font_t
*
font
,
uint16_t
letter_space
,
uint16_t
line_space
,
cord_t
max_width
)
uint16_t
letter_space
,
uint16_t
line_space
,
cord_t
max_width
,
txt_flag_t
flag
)
{
size_res
->
x
=
0
;
size_res
->
y
=
0
;
...
...
@@ -61,13 +62,13 @@ void txt_get_size(point_t * size_res, const char * text, const font_t * font,
/*Calc. the height and longest line*/
while
(
text
[
line_start
]
!=
'\0'
)
{
new_line_start
+=
txt_get_next_line
(
&
text
[
line_start
],
font
,
letter_space
,
max_width
);
new_line_start
+=
txt_get_next_line
(
&
text
[
line_start
],
font
,
letter_space
,
max_width
,
flag
);
size_res
->
y
+=
letter_height
;
size_res
->
y
+=
line_space
;
/*Calculate the the longest line*/
act_line_length
=
txt_get_width
(
&
text
[
line_start
],
new_line_start
-
line_start
,
font
,
letter_space
);
font
,
letter_space
,
flag
);
size_res
->
x
=
MATH_MAX
(
act_line_length
,
size_res
->
x
);
line_start
=
new_line_start
;
...
...
@@ -89,10 +90,11 @@ void txt_get_size(point_t * size_res, const char * text, const font_t * font,
* @param font pointer to a font
* @param letter_space letter space
* @param max_l max line length
* @param flags settings for the text from 'txt_flag_type' enum
* @return the index of the first char of the new line
*/
uint16_t
txt_get_next_line
(
const
char
*
txt
,
const
font_t
*
font
,
uint16_t
letter_space
,
cord_t
max_l
)
uint16_t
letter_space
,
cord_t
max_l
,
txt_flag_t
flag
)
{
if
(
txt
==
NULL
)
return
0
;
if
(
font
==
NULL
)
return
0
;
...
...
@@ -100,8 +102,18 @@ uint16_t txt_get_next_line(const char * txt, const font_t * font,
uint32_t
i
=
0
;
cord_t
act_l
=
0
;
uint16_t
last_break
=
TXT_NO_BREAK_FOUND
;
txt_cmd_state_t
cmd_state
=
TXT_CMD_STATE_WAIT
;
while
(
txt
[
i
]
!=
'\0'
)
{
/*Handle the recolor command*/
if
((
flag
&
TXT_FLAG_RECOLOR
)
!=
0
)
{
if
(
txt_is_cmd
(
&
cmd_state
,
txt
[
i
])
!=
false
)
{
i
++
;
/*Skip the letter is it is part of a command*/
continue
;
}
}
/*Check for new line chars*/
if
(
txt
[
i
]
==
'\n'
||
txt
[
i
]
==
'\r'
)
{
/*Handle \n\r and \r\n as well*/
...
...
@@ -150,20 +162,27 @@ uint16_t txt_get_next_line(const char * txt, const font_t * font,
* @param txt a '\0' terminate string
* @param char_num number of characters in 'txt'
* @param font pointer to a font
* @param letter_space letter sapce
* @param letter_space letter space
* @param flags settings for the text from 'txt_flag_t' enum
* @return length of a char_num long text
*/
cord_t
txt_get_width
(
const
char
*
txt
,
uint16_t
char_num
,
const
font_t
*
font
,
uint16_t
letter_space
)
const
font_t
*
font
,
uint16_t
letter_space
,
txt_flag_t
flag
)
{
if
(
txt
==
NULL
)
return
0
;
if
(
font
==
NULL
)
return
0
;
uint16_t
i
;
cord_t
len
=
0
;
txt_cmd_state_t
cmd_state
=
TXT_CMD_STATE_WAIT
;
if
(
char_num
!=
0
)
{
for
(
i
=
0
;
i
<
char_num
;
i
++
)
{
if
((
flag
&
TXT_FLAG_RECOLOR
)
!=
0
)
{
if
(
txt_is_cmd
(
&
cmd_state
,
txt
[
i
])
!=
false
)
{
continue
;
}
}
len
+=
font_get_width
(
font
,
txt
[
i
]);
len
+=
letter_space
;
}
...
...
@@ -186,6 +205,40 @@ cord_t txt_get_width(const char * txt, uint16_t char_num,
return
len
;
}
/**
* Check next character in a string and decide if te character is part of the command or not
* @param state pointer to a txt_cmd_state_t variable which stores the current state of command processing
* @param c the current character
* @return true: the character is part of a command and should not be written,
* false: the character should be written
*/
bool
txt_is_cmd
(
txt_cmd_state_t
*
state
,
char
c
)
{
bool
ret
=
false
;
if
(
c
==
TXT_RECOLOR_CMD
)
{
if
(
*
state
==
TXT_CMD_STATE_WAIT
)
{
/*Start char*/
*
state
=
TXT_CMD_STATE_PAR
;
ret
=
true
;
}
else
if
(
*
state
==
TXT_CMD_STATE_PAR
)
{
/*Other start char in parameter is escaped cmd. char */
*
state
=
TXT_CMD_STATE_WAIT
;
}
else
if
(
*
state
==
TXT_CMD_STATE_IN
)
{
/*Command end */
*
state
=
TXT_CMD_STATE_WAIT
;
ret
=
true
;
}
}
/*Skip the color parameter and wait the space after it*/
if
(
*
state
==
TXT_CMD_STATE_PAR
)
{
if
(
c
==
' '
)
{
*
state
=
TXT_CMD_STATE_IN
;
/*After the parameter the text is in the command*/
}
ret
=
true
;
}
return
ret
;
}
/**********************
* STATIC FUNCTIONS
**********************/
...
...
lv_misc/text.h
View file @
f189307b
...
...
@@ -18,10 +18,23 @@
/*********************
* DEFINES
*********************/
#define TXT_RECOLOR_CMD '#'
/**********************
* TYPEDEFS
**********************/
typedef
enum
{
TXT_FLAG_NONE
=
0x00
,
TXT_FLAG_RECOLOR
=
0x01
,
}
txt_flag_t
;
typedef
enum
{
TXT_CMD_STATE_WAIT
,
TXT_CMD_STATE_PAR
,
TXT_CMD_STATE_IN
,
}
txt_cmd_state_t
;
/**********************
* GLOBAL PROTOTYPES
...
...
@@ -34,10 +47,11 @@
* @param font pinter to font of the text
* @param letter_space letter space of the text
* @param line_space line space of the text
* @param flags settings for the text from 'txt_flag_t' enum
* @param max_width max with of the text (break the lines to fit this size) Set LV_CORD_MAX to avoid line breaks
*/
void
txt_get_size
(
point_t
*
size_res
,
const
char
*
text
,
const
font_t
*
font
,
uint16_t
letter_space
,
uint16_t
line_space
,
cord_t
max_width
);
uint16_t
letter_space
,
uint16_t
line_space
,
cord_t
max_width
,
txt_flag_t
flag
);
/**
* Get the next line of text. Check line length and break chars too.
...
...
@@ -45,21 +59,32 @@ void txt_get_size(point_t * size_res, const char * text, const font_t * font,
* @param font_p pointer to a font
* @param letter_space letter space
* @param max_l max line length
* @param flags settings for the text from 'txt_flag_t' enum
* @return the index of the first char of the new line
*/
uint16_t
txt_get_next_line
(
const
char
*
txt
,
const
font_t
*
font_p
,
uint16_t
letter_space
,
cord_t
max_l
);
uint16_t
letter_space
,
cord_t
max_l
,
txt_flag_t
flag
);
/**
* Give the length of a text with a given font
* @param txt a '\0' terminate string
* @param char_num number of characters in 'txt'
* @param font_p pointer to a font
* @param letter_space letter sapce
* @param letter_space letter space
* @param flags settings for the text from 'txt_flag_t' enum
* @return length of a char_num long text
*/
cord_t
txt_get_width
(
const
char
*
txt
,
uint16_t
char_num
,
const
font_t
*
font_p
,
uint16_t
letter_space
);
const
font_t
*
font_p
,
uint16_t
letter_space
,
txt_flag_t
flag
);
/**
* Check next character in a string and decide if te character is part of the command or not
* @param state pointer to a txt_cmd_state_t variable which stores the current state of command processing
* @param c the current character
* @return true: the character is part of a command and should not be written,
* false: the character should be written
*/
bool
txt_is_cmd
(
txt_cmd_state_t
*
state
,
char
c
);
/**********************
* MACROS
...
...
lv_objx/lv_btnm.c
View file @
f189307b
...
...
@@ -428,14 +428,15 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
const
font_t
*
font
=
font_get
(
style
->
labels
.
font
);
point_t
txt_size
;
txt_get_size
(
&
txt_size
,
ext
->
map_p
[
txt_i
],
font
,
style
->
labels
.
letter_space
,
style
->
labels
.
line_space
,
area_get_width
(
&
area_btnm
));
style
->
labels
.
letter_space
,
style
->
labels
.
line_space
,
area_get_width
(
&
area_btnm
),
TXT_FLAG_NONE
);
area_tmp
.
x1
+=
(
btn_w
-
txt_size
.
x
)
/
2
;
area_tmp
.
y1
+=
(
btn_h
-
txt_size
.
y
)
/
2
;
area_tmp
.
x2
=
area_tmp
.
x1
+
txt_size
.
x
;
area_tmp
.
y2
=
area_tmp
.
y1
+
txt_size
.
y
;
lv_draw_label
(
&
area_tmp
,
mask
,
&
style
->
labels
,
OPA_COVER
,
ext
->
map_p
[
txt_i
]);
lv_draw_label
(
&
area_tmp
,
mask
,
&
style
->
labels
,
OPA_COVER
,
ext
->
map_p
[
txt_i
]
,
TXT_FLAG_NONE
);
txt_i
++
;
}
}
...
...
lv_objx/lv_gauge.c
View file @
f189307b
...
...
@@ -414,7 +414,8 @@ static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask)
area_t
label_cord
;
point_t
label_size
;
txt_get_size
(
&
label_size
,
scale_txt
,
font_get
(
style
->
scale_labels
.
font
),
style
->
scale_labels
.
letter_space
,
style
->
scale_labels
.
line_space
,
LV_CORD_MAX
);
style
->
scale_labels
.
letter_space
,
style
->
scale_labels
.
line_space
,
LV_CORD_MAX
,
TXT_FLAG_NONE
);
/*Draw the label*/
label_cord
.
x1
=
x
-
label_size
.
x
/
2
;
...
...
@@ -422,7 +423,7 @@ static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask)
label_cord
.
x2
=
label_cord
.
x1
+
label_size
.
x
;
label_cord
.
y2
=
label_cord
.
y1
+
label_size
.
y
;
lv_draw_label
(
&
label_cord
,
mask
,
&
style
->
scale_labels
,
OPA_COVER
,
scale_txt
);
lv_draw_label
(
&
label_cord
,
mask
,
&
style
->
scale_labels
,
OPA_COVER
,
scale_txt
,
TXT_FLAG_NONE
);
}
/*Calculate the critical value*/
...
...
@@ -440,7 +441,8 @@ static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask)
area_t
label_cord
;
point_t
label_size
;
txt_get_size
(
&
label_size
,
value_txt
,
font_get
(
style
->
value_labels
.
font
),
style
->
value_labels
.
letter_space
,
style
->
value_labels
.
line_space
,
LV_CORD_MAX
);
style
->
value_labels
.
letter_space
,
style
->
value_labels
.
line_space
,
LV_CORD_MAX
,
TXT_FLAG_NONE
);
/*Draw the label*/
label_cord
.
x1
=
gauge
->
cords
.
x1
+
lv_obj_get_width
(
gauge
)
/
2
-
label_size
.
x
/
2
;
...
...
@@ -450,7 +452,7 @@ static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask)
label_cord
.
x2
=
label_cord
.
x1
+
label_size
.
x
;
label_cord
.
y2
=
label_cord
.
y1
+
label_size
.
y
;
lv_draw_label
(
&
label_cord
,
mask
,
&
style
->
value_labels
,
OPA_COVER
,
value_txt
);
lv_draw_label
(
&
label_cord
,
mask
,
&
style
->
value_labels
,
OPA_COVER
,
value_txt
,
TXT_FLAG_NONE
);
}
}
...
...
lv_objx/lv_img.c
View file @
f189307b
...
...
@@ -227,7 +227,7 @@ void lv_img_set_file(lv_obj_t * img, const char * fn)
#if LV_IMG_ENABLE_SYMBOLS
lv_imgs_t
*
imgs
=
lv_obj_get_style
(
img
);
point_t
size
;
txt_get_size
(
&
size
,
fn
,
font_get
(
imgs
->
sym_font
),
0
,
0
,
LV_CORD_MAX
);
txt_get_size
(
&
size
,
fn
,
font_get
(
imgs
->
sym_font
),
0
,
0
,
LV_CORD_MAX
,
TXT_FLAG_NONE
);
ext
->
w
=
size
.
x
;
ext
->
h
=
size
.
y
;
ext
->
transp
=
0
;
...
...
@@ -374,7 +374,7 @@ static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t
lv_draw_img
(
&
cords_tmp
,
mask
,
imgs_p
,
opa
,
ext
->
fn
);
#else
if
(
sym
==
false
)
lv_draw_img
(
&
cords_tmp
,
mask
,
imgs_p
,
opa
,
ext
->
fn
);
else
lv_draw_label
(
&
cords_tmp
,
mask
,
&
sym_style
,
opa
,
ext
->
fn
);
else
lv_draw_label
(
&
cords_tmp
,
mask
,
&
sym_style
,
opa
,
ext
->
fn
,
TXT_FLAG_NONE
);
#endif
}
}
...
...
lv_objx/lv_label.c
View file @
f189307b
...
...
@@ -86,6 +86,7 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy)
dm_assert
(
ext
);
ext
->
txt
=
NULL
;
ext
->
static_txt
=
0
;
ext
->
recolor
=
0
;
ext
->
dot_end
=
LV_LABEL_DOT_END_INV
;
ext
->
long_mode
=
LV_LABEL_LONG_EXPAND
;
...
...
@@ -104,6 +105,7 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy)
else
{
lv_label_ext_t
*
copy_ext
=
lv_obj_get_ext
(
copy
);
lv_label_set_long_mode
(
new_label
,
lv_label_get_long_mode
(
copy
));
lv_label_set_recolor
(
new_label
,
lv_label_get_recolor
(
copy
));
if
(
copy_ext
->
static_txt
==
0
)
lv_label_set_text
(
new_label
,
lv_label_get_text
(
copy
));
else
lv_label_set_text_static
(
new_label
,
lv_label_get_text
(
copy
));
...
...
@@ -262,6 +264,20 @@ void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode)
lv_label_refr_text
(
label
);
}
/**
* Enable the recoloring by in-line commands
* @param label pointer to a label object
* @param recolor true: enable recoloring, false: disable
*/
void
lv_label_set_recolor
(
lv_obj_t
*
label
,
bool
recolor
)
{
lv_label_ext_t
*
ext
=
lv_obj_get_ext
(
label
);
ext
->
recolor
=
recolor
==
false
?
0
:
1
;
lv_label_refr_text
(
label
);
}
/*=====================
* Getter functions
*====================*/
...
...
@@ -279,9 +295,9 @@ const char * lv_label_get_text(lv_obj_t * label)
}
/**
* Get the
fix width attribut
e of a label
* Get the
long mod
e of a label
* @param label pointer to a label object
* @return t
rue: fix width is enabled
* @return t
he long mode
*/
lv_label_long_mode_t
lv_label_get_long_mode
(
lv_obj_t
*
label
)
{
...
...
@@ -290,6 +306,18 @@ lv_label_long_mode_t lv_label_get_long_mode(lv_obj_t * label)
}
/**
* Get the recoloring attribute
* @param label pointer to a label object
* @return true: recoloring is enabled, false: disable
*/
bool
lv_label_get_recolor
(
lv_obj_t
*
label
)
{
lv_label_ext_t
*
ext
=
lv_obj_get_ext
(
label
);
return
ext
->
recolor
==
0
?
false
:
true
;
}
/**
* Get the relative x and y coordinates of a letter
* @param label pointer to a label object
* @param index index of the letter (0 ... text length)
...
...
@@ -306,6 +334,9 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
const
font_t
*
font
=
font_get
(
labels
->
font
);
uint8_t
letter_height
=
font_get_height
(
font
);
cord_t
y
=
0
;
txt_flag_t
flag
=
TXT_FLAG_NONE
;
if
(
ext
->
recolor
!=
0
)
flag
|=
TXT_FLAG_RECOLOR
;
/*If the width will be expanded the set the max length to very big */
if
(
ext
->
long_mode
==
LV_LABEL_LONG_EXPAND
||
ext
->
long_mode
==
LV_LABEL_LONG_SCROLL
)
{
...
...
@@ -314,7 +345,7 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
/*Search the line of the index letter */
;
while
(
text
[
new_line_start
]
!=
'\0'
)
{
new_line_start
+=
txt_get_next_line
(
&
text
[
line_start
],
font
,
labels
->
letter_space
,
max_w
);
new_line_start
+=
txt_get_next_line
(
&
text
[
line_start
],
font
,
labels
->
letter_space
,
max_w
,
flag
);
if
(
index
<
new_line_start
||
text
[
new_line_start
]
==
'\0'
)
break
;
/*The line of 'index' letter begins at 'line_start'*/
y
+=
letter_height
+
labels
->
line_space
;
...
...
@@ -329,14 +360,22 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
/*Calculate the x coordinate*/
cord_t
x
=
0
;
uint32_t
i
;
txt_cmd_state_t
cmd_state
=
TXT_CMD_STATE_WAIT
;
for
(
i
=
line_start
;
i
<
index
;
i
++
)
{
/*Handle the recolor command*/
if
((
flag
&
TXT_FLAG_RECOLOR
)
!=
0
)
{
if
(
txt_is_cmd
(
&
cmd_state
,
text
[
i
])
!=
false
)
{
continue
;
/*Skip the letter is it is part of a command*/
}
}
x
+=
font_get_width
(
font
,
text
[
i
])
+
labels
->
letter_space
;
}
if
(
labels
->
mid
!=
0
)
{
cord_t
line_w
;
line_w
=
txt_get_width
(
&
text
[
line_start
],
new_line_start
-
line_start
,
font
,
labels
->
letter_space
);
font
,
labels
->
letter_space
,
flag
);
x
+=
lv_obj_get_width
(
label
)
/
2
-
line_w
/
2
;
}
...
...
@@ -362,6 +401,9 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos)
const
font_t
*
font
=
font_get
(
style
->
font
);
uint8_t
letter_height
=
font_get_height
(
font
);
cord_t
y
=
0
;
txt_flag_t
flag
=
TXT_FLAG_NONE
;
if
(
ext
->
recolor
!=
0
)
flag
|=
TXT_FLAG_RECOLOR
;
/*If the width will be expanded set the max length to very big */
if
(
ext
->
long_mode
==
LV_LABEL_LONG_EXPAND
||
ext
->
long_mode
==
LV_LABEL_LONG_SCROLL
)
{
...
...
@@ -370,7 +412,7 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos)
/*Search the line of the index letter */
;
while
(
text
[
line_start
]
!=
'\0'
)
{
new_line_start
+=
txt_get_next_line
(
&
text
[
line_start
],
font
,
style
->
letter_space
,
max_w
);
new_line_start
+=
txt_get_next_line
(
&
text
[
line_start
],
font
,
style
->
letter_space
,
max_w
,
flag
);
if
(
pos
->
y
<=
y
+
letter_height
+
style
->
line_space
)
break
;
/*The line is found ('line_start')*/
y
+=
letter_height
+
style
->
line_space
;
line_start
=
new_line_start
;
...
...
@@ -381,12 +423,20 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos)
if
(
style
->
mid
!=
0
)
{
cord_t
line_w
;
line_w
=
txt_get_width
(
&
text
[
line_start
],
new_line_start
-
line_start
,
font
,
style
->
letter_space
);
font
,
style
->
letter_space
,
flag
);
x
+=
lv_obj_get_width
(
label
)
/
2
-
line_w
/
2
;
}
txt_cmd_state_t
cmd_state
=
TXT_CMD_STATE_WAIT
;
uint16_t
i
;
for
(
i
=
line_start
;
i
<
new_line_start
-
1
;
i
++
)
{
for
(
i
=
line_start
;
i
<
new_line_start
-
1
;
i
++
)
{
/*Handle the recolor command*/
if
((
flag
&
TXT_FLAG_RECOLOR
)
!=
0
)
{
if
(
txt_is_cmd
(
&
cmd_state
,
text
[
i
])
!=
false
)
{
continue
;
/*Skip the letter is it is part of a command*/
}
}
x
+=
font_get_width
(
font
,
text
[
i
])
+
style
->
letter_space
;
if
(
pos
->
x
<
x
)
break
;
}
...
...
@@ -465,9 +515,11 @@ static bool lv_label_design(lv_obj_t * label, const area_t * mask, lv_design_mod
lv_obj_get_cords
(
label
,
&
cords
);
opa_t
opa
=
lv_obj_get_opa
(
label
);
lv_label_ext_t
*
ext
=
lv_obj_get_ext
(
label
);
txt_flag_t
flag
=
TXT_FLAG_NONE
;
if
(
ext
->
recolor
!=
0
)
flag
|=
TXT_FLAG_RECOLOR
;
lv_draw_label
(
&
cords
,
mask
,
lv_obj_get_style
(
label
),
opa
,
ext
->
txt
);
lv_draw_label
(
&
cords
,
mask
,
lv_obj_get_style
(
label
),
opa
,
ext
->
txt
,
flag
);
}
...
...
@@ -497,7 +549,9 @@ static void lv_label_refr_text(lv_obj_t * label)
/*Calc. the height and longest line*/
point_t
size
;
txt_get_size
(
&
size
,
ext
->
txt
,
font
,
style
->
letter_space
,
style
->
line_space
,
max_w
);
txt_flag_t
flag
=
TXT_FLAG_NONE
;
if
(
ext
->
recolor
!=
0
)
flag
|=
TXT_FLAG_RECOLOR
;
txt_get_size
(
&
size
,
ext
->
txt
,
font
,
style
->
letter_space
,
style
->
line_space
,
max_w
,
flag
);
/*Refresh the full size in expand mode*/
if
(
ext
->
long_mode
==
LV_LABEL_LONG_EXPAND
||
ext
->
long_mode
==
LV_LABEL_LONG_SCROLL
)
{
...
...
lv_objx/lv_label.h
View file @
f189307b
...
...
@@ -14,6 +14,7 @@
#include "../lv_obj/lv_obj.h"
#include "../lv_misc/font.h"
#include "../lv_misc/text.h"
/*********************
* DEFINES
...
...
@@ -43,6 +44,7 @@ typedef struct
char
dot_tmp
[
LV_LABEL_DOT_NUM
];
/*Store character which are replaced with dots*/
uint16_t
dot_end
;
/* The text end position in dot mode*/
uint8_t
static_txt
:
1
;
/* Flag to indicate the text is static*/
uint8_t
recolor
:
1
;
/* Enable in-line letter recoloring*/
}
lv_label_ext_t
;
/*Style of label*/
...
...
@@ -117,6 +119,13 @@ void lv_label_set_text_static(lv_obj_t * label, const char * text);
void
lv_label_set_long_mode
(
lv_obj_t
*
label
,
lv_label_long_mode_t
long_mode
);
/**
* Enable the recoloring by in-line commands
* @param label pointer to a label object
* @param recolor true: enable recoloring, false: disable
*/
void
lv_label_set_recolor
(
lv_obj_t
*
label
,
bool
recolor
);
/**
* Get the text of a label
* @param label pointer to a label object
* @return the text of the label
...
...
@@ -124,12 +133,20 @@ void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode);
const
char
*
lv_label_get_text
(
lv_obj_t
*
label
);
/**
* Get the
fix width attribut
e of a label
* Get the
long mod
e of a label
* @param label pointer to a label object
* @return t
rue: fix width is enabled
* @return t
he long mode
*/
lv_label_long_mode_t
lv_label_get_long_mode
(
lv_obj_t
*
label
);
/**
* Get the recoloring attribute
* @param label pointer to a label object
* @return true: recoloring is enabled, false: disable
*/
bool
lv_label_get_recolor
(
lv_obj_t
*
label
);
/**
* Get the relative x and y coordinates of a letter
* @param label pointer to a label object
...
...
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