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
d04c2463
Commit
d04c2463
authored
Sep 30, 2016
by
Gabor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Text area beginned
parent
5b455a9f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
336 additions
and
0 deletions
+336
-0
lv_conf_temp.h
lv_conf_temp.h
+2
-0
lv_label.c
lv_objx/lv_label.c
+50
-0
lv_label.h
lv_objx/lv_label.h
+1
-0
lv_ta.c
lv_objx/lv_ta.c
+210
-0
lv_ta.h
lv_objx/lv_ta.h
+72
-0
lvgl.h
lvgl.h
+1
-0
No files found.
lv_conf_temp.h
View file @
d04c2463
...
...
@@ -95,6 +95,8 @@
#define USE_LV_BTNM 1
#define USE_LV_TA 1
/*==================
* LV APP SETTINGS
* =================*/
...
...
lv_objx/lv_label.c
View file @
d04c2463
...
...
@@ -212,6 +212,7 @@ void lv_label_set_text(lv_obj_t * obj_dp, const char * text)
/**
* Set the fix width attribute
* If enabled the text will be automatically broken to fit to the size
* @param obj_dp pointer to a label object
* @param fixw true: enable fix width for the label
*/
...
...
@@ -249,6 +250,55 @@ bool lv_label_get_fixw(lv_obj_t * obj_dp)
}
/**
* Get the relative x and y coordinates of a letter
* @param obj_dp pointer to a label object
* @param index index of the letter (0 ... text length)
* @param pos_p store the result here
*/
void
lv_label_get_letter_pos
(
lv_obj_t
*
obj_dp
,
uint16_t
index
,
point_t
*
pos_p
)
{
const
char
*
text
=
lv_label_get_text
(
obj_dp
);
lv_label_ext_t
*
ext_p
=
lv_obj_get_ext
(
obj_dp
);
uint32_t
line_start
=
0
;
uint32_t
new_line_start
=
0
;
cord_t
max_length
=
lv_obj_get_width
(
obj_dp
);
lv_labels_t
*
labels_p
=
lv_obj_get_style
(
obj_dp
);
const
font_t
*
font_p
=
font_get
(
labels_p
->
font
);
uint8_t
letter_height
=
font_get_height
(
font_p
);
cord_t
y
=
0
;
/*If the fix width is not enabled the set the max length to very big */
if
(
ext_p
->
fixw
==
0
)
{
max_length
=
LV_CORD_MAX
;
}
/*Search the line of the index letter */
;
while
(
text
[
line_start
]
!=
'\0'
)
{
new_line_start
+=
txt_get_next_line
(
&
text
[
line_start
],
font_p
,
labels_p
->
letter_space
,
max_length
);
if
(
index
<
new_line_start
)
break
;
/*Lines of index letter begins at 'line_start'*/
y
+=
letter_height
+
labels_p
->
line_space
;
line_start
=
new_line_start
;
}
/*Calculate the x coordinate*/
cord_t
x
=
0
;
/*TODO handle 'mid'*/
//if(labels_p->mid == 0)
{
uint32_t
i
;
for
(
i
=
line_start
;
i
<
index
;
i
++
)
{
x
+=
font_get_width
(
font_p
,
text
[
i
])
+
labels_p
->
line_space
;
}
}
pos_p
->
x
=
x
+
obj_dp
->
cords
.
x1
;
pos_p
->
y
=
y
+
obj_dp
->
cords
.
y1
;
}
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_labels_builtin_t enum
* @param copy_p copy the style to this variable. (NULL if unused)
...
...
lv_objx/lv_label.h
View file @
d04c2463
...
...
@@ -59,6 +59,7 @@ void lv_label_set_text(lv_obj_t* obj_dp, const char * text);
void
lv_label_set_fixw
(
lv_obj_t
*
obj_dp
,
bool
fixw
);
const
char
*
lv_label_get_text
(
lv_obj_t
*
obj_dp
);
bool
lv_label_get_fixw
(
lv_obj_t
*
obj_dp
);
void
lv_label_get_letter_pos
(
lv_obj_t
*
obj_dp
,
uint16_t
index
,
point_t
*
pos_p
);
lv_labels_t
*
lv_labels_get
(
lv_labels_builtin_t
style
,
lv_labels_t
*
copy_p
);
...
...
lv_objx/lv_ta.c
0 → 100644
View file @
d04c2463
/**
* @file lv_ta.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_conf.h"
#if USE_LV_TA != 0
#include "lv_ta.h"
/*********************
* DEFINES
*********************/
#define LV_TA_MAX_LENGTH 512
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static
bool
lv_ta_design
(
lv_obj_t
*
obj_dp
,
const
area_t
*
mask_p
,
lv_design_mode_t
mode
);
/**********************
* STATIC VARIABLES
**********************/
static
lv_tas_t
lv_tas_def
=
{
/*Create a default style*/
};
lv_design_f_t
ancestor_design_f
;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/*-----------------
* Create function
*-----------------*/
/**
* Create a text area objects
* @param par_dp pointer to an object, it will be the parent of the new text area
* @param copy_dp pointer to a text area object, if not NULL then the new object will be copied from it
* @return pointer to the created text area
*/
lv_obj_t
*
lv_ta_create
(
lv_obj_t
*
par_dp
,
lv_obj_t
*
copy_dp
)
{
/*Create the ancestor object*/
lv_obj_t
*
new_obj_dp
=
lv_page_create
(
par_dp
,
copy_dp
);
dm_assert
(
new_obj_dp
);
/*Allocate the object type specific extended data*/
lv_ta_ext_t
*
ext_dp
=
lv_obj_alloc_ext
(
new_obj_dp
,
sizeof
(
lv_ta_ext_t
));
dm_assert
(
ext_dp
);
if
(
ancestor_design_f
==
NULL
)
{
ancestor_design_f
=
lv_obj_get_design_f
(
new_obj_dp
);
}
lv_obj_set_signal_f
(
new_obj_dp
,
lv_ta_signal
);
lv_obj_set_design_f
(
new_obj_dp
,
lv_ta_design
);
/*Init the new text area object*/
if
(
copy_dp
==
NULL
)
{
ext_dp
->
label_dp
=
lv_label_create
(
new_obj_dp
,
NULL
);
lv_label_set_text
(
ext_dp
->
label_dp
,
"Abc def xyz
\n\n\n\n\n\n\n\n\n\n\n\n
ghi
\n\n\n\n\n\n\n\n\n\n
123
\n\n\n\n\n\n\n\n\n\n
456
\n\n\n\n\n\n
789"
);
lv_obj_set_style
(
ext_dp
->
label_dp
,
lv_labels_get
(
LV_LABELS_TXT
,
NULL
));
}
/*Copy an existing object*/
else
{
}
return
new_obj_dp
;
}
/**
* Signal function of the text area
* @param obj_dp pointer to a text area object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
*/
bool
lv_ta_signal
(
lv_obj_t
*
obj_dp
,
lv_signal_t
sign
,
void
*
param
)
{
bool
valid
;
/* Include the ancient signal function */
valid
=
lv_page_signal
(
obj_dp
,
sign
,
param
);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if
(
valid
!=
false
)
{
switch
(
sign
)
{
case
LV_SIGNAL_CLEANUP
:
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
break
;
default:
break
;
}
}
return
valid
;
}
/*=====================
* Setter functions
*====================*/
void
lv_ta_set_cursor_pos
(
lv_obj_t
*
obj_dp
,
uint16_t
pos
)
{
lv_ta_ext_t
*
ta_dp
=
lv_obj_get_ext
(
obj_dp
);
ta_dp
->
cursor_pos
=
pos
;
lv_obj_inv
(
obj_dp
);
}
/*=====================
* Getter functions
*====================*/
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_tas_builtin_t enum
* @param copy_p copy the style to this variable. (NULL if unused)
* @return pointer to an lv_tas_t style
*/
lv_tas_t
*
lv_tas_get
(
lv_tas_builtin_t
style
,
lv_tas_t
*
copy_p
)
{
lv_tas_t
*
style_p
;
switch
(
style
)
{
case
LV_TAS_DEF
:
style_p
=
&
lv_tas_def
;
break
;
default:
style_p
=
&
lv_tas_def
;
}
if
(
copy_p
!=
NULL
)
{
if
(
style_p
!=
NULL
)
memcpy
(
copy_p
,
style_p
,
sizeof
(
lv_tas_t
));
else
memcpy
(
copy_p
,
&
lv_tas_def
,
sizeof
(
lv_tas_t
));
}
return
style_p
;
}
uint16_t
lv_ta_get_cursor_pos
(
lv_obj_t
*
obj_dp
)
{
lv_ta_ext_t
*
ta_dp
=
lv_obj_get_ext
(
obj_dp
);
return
ta_dp
->
cursor_pos
;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Handle the drawing related tasks of the text areas
* @param obj_dp pointer to an object
* @param mask the object will be drawn only in this area
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
* (return 'true' if yes)
* LV_DESIGN_DRAW: draw the object (always return 'true')
* @param return true/false, depends on 'mode'
*/
static
bool
lv_ta_design
(
lv_obj_t
*
obj_dp
,
const
area_t
*
mask_p
,
lv_design_mode_t
mode
)
{
if
(
mode
==
LV_DESIGN_COVER_CHK
)
{
/*Return false if the object is not covers the mask_p area*/
return
ancestor_design_f
(
obj_dp
,
mask_p
,
mode
);
}
/*Draw the object*/
ancestor_design_f
(
obj_dp
,
mask_p
,
mode
);
lv_ta_ext_t
*
ta_dp
=
lv_obj_get_ext
(
obj_dp
);
uint16_t
cur_pos
=
lv_ta_get_cursor_pos
(
obj_dp
);
point_t
letter_pos
;
lv_label_get_letter_pos
(
ta_dp
->
label_dp
,
cur_pos
,
&
letter_pos
);
area_t
cur_area
;
lv_labels_t
*
label_p
=
lv_obj_get_style
(
ta_dp
->
label_dp
);
cur_area
.
x1
=
letter_pos
.
x
;
cur_area
.
y1
=
letter_pos
.
y
;
cur_area
.
x2
=
letter_pos
.
x
+
4
;
cur_area
.
y2
=
letter_pos
.
y
+
font_get_height
(
font_get
(
label_p
->
font
));
lv_rects_t
rects
;
lv_rects_get
(
LV_RECTS_DEF
,
&
rects
);
rects
.
round
=
0
;
rects
.
bwidth
=
0
;
rects
.
objs
.
color
=
COLOR_RED
;
rects
.
gcolor
=
COLOR_RED
;
lv_draw_rect
(
&
cur_area
,
mask_p
,
&
rects
,
OPA_COVER
);
return
true
;
}
#endif
lv_objx/lv_ta.h
0 → 100644
View file @
d04c2463
/**
* @file lv_ta.h
*
*/
#ifndef LV_TA_H
#define LV_TA_H
/*********************
* INCLUDES
*********************/
#include "lv_conf.h"
#if USE_LV_TA != 0
#include "../lv_obj/lv_obj.h"
#include "lv_page.h"
#include "lv_label.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Style of text area*/
typedef
struct
{
lv_pages_t
pages
;
/*Style of ancestor*/
/*New style element for this type */
lv_labels_t
labels
;
uint8_t
cursor_show
:
1
;
}
lv_tas_t
;
/*Built-in styles of text area*/
typedef
enum
{
LV_TAS_DEF
,
}
lv_tas_builtin_t
;
/*Data of text area*/
typedef
struct
{
lv_page_ext_t
page
;
/*Ext. of ancestor*/
/*New data for this type */
lv_obj_t
*
label_dp
;
uint16_t
cursor_pos
;
}
lv_ta_ext_t
;
/**********************
* GLOBAL PROTOTYPES
**********************/
lv_obj_t
*
lv_ta_create
(
lv_obj_t
*
par_dp
,
lv_obj_t
*
copy_dp
);
bool
lv_ta_signal
(
lv_obj_t
*
obj_dp
,
lv_signal_t
sign
,
void
*
param
);
lv_tas_t
*
lv_tas_get
(
lv_tas_builtin_t
style
,
lv_tas_t
*
copy_p
);
void
lv_ta_add_char
(
lv_obj_t
*
obj_dp
,
char
c
);
void
lv_ta_set_cursor_pos
(
lv_obj_t
*
obj_dp
,
uint16_t
pos
);
const
char
*
lv_ta_get_txt
(
lv_obj_t
obj_dp
);
uint16_t
lv_ta_get_cursor_pos
(
lv_obj_t
*
obj_dp
);
/**********************
* MACROS
**********************/
#endif
#endif
lvgl.h
View file @
d04c2463
...
...
@@ -22,6 +22,7 @@
#include "lv_objx/lv_pb.h"
#include "lv_objx/lv_led.h"
#include "lv_objx/lv_btnm.h"
#include "lv_objx/lv_ta.h"
/*********************
* DEFINES
...
...
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