mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
remove lv_example because it is moved to seperate repo
This commit is contained in:
parent
bf1903d17b
commit
866f53658e
@ -1,67 +0,0 @@
|
||||
/**
|
||||
* @file lv_ex_hello_world.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Greetings,
|
||||
* this is the first example in the tutorial hence this is the most simple one.
|
||||
* It only creates a Label, set its text, and align to the middle.
|
||||
*
|
||||
* Be sure in lv_conf.h LV_APP_ENEBLE is 0 (just for simplicity)
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_ex_hello_world.h"
|
||||
#if USE_LV_EXAMPLE != 0
|
||||
|
||||
#include "lvgl/lvgl.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Create a simple 'Hello world!' label
|
||||
*/
|
||||
void lv_ex_hello_world(void)
|
||||
{
|
||||
/*Create a Label on the current screen*/
|
||||
lv_obj_t * label1 = lv_label_create(lv_scr_act(), NULL);
|
||||
|
||||
/*Modify the Label's text*/
|
||||
lv_label_set_text(label1, "Hello world!");
|
||||
|
||||
/* Align the Label to the center
|
||||
* NULL means align on parent (which is the screen now)
|
||||
* 0, 0 at the and means an x, y offset after alignment*/
|
||||
lv_obj_align_us(label1, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_EXAMPLE != 0*/
|
@ -1,42 +0,0 @@
|
||||
/**
|
||||
* @file lv_ex_hello_world.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EX_HELLO_WORLD_H
|
||||
#define LV_EX_HELLO_WORLD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_conf.h"
|
||||
#if USE_LV_EXAMPLE != 0
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_ex_hello_world(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_EXAMPLE != 0*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_HELLO_WORLD_H*/
|
Binary file not shown.
Before Width: | Height: | Size: 1.8 KiB |
@ -1,218 +0,0 @@
|
||||
/**
|
||||
* @file lv_hello_world.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* The basic building blocks (components or widgets) in LittlevGL are the graphical objects.
|
||||
* For example:
|
||||
* - Buttons
|
||||
* - Labels
|
||||
* - Charts
|
||||
* - Sliders etc
|
||||
*
|
||||
* In this part you can learn the basics of the objects like creating, positioning, sizing etc.
|
||||
* You will also meet some different object types and their attributes.
|
||||
*
|
||||
* Regardless to the object type the 'lv_obj_t' variable type is used stores the objects
|
||||
* and you can refer to an object with an lv_obj_t pointer (lv_obj_t *)
|
||||
*
|
||||
* INHERITANCE
|
||||
* -------------
|
||||
* Similarly to object oriented languages some kind of inheritance is used
|
||||
* among the object types.
|
||||
*
|
||||
* Every object is derived from the 'Basic object'. (lv_obj)
|
||||
*
|
||||
* The types are backward compatible which means a type can use all the ancestor
|
||||
* attributes/functions too.
|
||||
*
|
||||
* For example a 'Button' is derived from 'Container' which is derived from 'Basic objects'.
|
||||
* Therefore a button can use container attributes like automatically fit size to the content.
|
||||
*
|
||||
* PARENT-CHILD
|
||||
* -------------
|
||||
* A parent can be considered as the container of its children.
|
||||
* Every object has exactly one parent object (except screens).
|
||||
* A parent can have unlimited number of children.
|
||||
* There is no limitation for the type of the parent.
|
||||
*
|
||||
* The children are visible only on their parent. The parts outside will be cropped (not displayed)
|
||||
*
|
||||
* If the parent is moved the children will be moved with it.
|
||||
*
|
||||
* The earlier created object (and its children) will drawn earlier.
|
||||
* Using this layers can be built.
|
||||
*
|
||||
* LEARN MORE
|
||||
* -------------
|
||||
* - General overview: http://www.gl.littlev.hu/objects
|
||||
* - Detailed description of types: http://www.gl.littlev.hu/object-types
|
||||
*
|
||||
* NOTES
|
||||
* -------------
|
||||
* - Be sure 'LV_OBJ_FREE_P' is enabled in 'lv_conf.h'
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_ex_objects.h"
|
||||
#if USE_LV_EXAMPLE != 0
|
||||
|
||||
#include "lvgl/lvgl.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static lv_action_res_t btn_rel_action(lv_obj_t * btn, LV_INDEV_t * indev_proc);
|
||||
static lv_action_res_t ddlist_action(lv_obj_t * ddlist, LV_INDEV_t * indev_proc);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the Object usage example
|
||||
*/
|
||||
void lv_ex_objects(void)
|
||||
{
|
||||
|
||||
/********************
|
||||
* CREATE A SCREEN
|
||||
*******************/
|
||||
|
||||
/* Create a new screen and load it
|
||||
* Screen can be created from any type object
|
||||
* Now a Page is used which is an objects with scrollable content*/
|
||||
lv_obj_t * scr = lv_page_create(NULL, NULL);
|
||||
lv_scr_load(scr);
|
||||
|
||||
|
||||
/****************
|
||||
* ADD A TITLE
|
||||
****************/
|
||||
lv_obj_t * label = lv_label_create(scr, NULL); /*First parameters (scr) is the parent*/
|
||||
lv_label_set_text(label, "Object usage demo"); /*Set the text*/
|
||||
lv_obj_set_x(label, 50); /*Labels are inherited from Basic object so 'lv_obj_...' functions can be used*/
|
||||
|
||||
|
||||
/********************
|
||||
* CREATE TWO BUTTONS
|
||||
********************/
|
||||
|
||||
/*Create a button*/
|
||||
lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL); /*Create a button on the currently loaded screen*/
|
||||
lv_btn_set_rel_action(btn1, btn_rel_action); /*Set function to call when the button is released*/
|
||||
lv_obj_align(btn1, label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 20); /*Align below the label*/
|
||||
label = lv_label_create(btn1, NULL); /*Create a label on the button (the 'label' variable can be reused)*/
|
||||
lv_label_set_text(label, "Button 1");
|
||||
|
||||
/*Copy the previous button*/
|
||||
lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), btn1); /*Second parameter is an object to copy*/
|
||||
lv_obj_align(btn2, btn1, LV_ALIGN_OUT_RIGHT_MID, 50, 0);/*Align next to the prev. button.*/
|
||||
label = lv_label_create(btn2, NULL); /*Create a label on the button*/
|
||||
lv_label_set_text(label, "Button 2");
|
||||
|
||||
|
||||
/****************
|
||||
* ADD A SLIDER
|
||||
****************/
|
||||
|
||||
/*Add a slider (inheritance: lv_obj -> lv_bar -> lv_slider)*/
|
||||
lv_obj_t * slider = lv_slider_create(scr, NULL); /*Create a slider*/
|
||||
lv_obj_set_size(slider, lv_obj_get_width(lv_scr_act()) / 3, LV_DPI / 3); /*Set the size*/
|
||||
lv_obj_align(slider, btn1, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 20); /*Align below the first button*/
|
||||
lv_bar_set_value(slider, 30); /*Slider is a 'bar' so set its value like a 'bar'*/
|
||||
|
||||
|
||||
/***********************
|
||||
* ADD A DROP DOWN LIST
|
||||
************************/
|
||||
|
||||
lv_obj_t * ddlist = lv_ddlist_create(lv_scr_act(), NULL);
|
||||
lv_obj_align(ddlist, slider, LV_ALIGN_OUT_RIGHT_TOP, 20, 0); /*Align next to the slider*/
|
||||
lv_obj_set_free_p(ddlist, slider); /*Save the pointer of the slider in the ddlist (used in 'ddlist_action()')*/
|
||||
lv_ddlist_set_options_str(ddlist, "None\nLittle\nHalf\nA lot\nAll"); /*Set the options*/
|
||||
lv_ddlist_set_action(ddlist, ddlist_action); /*Set function to call on new option choose*/
|
||||
lv_obj_set_top(ddlist, true); /*Enable the drop down list always be on the top*/
|
||||
|
||||
|
||||
/****************
|
||||
* CREATE A CHART
|
||||
****************/
|
||||
lv_obj_t * chart = lv_chart_create(lv_scr_act(), NULL); /*Craete the chart*/
|
||||
lv_obj_set_size(chart, lv_obj_get_width(scr) / 2, lv_obj_get_width(scr) / 4); /*Set the size*/
|
||||
lv_obj_align(chart, slider, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 20); /*Align below the slider*/
|
||||
lv_chart_set_dl_width(chart, 3 << LV_ANTIALIAS); /*Set the line width (LV_DOWNSCALE compensates anti-aliasing if enabled)*/
|
||||
|
||||
/*Add a RED data line and set some points*/
|
||||
lv_chart_dl_t * dl1 = lv_chart_add_data_line(chart, COLOR_RED);
|
||||
lv_chart_set_next(chart, dl1, 10);
|
||||
lv_chart_set_next(chart, dl1, 25);
|
||||
lv_chart_set_next(chart, dl1, 45);
|
||||
lv_chart_set_next(chart, dl1, 80);
|
||||
|
||||
/*Add a BLUE data line and set some points*/
|
||||
lv_chart_dl_t * dl2 = lv_chart_add_data_line(chart, COLOR_MAKE(0x40, 0x70, 0xC0));
|
||||
lv_chart_set_next(chart, dl2, 10);
|
||||
lv_chart_set_next(chart, dl2, 25);
|
||||
lv_chart_set_next(chart, dl2, 45);
|
||||
lv_chart_set_next(chart, dl2, 80);
|
||||
lv_chart_set_next(chart, dl2, 75);
|
||||
lv_chart_set_next(chart, dl2, 505);
|
||||
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Called when a button is released
|
||||
* @param btn pointer to the released button
|
||||
* @param indev_proc pointer to caller display input (e.g. touchpad)
|
||||
* @return LV_ACTION_RES_OK because the object is not deleted in this function
|
||||
*/
|
||||
static lv_action_res_t btn_rel_action(lv_obj_t * btn, LV_INDEV_t * indev_proc)
|
||||
{
|
||||
/*Increase the button width*/
|
||||
cord_t width = lv_obj_get_width(btn);
|
||||
lv_obj_set_width(btn, width + 20);
|
||||
|
||||
return LV_ACTION_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a new option is chosen in the drop down list
|
||||
* @param ddlist pointer to the drop down list
|
||||
* @param indev_proc pointer to caller display input (e.g. touchpad)
|
||||
* @return LV_ACTION_RES_OK because the object is not deleted in this function
|
||||
*/
|
||||
static lv_action_res_t ddlist_action(lv_obj_t * ddlist, LV_INDEV_t * indev_proc)
|
||||
{
|
||||
uint16_t opt = lv_ddlist_get_selected(ddlist); /*Get the id of selected option*/
|
||||
|
||||
lv_obj_t * slider = lv_obj_get_free_p(ddlist); /*Get the saved slider*/
|
||||
lv_bar_set_value(slider, (opt * 100) / 4); /*Modify the slider value according to the selection*/
|
||||
|
||||
return LV_ACTION_RES_OK;
|
||||
}
|
||||
|
||||
#endif /*USE_LV_EXAMPLE != 0*/
|
@ -1,42 +0,0 @@
|
||||
/**
|
||||
* @file lv_ex_objects.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EX_OBJECTS_H
|
||||
#define LV_EX_OBJECTS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_conf.h"
|
||||
#if USE_LV_EXAMPLE != 0
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_ex_objects(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_EXAMPLE != 0*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_OBJ_USAGE_H*/
|
Binary file not shown.
Before Width: | Height: | Size: 11 KiB |
@ -1,161 +0,0 @@
|
||||
/**
|
||||
* @file lv_ex_styles.h
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* You can modify the appearance of the graphical objects with styles.
|
||||
* A style is simple 'lv_style_t' variable.
|
||||
* Objects save the address of this variable so it has to be 'static or 'global'.
|
||||
*
|
||||
* A style contains various attributes to describe rectangle, image or text like
|
||||
* objects at same time. To know which attribute is used by an object see:
|
||||
* http://www.gl.littlev.hu/object-types
|
||||
*
|
||||
* To set a new style for an object use: 'lv_obj_set_style(obj, &style);
|
||||
* If NULL is set as style then the object will inherit the parents style.
|
||||
* For example is you create a style for button the label appearance can be defined there as well.
|
||||
*
|
||||
* You can use built-in styles. 'lv_style_get(LV_STYLE_... , ©)' will give you a pointer to built in style
|
||||
* and copy it to variable (second parameter) if it is not NULL.
|
||||
* By default the objects use the built-in styles.
|
||||
* The built-in styles can be modified in run time to give a new default skin to your GUI.
|
||||
*
|
||||
* Learn more here: http://www.gl.littlev.hu/objects#style
|
||||
* */
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_ex_styles.h"
|
||||
|
||||
#if USE_LV_EXAMPLE != 0
|
||||
|
||||
#include "lvgl/lvgl.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Create a simple 'Hello world!' label
|
||||
*/
|
||||
void lv_ex_styles(void)
|
||||
{
|
||||
|
||||
/****************************************
|
||||
* BASE OBJECT + LABEL WITH DEFAULT STYLE
|
||||
****************************************/
|
||||
|
||||
lv_obj_t * obj1;
|
||||
obj1 = lv_obj_create(lv_scr_act(), NULL); /*Create a simple objects*/
|
||||
lv_obj_set_pos(obj1, 10, 10);
|
||||
lv_obj_t * label = lv_label_create(obj1, NULL);
|
||||
|
||||
/*Add a label to the object*/
|
||||
lv_label_set_text(label, "Default");
|
||||
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
/****************************************
|
||||
* BASE OBJECT WITH PRETTY COLOR STYLE
|
||||
****************************************/
|
||||
|
||||
lv_obj_t * obj2;
|
||||
obj2 = lv_obj_create(lv_scr_act(), NULL);
|
||||
lv_obj_align(obj2, obj1, LV_ALIGN_OUT_RIGHT_MID, 20, 0); /*Align next to the previous object*/
|
||||
lv_obj_set_style(obj2, lv_style_get(LV_STYLE_PRETTY_COLOR, NULL)); /*Set built in style*/
|
||||
label = lv_label_create(obj2, NULL);
|
||||
|
||||
/* Add a label to the object.
|
||||
* Labels by default inherit the parent's style */
|
||||
lv_label_set_text(label, "Pretty\ncolor");
|
||||
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
/*****************************
|
||||
* BASE OBJECT WITH NEW STYLE
|
||||
*****************************/
|
||||
|
||||
/* Create a new style */
|
||||
static lv_style_t style_new; /*Styles can't be local variables*/
|
||||
lv_style_get(LV_STYLE_PRETTY_COLOR, &style_new); /*Copy a built-in style as a starting point*/
|
||||
style_new.radius = LV_RADIUS_CIRCLE; /*Fully round corners*/
|
||||
style_new.swidth = 8; /*8 px shadow*/
|
||||
style_new.bwidth = 2; /*2 px border width*/
|
||||
style_new.mcolor = COLOR_WHITE; /*White main color*/
|
||||
style_new.gcolor = color_mix(COLOR_BLUE, COLOR_WHITE, OPA_40); /*light blue gradient color*/
|
||||
style_new.scolor = COLOR_MAKE(0xa0, 0xa0, 0xa0); /*Light gray shadow color*/
|
||||
style_new.ccolor = color_mix(COLOR_BLUE, COLOR_WHITE, OPA_90); /*Blue content color (text color)*/
|
||||
style_new.letter_space = 10; /*10 px letter space*/
|
||||
style_new.txt_align = LV_TXT_ALIGN_MID; /*Middel text align*/
|
||||
|
||||
/*Create a base object and apply the new style*/
|
||||
lv_obj_t * obj3;
|
||||
obj3 = lv_obj_create(lv_scr_act(), NULL);
|
||||
lv_obj_align(obj3, obj2, LV_ALIGN_OUT_RIGHT_MID, 20, 0);
|
||||
lv_obj_set_style(obj3, &style_new);
|
||||
|
||||
/* Add a label to the object.
|
||||
* Labels by default inherit the parent's style */
|
||||
label = lv_label_create(obj3, NULL);
|
||||
lv_label_set_text(label, "New\nstyle");
|
||||
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
|
||||
/************************
|
||||
* CREATE A STYLED LED
|
||||
***********************/
|
||||
|
||||
/*Create a style for the LED*/
|
||||
static lv_style_t style_led;
|
||||
lv_style_get(LV_STYLE_PRETTY_COLOR, &style_led);
|
||||
style_led.swidth = 15;
|
||||
style_led.radius = LV_RADIUS_CIRCLE;
|
||||
style_led.bwidth = 3;
|
||||
style_led.bopa = OPA_30;
|
||||
style_led.mcolor = COLOR_MAKE(0xb5, 0x0f, 0x04);
|
||||
style_led.gcolor = COLOR_MAKE(0x50, 0x07, 0x02);
|
||||
style_led.bcolor = COLOR_MAKE(0xfa, 0x0f, 0x00);
|
||||
style_led.scolor = COLOR_MAKE(0xb5, 0x0f, 0x04);
|
||||
|
||||
/*Create a LED and switch it ON*/
|
||||
lv_obj_t * led1 = lv_led_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_style(led1, &style_led);
|
||||
lv_obj_align_us(led1, obj1, LV_ALIGN_OUT_BOTTOM_MID, 0, 40);
|
||||
lv_led_on(led1);
|
||||
|
||||
/*Copy the previous LED and set a brightness*/
|
||||
lv_obj_t * led2 = lv_led_create(lv_scr_act(), led1);
|
||||
lv_obj_align_us(led2, obj2, LV_ALIGN_OUT_BOTTOM_MID, 0, 40);
|
||||
lv_led_set_bright(led2, 190);
|
||||
|
||||
/*Copy the previous LED and switch it OFF*/
|
||||
lv_obj_t * led3 = lv_led_create(lv_scr_act(), led1);
|
||||
lv_obj_align_us(led3, obj3, LV_ALIGN_OUT_BOTTOM_MID, 0, 40);
|
||||
lv_led_off(led3);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_EXAMPLE != 0*/
|
@ -1,42 +0,0 @@
|
||||
/**
|
||||
* @file style_usage.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef STYLE_USAGE_H
|
||||
#define STYLE_USAGE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_conf.h"
|
||||
#if USE_LV_EXAMPLE != 0
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_ex_styles(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_EXAMPLE != 0*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_HELLO_WORLD_H*/
|
Binary file not shown.
Before Width: | Height: | Size: 11 KiB |
@ -1 +0,0 @@
|
||||
|
@ -1,328 +0,0 @@
|
||||
/**
|
||||
* @file lv_ex_encoder_ctrl.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Create a simple GUI to demonstrate how to control it with an encoder
|
||||
* using 'lv_group'.
|
||||
*
|
||||
* Be sure in lv_conf.h:
|
||||
* - LV_OBJ_GROUP 1 to enable groups
|
||||
* - LV_APP_ENABLE 0 to disable applications because they might bother now
|
||||
*
|
||||
* lv_group:
|
||||
* - you can create groups and add object to them
|
||||
* - it can be a focused object within a group
|
||||
* - the style of the focused object will be automatically modified
|
||||
* - different style modifier functions can be applied in each groups
|
||||
* - you can focus on the next or previous object (lv_group_focus_next/prev)
|
||||
* - letters can be sent to the focused object to do something (lv_group_send):
|
||||
* - LV_GROUP_KEY_RIGHT/UP: increment action in the object
|
||||
* - LV_GROUP_KEY_LEFT/DOWN: decrement action in the object
|
||||
* - LV_GROUP_KEY_ENTER: ok or select action in the object
|
||||
* - LV_GROUP_KEY_ESC: close or back action action in the object
|
||||
* - or any character for example to a text area
|
||||
*
|
||||
* The encoder is replaced by 4 button on the screen:
|
||||
* - [>] Next (lv_group_focus_next): focus on the next object in the group (simulates encoder press)
|
||||
* - [+] IncrementNext (LV_GROUP_KEY_RIGHT): increment signal to the object (simulates rotate right)
|
||||
* - [-] DecrementNext (LV_GROUP_KEY_LEFT): increment signal to the object (simulates rotate left)
|
||||
* - [!] SelectNext (LV_GROUP_KEY_ENTER): Select something (simulates encoder long press or an 'Select' button)
|
||||
*/
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_ex_encoder_ctrl.h"
|
||||
#if USE_LV_EXAMPLE != 0
|
||||
|
||||
#include "lvgl/lvgl.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void gui_create(void);
|
||||
static void enc_create(void);
|
||||
static lv_action_res_t mbox_yes_action(lv_obj_t * btn, LV_INDEV_t * indev_proc);
|
||||
static lv_action_res_t mbox_no_action(lv_obj_t * btn, LV_INDEV_t * indev_proc);
|
||||
static lv_action_res_t enable_action(lv_obj_t * btn, LV_INDEV_t * indev_proc);
|
||||
static lv_action_res_t enc_next(lv_obj_t * btn, LV_INDEV_t * indev_proc);
|
||||
static lv_action_res_t enc_inc(lv_obj_t * btn, LV_INDEV_t * indev_proc);
|
||||
static lv_action_res_t enc_dec(lv_obj_t * btn, LV_INDEV_t * indev_proc);
|
||||
static lv_action_res_t enc_sel(lv_obj_t * btn, LV_INDEV_t * indev_proc);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_obj_t * scr; /*The screen for the demo*/
|
||||
static lv_obj_t * btn_enable; /*An enable button*/
|
||||
static lv_style_t style_mbox_bg; /*Black bg. style with opacity*/
|
||||
static lv_group_t * g; /*An Object Group*/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Create a simple GUI to demonstrate encoder control capability
|
||||
*/
|
||||
void lv_ex_encoder_ctrl(void)
|
||||
{
|
||||
/* Create a Page screen (to make it scrollable)
|
||||
* and use Pretty layout to make the content responsive.
|
||||
* See the 'responsive' example for more information */
|
||||
scr = lv_page_create(NULL, NULL);
|
||||
lv_cont_set_layout(lv_page_get_scrl(scr), LV_CONT_LAYOUT_PRETTY);
|
||||
lv_page_set_sb_mode(scr, LV_PAGE_SB_MODE_AUTO);
|
||||
lv_scr_load(scr);
|
||||
|
||||
/*Create an object group for objects to focus*/
|
||||
g = lv_group_create();
|
||||
|
||||
/* Create a dark plain style for a message box's background*/
|
||||
lv_style_get(LV_STYLE_PLAIN, &style_mbox_bg);
|
||||
style_mbox_bg.mcolor = COLOR_BLACK;
|
||||
style_mbox_bg.gcolor = COLOR_BLACK;
|
||||
style_mbox_bg.opa = OPA_50;
|
||||
|
||||
/*Create a demo GUI*/
|
||||
gui_create();
|
||||
|
||||
/*Create virtual encoder*/
|
||||
enc_create();
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Create a demo GUI
|
||||
*/
|
||||
static void gui_create(void)
|
||||
{
|
||||
/*Create a title*/
|
||||
lv_obj_t * title = lv_label_create(scr, NULL);
|
||||
lv_label_set_text(title, "Encoder control");
|
||||
lv_obj_set_protect(title, LV_PROTECT_FOLLOW); /*Make a line break in the layout*/
|
||||
|
||||
/*Create a drop down list*/
|
||||
lv_obj_t * ddlist = lv_ddlist_create(scr, NULL);
|
||||
lv_ddlist_set_options_str(ddlist, "Low\nMedium\nHigh");
|
||||
lv_group_add_obj(g, ddlist); /*Add the object to the group*/
|
||||
|
||||
/*Create a holder an check boxes on it*/
|
||||
lv_obj_t * holder = lv_cont_create(scr, NULL); /*Create a transparent holder*/
|
||||
lv_cont_set_fit(holder, true, true);
|
||||
lv_cont_set_layout(holder, LV_CONT_LAYOUT_COL_L);
|
||||
lv_obj_set_style(holder, lv_style_get(LV_STYLE_TRANSPARENT, NULL));
|
||||
|
||||
lv_obj_t * cb = lv_cb_create(holder, NULL); /*First check box*/
|
||||
lv_cb_set_text(cb, "Red");
|
||||
lv_group_add_obj(g, cb); /*Add to the group*/
|
||||
|
||||
cb = lv_cb_create(holder, cb); /*Copy the first check box. Automatically added to the same group*/
|
||||
lv_cb_set_text(cb, "Green");
|
||||
|
||||
cb = lv_cb_create(holder, cb); /*Copy the second check box. Automatically added to the same group*/
|
||||
lv_cb_set_text(cb, "Blue");
|
||||
|
||||
/*Create a sliders*/
|
||||
lv_obj_t * slider = lv_slider_create(scr, NULL);
|
||||
lv_obj_set_size_us(slider, 180, 30);
|
||||
lv_bar_set_range(slider, 0, 20);
|
||||
lv_group_add_obj(g, slider); /*Add to the group*/
|
||||
|
||||
/*Create a button*/
|
||||
btn_enable = lv_btn_create(scr, NULL);
|
||||
lv_btn_set_rel_action(btn_enable, enable_action);
|
||||
lv_cont_set_fit(btn_enable, true, true);
|
||||
lv_group_add_obj(g, btn_enable); /*Add to the group*/
|
||||
lv_obj_t * l = lv_label_create(btn_enable, NULL);
|
||||
lv_label_set_text(l, "Enable");
|
||||
lv_obj_set_protect(btn_enable, LV_PROTECT_FOLLOW); /*Make a line break in the layout*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Create virtual encoder using 4 buttons:
|
||||
* - [>] Next: focus on the next object in the group (simulates encoder press)
|
||||
* - [+] Increment: increment signal to the object (simulates rotate right)
|
||||
* - [-] Decrement: increment signal to the object (simulates rotate left)
|
||||
* - [!] Select: Select something (simulates encoder long press or an 'Select' button)
|
||||
*/
|
||||
static void enc_create(void)
|
||||
{
|
||||
/*Next button*/
|
||||
lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);
|
||||
lv_btn_set_rel_action(btn, enc_next);
|
||||
lv_cont_set_fit(btn, true, true);
|
||||
lv_obj_t * l = lv_label_create(btn, NULL);
|
||||
lv_label_set_text(l, ">");
|
||||
|
||||
/*Increment button*/
|
||||
btn = lv_btn_create(lv_scr_act(), btn);
|
||||
lv_btn_set_rel_action(btn, enc_dec);
|
||||
l = lv_label_create(btn, NULL);
|
||||
lv_label_set_text(l, "-");
|
||||
|
||||
/*Decrement button*/
|
||||
btn = lv_btn_create(lv_scr_act(), btn);
|
||||
lv_btn_set_rel_action(btn, enc_inc);
|
||||
l = lv_label_create(btn, NULL);
|
||||
lv_label_set_text(l, "+");
|
||||
|
||||
/*Select button*/
|
||||
btn = lv_btn_create(lv_scr_act(), btn);
|
||||
lv_btn_set_rel_action(btn, enc_sel);
|
||||
l = lv_label_create(btn, NULL);
|
||||
lv_label_set_text(l, "!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Enable button is released. Show a message box to really enable or not?
|
||||
* @param btn pointer to the Enable button
|
||||
* @param indev_proc pointer to the caller display input or NULL if the encoder used
|
||||
* @return LV_ACTION_RES_OK: because the button is not deleted
|
||||
*/
|
||||
static lv_action_res_t enable_action(lv_obj_t * btn, LV_INDEV_t * indev_proc)
|
||||
{
|
||||
/*If the butto nsi released the show message box to be sure about the Enable*/
|
||||
if(lv_btn_get_state(btn) == LV_BTN_STATE_REL) {
|
||||
/* Create a dark screen sized bg. with opacity to show
|
||||
* the other objects are not available now*/
|
||||
lv_obj_t * bg = lv_obj_create(scr, NULL);
|
||||
lv_obj_set_protect(bg, LV_PROTECT_PARENT); /*The page screen move it to scrollable area*/
|
||||
lv_obj_set_parent(bg, scr); /*So movi it back ater protected*/
|
||||
lv_obj_set_style(bg, &style_mbox_bg);
|
||||
lv_obj_set_size(bg, LV_HOR_RES, LV_VER_RES);
|
||||
lv_obj_set_pos(bg, 0, 0);
|
||||
lv_obj_set_click(bg, false); /*For test disable click there fore buttons under it remain clickable*/
|
||||
|
||||
/*Create a message box*/
|
||||
lv_obj_t * mbox = lv_mbox_create(bg, NULL);
|
||||
lv_mbox_set_text(mbox, "Really Enable the outputs?");
|
||||
lv_group_add_obj(g, mbox); /*Add to he group*/
|
||||
|
||||
/*Add two buttons*/
|
||||
lv_mbox_add_btn(mbox, "Yes", mbox_yes_action);
|
||||
lv_mbox_add_btn(mbox, "No", mbox_no_action);
|
||||
|
||||
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, - LV_DPI / 2);
|
||||
|
||||
/*Focus on the new message box, can freeze focus on it*/
|
||||
lv_group_focus_obj(mbox);
|
||||
lv_group_focus_freeze(g, true);
|
||||
}
|
||||
/*Disable is not dangerous so just change the button state*/
|
||||
else {
|
||||
lv_btn_set_state(btn_enable, LV_BTN_STATE_REL);
|
||||
}
|
||||
return LV_ACTION_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the message box's 'Yes' button is released
|
||||
* @param btn pointer to the 'Yes' button
|
||||
* @param indev_proc pointer to the caller display input or NULL if the encoder used
|
||||
* @return LV_ACTION_RES_INV: because the button along with the message box will be deleted
|
||||
*/
|
||||
static lv_action_res_t mbox_yes_action(lv_obj_t * btn, LV_INDEV_t * indev_proc)
|
||||
{
|
||||
lv_group_focus_freeze(g, false); /*Release the freeze*/
|
||||
lv_obj_t * mbox = lv_mbox_get_from_btn(btn);
|
||||
lv_obj_del(lv_obj_get_parent(mbox)); /*Delete the black background. (it will delete the mbox too)*/
|
||||
|
||||
/*Mark the enabled state by toggling the button*/
|
||||
lv_btn_set_state(btn_enable, LV_BTN_STATE_TREL);
|
||||
|
||||
/* In a real case you can add some specific actions here
|
||||
* to really enable something */
|
||||
|
||||
return LV_ACTION_RES_INV;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the message box's 'No' button is released
|
||||
* @param btn pointer to the 'No' button
|
||||
* @param indev_proc pointer to the caller display input or NULL if the encoder used
|
||||
* @return LV_ACTION_RES_INV: because the button along with the message box will be deleted
|
||||
*/
|
||||
static lv_action_res_t mbox_no_action(lv_obj_t * btn, LV_INDEV_t * indev_proc)
|
||||
{
|
||||
lv_group_focus_freeze(g, false); /*Release the freeze*/
|
||||
lv_obj_t * mbox = lv_mbox_get_from_btn(btn);
|
||||
lv_obj_del(lv_obj_get_parent(mbox)); /*Delete the black background. (it will delete the mbox too)*/
|
||||
|
||||
return LV_ACTION_RES_INV;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Encoder emulator's Next button is released
|
||||
* @param btn pointer to the button
|
||||
* @param indev_proc pointer to the caller display input
|
||||
* @return LV_ACTION_RES_OK: because the button is not deleted
|
||||
*/
|
||||
static lv_action_res_t enc_next(lv_obj_t * btn, LV_INDEV_t * indev_proc)
|
||||
{
|
||||
/*Focus on the next object in the group*/
|
||||
lv_group_focus_next(g);
|
||||
|
||||
return LV_ACTION_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Encoder emulator's Increment button is released
|
||||
* @param btn pointer to the button
|
||||
* @param indev_proc pointer to the caller display input
|
||||
* @return LV_ACTION_RES_OK: because the button is not deleted
|
||||
*/
|
||||
static lv_action_res_t enc_inc(lv_obj_t * btn, LV_INDEV_t * indev_proc)
|
||||
{
|
||||
/* Send RIGHT key when rotate to right.
|
||||
* It will trigger an increment like action in the object */
|
||||
lv_group_send(g, LV_GROUP_KEY_RIGHT);
|
||||
return LV_ACTION_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Encoder emulator's Increment button is released
|
||||
* @param btn pointer to the button
|
||||
* @param indev_proc pointer to the caller display input
|
||||
* @return LV_ACTION_RES_OK: because the button is not deleted
|
||||
*/
|
||||
static lv_action_res_t enc_dec(lv_obj_t * btn, LV_INDEV_t * indev_proc)
|
||||
{
|
||||
/* Send LEFT key when rotate to left.
|
||||
* It will trigger a decrement like action in the object */
|
||||
lv_group_send(g, LV_GROUP_KEY_LEFT);
|
||||
|
||||
return LV_ACTION_RES_OK;
|
||||
}
|
||||
/**
|
||||
* Called when the Encoder emulator's Send button is released
|
||||
* @param btn pointer to the button
|
||||
* @param indev_proc pointer to the caller display input
|
||||
* @return LV_ACTION_RES_OK: because the button is not deleted
|
||||
*/
|
||||
static lv_action_res_t enc_sel(lv_obj_t * btn, LV_INDEV_t * indev_proc)
|
||||
{
|
||||
/* Send ENTER key.
|
||||
* It will trigger an 'OK' or 'Select' action in the object */
|
||||
lv_group_send(g, LV_GROUP_KEY_ENTER);
|
||||
|
||||
return LV_ACTION_RES_OK;
|
||||
}
|
||||
|
||||
#endif /*USE_LV_EXAMPLE != 0*/
|
@ -1,42 +0,0 @@
|
||||
/**
|
||||
* @file lv_ex_encoder_ctrl.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EX_ENCODER_CTRL_H
|
||||
#define LV_EX_ENCODER_CTRL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_conf.h"
|
||||
#if USE_LV_EXAMPLE != 0
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_ex_encoder_ctrl(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_EXAMPLE != 0*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*ENCODER_CTRL_H*/
|
Binary file not shown.
Before Width: | Height: | Size: 8.8 KiB |
@ -1,41 +0,0 @@
|
||||
# EXAMPLES FOR LITTLEV GRAPHICS LIBRARY
|
||||
|
||||
## Introduction
|
||||
In the folders you will find simple hardware independent examples to know the key features of Littlev Graphics Library.
|
||||
The examples are organized in consistent way and can be used as a **Tutorial**.
|
||||
|
||||
Every example consist of least an *example_name.c* and *example_name.h* files. You can load an example in your *main* function with **example_name_init()**. The header file has to be included too.
|
||||
|
||||
You will find **detailed explanation** in the *c* and *h* files.
|
||||
|
||||
The examples can be enabled/disabled in *lv_conf.h* with **USE_LV_EXAMPLES**.
|
||||
|
||||
## 1_x Getting started
|
||||
With examples in this section you can learn the basics from a simple *Hello world* label to a complex full featured GUI with animations and other effects. You will learn about
|
||||
- creating, deleting graphical objects
|
||||
- modify their attributes
|
||||
- change their style
|
||||
- and even creating a new object type
|
||||
|
||||
## 2_x GUI control without Touchpad
|
||||
You can control your GUI not only with Touchpad. The most simple way to put real buttons next to the graphical ones and simulate *touch pad-like press* on the display. An other way is to organize the objects in groups and *focus* on one of objects. Then you can control the object-in-focus with simple character instructions. Or using a cursor and mouse is also possible. So an external control device can be
|
||||
- push buttons
|
||||
- encoders
|
||||
- keyboard
|
||||
- or a mouse
|
||||
|
||||
In this section you will find examples for them!
|
||||
|
||||
## 3_x Applications
|
||||
The applications are high level components to do complex thing with a nice user interface. An application can be for example
|
||||
- WiFi network manager
|
||||
- File system browser
|
||||
- System monitor
|
||||
- Terminal etc.
|
||||
|
||||
Here you will find examples how to run application, and communicate with them.
|
||||
|
||||
## Final words
|
||||
If you also have codes which could be useful for others, please share it via *Pull requests* on *GitHub*!
|
||||
Thank you in advance!
|
||||
|
Loading…
x
Reference in New Issue
Block a user