summaryrefslogtreecommitdiff
path: root/src/libs/lvgl/docs/CODING_STYLE.md
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/lvgl/docs/CODING_STYLE.md')
-rw-r--r--src/libs/lvgl/docs/CODING_STYLE.md43
1 files changed, 19 insertions, 24 deletions
diff --git a/src/libs/lvgl/docs/CODING_STYLE.md b/src/libs/lvgl/docs/CODING_STYLE.md
index 31071e94..46bc6375 100644
--- a/src/libs/lvgl/docs/CODING_STYLE.md
+++ b/src/libs/lvgl/docs/CODING_STYLE.md
@@ -1,6 +1,7 @@
+# Coding style
## File format
-Use [lv_misc/lv_templ.c](https://github.com/littlevgl/lvgl/blob/master/src/lv_misc/lv_templ.c) and [lv_misc/lv_templ.h](https://github.com/littlevgl/lvgl/blob/master/src/lv_misc/lv_templ.h)
+Use [lv_misc/lv_templ.c](https://github.com/lvgl/lvgl/blob/master/src/lv_misc/lv_templ.c) and [lv_misc/lv_templ.h](https://github.com/lvgl/lvgl/blob/master/src/lv_misc/lv_templ.h)
## Naming conventions
* Words are separated by '_'
@@ -10,22 +11,23 @@ Use [lv_misc/lv_templ.c](https://github.com/littlevgl/lvgl/blob/master/src/lv_mi
* starts with *lv*
* followed by module name: *btn*, *label*, *style* etc.
* followed by the action (for functions): *set*, *get*, *refr* etc.
- * closed with the subject: *name*, *size*, *state* etc.
+ * closed with the subject: *name*, *size*, *state* etc.
* Typedefs
* prefer `typedef struct` and `typedef enum` instead of `struct name` and `enum name`
* always end `typedef struct` and `typedef enum` type names with `_t`
* Abbreviations:
- * Use abbreviations on public names only if they become longer than 32 characters
- * Use only very straightforward (e.g. pos: position) or well-established (e.g. pr: press) abbreviations
+ * Only words longer or equal than 6 characters can be abbreviated.
+ * Abbreviate only if it makes the word at least half as long
+ * Use only very straightforward and well-known abbreviations (e.g. pos: position, def: default, btn: button)
## Coding guide
* Functions:
- * Try to write function shorter than is 50 lines
- * Always shorter than 100 lines (except very straightforwards)
+ * Try to write function shorter than is 50 lines
+ * Always shorter than 200 lines (except very straightforwards)
* Variables:
* One line, one declaration (BAD: char x, y;)
* Use `<stdint.h>` (*uint8_t*, *int32_t* etc)
- * Declare variables when needed (not all at function start)
+ * Declare variables where needed (not all at function start)
* Use the smallest required scope
* Variables in a file (outside functions) are always *static*
* Do not use global variables (use functions to set/get static variables)
@@ -39,16 +41,16 @@ Before every function have a comment like this:
* @param obj pointer to an object
* @return pointer to a screen
*/
-lv_obj_t * lv_obj_get_scr(lv_obj_t * obj);
+lv_obj_t * lv_obj_get_scr(lv_obj_t * obj);
```
Always use `/* Something */` format and NOT `//Something`
-Write readable code to avoid descriptive comments like:
-`x++; /* Add 1 to x */`.
+Write readable code to avoid descriptive comments like:
+`x++; /* Add 1 to x */`.
The code should show clearly what you are doing.
-You should write **why** have you done this:
+You should write **why** have you done this:
`x++; /*Because of closing '\0' of the string */`
Short "code summaries" of a few lines are accepted. E.g. `/*Calculate the new coordinates*/`
@@ -65,30 +67,23 @@ Here is example to show bracket placing and using of white spaces:
*/
void lv_label_set_text(lv_obj_t * label, const char * text)
{ /* Main brackets of functions in new line*/
-
+
if(label == NULL) return; /*No bracket only if the command is inline with the if statement*/
-
+
lv_obj_inv(label);
-
+
lv_label_ext_t * ext = lv_obj_get_ext(label);
/*Comment before a section */
if(text == ext->txt || text == NULL) { /*Bracket of statements start inline*/
lv_label_refr_text(label);
- return;
+ return;
}
-
+
...
}
```
Use 4 spaces indentation instead of tab.
-You can use **astyle** to format the code. The required config flies are: `docs/astyle_c` and `docs/astyle_h`.
-To format the source files:
- `$ find . -type f -name "*.c" | xargs astyle --options=docs/astyle_c`
-
-To format the header files:
- `$ find . -type f -name "*.h" | xargs astyle --options=docs/astyle_h`
-
-Append `-n` to the end to skip creation of backup file OR use `$ find . -type f -name "*.bak" -delete` (for source file's backups) and `find . -type f -name "*.orig" -delete` (for header file's backups)
+You can use **astyle** to format the code. Run `code-formatter.sh` from the `scrips` folder.