init Files
This commit is contained in:
109
libraries/lvgl/examples/styles/index.rst
Normal file
109
libraries/lvgl/examples/styles/index.rst
Normal file
@@ -0,0 +1,109 @@
|
||||
|
||||
Size styles
|
||||
-----------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_1
|
||||
:language: c
|
||||
|
||||
Background styles
|
||||
-----------------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_2
|
||||
:language: c
|
||||
|
||||
Border styles
|
||||
-------------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_3
|
||||
:language: c
|
||||
|
||||
Outline styles
|
||||
--------------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_4
|
||||
:language: c
|
||||
|
||||
Shadow styles
|
||||
-------------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_5
|
||||
:language: c
|
||||
|
||||
Image styles
|
||||
------------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_6
|
||||
:language: c
|
||||
|
||||
Arc styles
|
||||
----------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_7
|
||||
:language: c
|
||||
|
||||
Text styles
|
||||
-----------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_8
|
||||
:language: c
|
||||
|
||||
Line styles
|
||||
-----------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_9
|
||||
:language: c
|
||||
|
||||
Transition
|
||||
----------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_10
|
||||
:language: c
|
||||
|
||||
Using multiple styles
|
||||
---------------------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_11
|
||||
:language: c
|
||||
|
||||
Local styles
|
||||
------------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_12
|
||||
:language: c
|
||||
|
||||
Add styles to parts and states
|
||||
------------------------------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_13
|
||||
:language: c
|
||||
|
||||
Extending the current theme
|
||||
---------------------------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_14
|
||||
:language: c
|
||||
|
||||
Opacity and Transformations
|
||||
---------------------------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_15
|
||||
:language: c
|
||||
|
||||
Metallic knob with conic gradient
|
||||
---------------------------------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_16
|
||||
:language: c
|
||||
|
||||
Radial gradient as background
|
||||
-----------------------------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_17
|
||||
:language: c
|
||||
|
||||
Gradients for button background
|
||||
-----------------------------
|
||||
|
||||
.. lv_example:: styles/lv_example_style_18
|
||||
:language: c
|
||||
|
||||
55
libraries/lvgl/examples/styles/lv_example_style.h
Normal file
55
libraries/lvgl/examples/styles/lv_example_style.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* @file lv_example_style.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EXAMPLE_STYLE_H
|
||||
#define LV_EXAMPLE_STYLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_style_1(void);
|
||||
void lv_example_style_2(void);
|
||||
void lv_example_style_3(void);
|
||||
void lv_example_style_4(void);
|
||||
void lv_example_style_5(void);
|
||||
void lv_example_style_6(void);
|
||||
void lv_example_style_7(void);
|
||||
void lv_example_style_8(void);
|
||||
void lv_example_style_9(void);
|
||||
void lv_example_style_10(void);
|
||||
void lv_example_style_11(void);
|
||||
void lv_example_style_12(void);
|
||||
void lv_example_style_13(void);
|
||||
void lv_example_style_14(void);
|
||||
void lv_example_style_15(void);
|
||||
void lv_example_style_16(void);
|
||||
void lv_example_style_17(void);
|
||||
void lv_example_style_18(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EXAMPLE_STYLE_H*/
|
||||
31
libraries/lvgl/examples/styles/lv_example_style_1.c
Normal file
31
libraries/lvgl/examples/styles/lv_example_style_1.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES && LV_USE_IMAGE
|
||||
|
||||
/**
|
||||
* Using the Size, Position and Padding style properties
|
||||
*/
|
||||
void lv_example_style_1(void)
|
||||
{
|
||||
static lv_style_t style;
|
||||
lv_style_init(&style);
|
||||
lv_style_set_radius(&style, 5);
|
||||
|
||||
/*Make a gradient*/
|
||||
lv_style_set_width(&style, 150);
|
||||
lv_style_set_height(&style, LV_SIZE_CONTENT);
|
||||
|
||||
lv_style_set_pad_ver(&style, 20);
|
||||
lv_style_set_pad_left(&style, 5);
|
||||
|
||||
lv_style_set_x(&style, lv_pct(50));
|
||||
lv_style_set_y(&style, 80);
|
||||
|
||||
/*Create an object with the new style*/
|
||||
lv_obj_t * obj = lv_obj_create(lv_screen_active());
|
||||
lv_obj_add_style(obj, &style, 0);
|
||||
|
||||
lv_obj_t * label = lv_label_create(obj);
|
||||
lv_label_set_text(label, "Hello");
|
||||
}
|
||||
|
||||
#endif
|
||||
40
libraries/lvgl/examples/styles/lv_example_style_10.c
Normal file
40
libraries/lvgl/examples/styles/lv_example_style_10.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES && LV_USE_IMAGE
|
||||
|
||||
/**
|
||||
* Creating a transition
|
||||
*/
|
||||
void lv_example_style_10(void)
|
||||
{
|
||||
static const lv_style_prop_t props[] = {LV_STYLE_BG_COLOR, LV_STYLE_BORDER_COLOR, LV_STYLE_BORDER_WIDTH, 0};
|
||||
|
||||
/* A default transition
|
||||
* Make it fast (100ms) and start with some delay (200 ms)*/
|
||||
static lv_style_transition_dsc_t trans_def;
|
||||
lv_style_transition_dsc_init(&trans_def, props, lv_anim_path_linear, 100, 200, NULL);
|
||||
|
||||
/* A special transition when going to pressed state
|
||||
* Make it slow (500 ms) but start without delay*/
|
||||
static lv_style_transition_dsc_t trans_pr;
|
||||
lv_style_transition_dsc_init(&trans_pr, props, lv_anim_path_linear, 500, 0, NULL);
|
||||
|
||||
static lv_style_t style_def;
|
||||
lv_style_init(&style_def);
|
||||
lv_style_set_transition(&style_def, &trans_def);
|
||||
|
||||
static lv_style_t style_pr;
|
||||
lv_style_init(&style_pr);
|
||||
lv_style_set_bg_color(&style_pr, lv_palette_main(LV_PALETTE_RED));
|
||||
lv_style_set_border_width(&style_pr, 6);
|
||||
lv_style_set_border_color(&style_pr, lv_palette_darken(LV_PALETTE_RED, 3));
|
||||
lv_style_set_transition(&style_pr, &trans_pr);
|
||||
|
||||
/*Create an object with the new style_pr*/
|
||||
lv_obj_t * obj = lv_obj_create(lv_screen_active());
|
||||
lv_obj_add_style(obj, &style_def, 0);
|
||||
lv_obj_add_style(obj, &style_pr, LV_STATE_PRESSED);
|
||||
|
||||
lv_obj_center(obj);
|
||||
}
|
||||
|
||||
#endif
|
||||
50
libraries/lvgl/examples/styles/lv_example_style_11.c
Normal file
50
libraries/lvgl/examples/styles/lv_example_style_11.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES && LV_USE_IMAGE
|
||||
|
||||
/**
|
||||
* Using multiple styles
|
||||
*/
|
||||
void lv_example_style_11(void)
|
||||
{
|
||||
/*A base style*/
|
||||
static lv_style_t style_base;
|
||||
lv_style_init(&style_base);
|
||||
lv_style_set_bg_color(&style_base, lv_palette_main(LV_PALETTE_LIGHT_BLUE));
|
||||
lv_style_set_border_color(&style_base, lv_palette_darken(LV_PALETTE_LIGHT_BLUE, 3));
|
||||
lv_style_set_border_width(&style_base, 2);
|
||||
lv_style_set_radius(&style_base, 10);
|
||||
lv_style_set_shadow_width(&style_base, 10);
|
||||
lv_style_set_shadow_offset_y(&style_base, 5);
|
||||
lv_style_set_shadow_opa(&style_base, LV_OPA_50);
|
||||
lv_style_set_text_color(&style_base, lv_color_white());
|
||||
lv_style_set_width(&style_base, 100);
|
||||
lv_style_set_height(&style_base, LV_SIZE_CONTENT);
|
||||
|
||||
/*Set only the properties that should be different*/
|
||||
static lv_style_t style_warning;
|
||||
lv_style_init(&style_warning);
|
||||
lv_style_set_bg_color(&style_warning, lv_palette_main(LV_PALETTE_YELLOW));
|
||||
lv_style_set_border_color(&style_warning, lv_palette_darken(LV_PALETTE_YELLOW, 3));
|
||||
lv_style_set_text_color(&style_warning, lv_palette_darken(LV_PALETTE_YELLOW, 4));
|
||||
|
||||
/*Create an object with the base style only*/
|
||||
lv_obj_t * obj_base = lv_obj_create(lv_screen_active());
|
||||
lv_obj_add_style(obj_base, &style_base, 0);
|
||||
lv_obj_align(obj_base, LV_ALIGN_LEFT_MID, 20, 0);
|
||||
|
||||
lv_obj_t * label = lv_label_create(obj_base);
|
||||
lv_label_set_text(label, "Base");
|
||||
lv_obj_center(label);
|
||||
|
||||
/*Create another object with the base style and earnings style too*/
|
||||
lv_obj_t * obj_warning = lv_obj_create(lv_screen_active());
|
||||
lv_obj_add_style(obj_warning, &style_base, 0);
|
||||
lv_obj_add_style(obj_warning, &style_warning, 0);
|
||||
lv_obj_align(obj_warning, LV_ALIGN_RIGHT_MID, -20, 0);
|
||||
|
||||
label = lv_label_create(obj_warning);
|
||||
lv_label_set_text(label, "Warning");
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
#endif
|
||||
24
libraries/lvgl/examples/styles/lv_example_style_12.c
Normal file
24
libraries/lvgl/examples/styles/lv_example_style_12.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES && LV_USE_IMAGE
|
||||
|
||||
/**
|
||||
* Local styles
|
||||
*/
|
||||
void lv_example_style_12(void)
|
||||
{
|
||||
static lv_style_t style;
|
||||
lv_style_init(&style);
|
||||
lv_style_set_bg_color(&style, lv_palette_main(LV_PALETTE_GREEN));
|
||||
lv_style_set_border_color(&style, lv_palette_lighten(LV_PALETTE_GREEN, 3));
|
||||
lv_style_set_border_width(&style, 3);
|
||||
|
||||
lv_obj_t * obj = lv_obj_create(lv_screen_active());
|
||||
lv_obj_add_style(obj, &style, 0);
|
||||
|
||||
/*Overwrite the background color locally*/
|
||||
lv_obj_set_style_bg_color(obj, lv_palette_main(LV_PALETTE_ORANGE), LV_PART_MAIN);
|
||||
|
||||
lv_obj_center(obj);
|
||||
}
|
||||
|
||||
#endif
|
||||
29
libraries/lvgl/examples/styles/lv_example_style_13.c
Normal file
29
libraries/lvgl/examples/styles/lv_example_style_13.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES && LV_USE_IMAGE
|
||||
|
||||
/**
|
||||
* Add styles to parts and states
|
||||
*/
|
||||
void lv_example_style_13(void)
|
||||
{
|
||||
static lv_style_t style_indic;
|
||||
lv_style_init(&style_indic);
|
||||
lv_style_set_bg_color(&style_indic, lv_palette_lighten(LV_PALETTE_RED, 3));
|
||||
lv_style_set_bg_grad_color(&style_indic, lv_palette_main(LV_PALETTE_RED));
|
||||
lv_style_set_bg_grad_dir(&style_indic, LV_GRAD_DIR_HOR);
|
||||
|
||||
static lv_style_t style_indic_pr;
|
||||
lv_style_init(&style_indic_pr);
|
||||
lv_style_set_shadow_color(&style_indic_pr, lv_palette_main(LV_PALETTE_RED));
|
||||
lv_style_set_shadow_width(&style_indic_pr, 10);
|
||||
lv_style_set_shadow_spread(&style_indic_pr, 3);
|
||||
|
||||
/*Create an object with the new style_pr*/
|
||||
lv_obj_t * obj = lv_slider_create(lv_screen_active());
|
||||
lv_obj_add_style(obj, &style_indic, LV_PART_INDICATOR);
|
||||
lv_obj_add_style(obj, &style_indic_pr, LV_PART_INDICATOR | LV_STATE_PRESSED);
|
||||
lv_slider_set_value(obj, 70, LV_ANIM_OFF);
|
||||
lv_obj_center(obj);
|
||||
}
|
||||
|
||||
#endif
|
||||
62
libraries/lvgl/examples/styles/lv_example_style_14.c
Normal file
62
libraries/lvgl/examples/styles/lv_example_style_14.c
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "../../src/themes/lv_theme_private.h"
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES && LV_USE_IMAGE
|
||||
|
||||
static lv_style_t style_btn;
|
||||
|
||||
/*Will be called when the styles of the base theme are already added
|
||||
to add new styles*/
|
||||
static void new_theme_apply_cb(lv_theme_t * th, lv_obj_t * obj)
|
||||
{
|
||||
LV_UNUSED(th);
|
||||
|
||||
if(lv_obj_check_type(obj, &lv_button_class)) {
|
||||
lv_obj_add_style(obj, &style_btn, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void new_theme_init_and_set(void)
|
||||
{
|
||||
/*Initialize the styles*/
|
||||
lv_style_init(&style_btn);
|
||||
lv_style_set_bg_color(&style_btn, lv_palette_main(LV_PALETTE_GREEN));
|
||||
lv_style_set_border_color(&style_btn, lv_palette_darken(LV_PALETTE_GREEN, 3));
|
||||
lv_style_set_border_width(&style_btn, 3);
|
||||
|
||||
/*Initialize the new theme from the current theme*/
|
||||
lv_theme_t * th_act = lv_display_get_theme(NULL);
|
||||
static lv_theme_t th_new;
|
||||
th_new = *th_act;
|
||||
|
||||
/*Set the parent theme and the style apply callback for the new theme*/
|
||||
lv_theme_set_parent(&th_new, th_act);
|
||||
lv_theme_set_apply_cb(&th_new, new_theme_apply_cb);
|
||||
|
||||
/*Assign the new theme to the current display*/
|
||||
lv_display_set_theme(NULL, &th_new);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extending the current theme
|
||||
*/
|
||||
void lv_example_style_14(void)
|
||||
{
|
||||
lv_obj_t * btn;
|
||||
lv_obj_t * label;
|
||||
|
||||
btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, 20);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Original theme");
|
||||
|
||||
new_theme_init_and_set();
|
||||
|
||||
btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_align(btn, LV_ALIGN_BOTTOM_MID, 0, -20);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "New theme");
|
||||
}
|
||||
|
||||
#endif
|
||||
48
libraries/lvgl/examples/styles/lv_example_style_15.c
Normal file
48
libraries/lvgl/examples/styles/lv_example_style_15.c
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES && LV_USE_BUTTON && LV_USE_LABEL
|
||||
|
||||
/**
|
||||
* Opacity and Transformations
|
||||
*/
|
||||
void lv_example_style_15(void)
|
||||
{
|
||||
lv_obj_t * btn;
|
||||
lv_obj_t * label;
|
||||
|
||||
/*Normal button*/
|
||||
btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_set_size(btn, 100, 40);
|
||||
lv_obj_align(btn, LV_ALIGN_CENTER, 0, -70);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Normal");
|
||||
lv_obj_center(label);
|
||||
|
||||
/*Set opacity
|
||||
*The button and the label is rendered to a layer first and that layer is blended*/
|
||||
btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_set_size(btn, 100, 40);
|
||||
lv_obj_set_style_opa(btn, LV_OPA_50, 0);
|
||||
lv_obj_align(btn, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Opa:50%");
|
||||
lv_obj_center(label);
|
||||
|
||||
/*Set transformations
|
||||
*The button and the label is rendered to a layer first and that layer is transformed*/
|
||||
btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_set_size(btn, 100, 40);
|
||||
lv_obj_set_style_transform_rotation(btn, 150, 0); /*15 deg*/
|
||||
lv_obj_set_style_transform_scale(btn, 256 + 64, 0); /*1.25x*/
|
||||
lv_obj_set_style_transform_pivot_x(btn, 50, 0);
|
||||
lv_obj_set_style_transform_pivot_y(btn, 20, 0);
|
||||
lv_obj_set_style_opa(btn, LV_OPA_50, 0);
|
||||
lv_obj_align(btn, LV_ALIGN_CENTER, 0, 70);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Transf.");
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
#endif
|
||||
84
libraries/lvgl/examples/styles/lv_example_style_16.c
Normal file
84
libraries/lvgl/examples/styles/lv_example_style_16.c
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES
|
||||
|
||||
#if LV_USE_DRAW_SW_COMPLEX_GRADIENTS
|
||||
|
||||
/**
|
||||
* Simulate metallic knob using conical gradient
|
||||
* For best effect set LV_GRADIENT_MAX_STOPS to 8 or at least 3
|
||||
*/
|
||||
void lv_example_style_16(void)
|
||||
{
|
||||
#if LV_GRADIENT_MAX_STOPS >= 8
|
||||
static const lv_color_t grad_colors[8] = {
|
||||
LV_COLOR_MAKE(0xe8, 0xe8, 0xe8),
|
||||
LV_COLOR_MAKE(0xff, 0xff, 0xff),
|
||||
LV_COLOR_MAKE(0xfa, 0xfa, 0xfa),
|
||||
LV_COLOR_MAKE(0x79, 0x79, 0x79),
|
||||
LV_COLOR_MAKE(0x48, 0x48, 0x48),
|
||||
LV_COLOR_MAKE(0x4b, 0x4b, 0x4b),
|
||||
LV_COLOR_MAKE(0x70, 0x70, 0x70),
|
||||
LV_COLOR_MAKE(0xe8, 0xe8, 0xe8),
|
||||
};
|
||||
#elif LV_GRADIENT_MAX_STOPS >= 3
|
||||
static const lv_color_t grad_colors[3] = {
|
||||
LV_COLOR_MAKE(0xe8, 0xe8, 0xe8),
|
||||
LV_COLOR_MAKE(0xff, 0xff, 0xff),
|
||||
LV_COLOR_MAKE(0x79, 0x79, 0x79),
|
||||
};
|
||||
#else
|
||||
static const lv_color_t grad_colors[2] = {
|
||||
LV_COLOR_MAKE(0xe8, 0xe8, 0xe8),
|
||||
LV_COLOR_MAKE(0x79, 0x79, 0x79),
|
||||
};
|
||||
#endif
|
||||
|
||||
/*Create a style with gradient background and shadow*/
|
||||
static lv_style_t style;
|
||||
lv_style_init(&style);
|
||||
lv_style_set_radius(&style, 500);
|
||||
lv_style_set_bg_opa(&style, LV_OPA_COVER);
|
||||
lv_style_set_shadow_color(&style, lv_color_black());
|
||||
lv_style_set_shadow_width(&style, 50);
|
||||
lv_style_set_shadow_offset_x(&style, 20);
|
||||
lv_style_set_shadow_offset_y(&style, 20);
|
||||
lv_style_set_shadow_opa(&style, LV_OPA_50);
|
||||
|
||||
/*First define a color gradient. In this example we use a gray color map with random values.*/
|
||||
static lv_grad_dsc_t grad;
|
||||
|
||||
lv_gradient_init_stops(&grad, grad_colors, NULL, NULL, sizeof(grad_colors) / sizeof(lv_color_t));
|
||||
|
||||
/*Make a conical gradient with the center in the middle of the object*/
|
||||
#if LV_GRADIENT_MAX_STOPS >= 8
|
||||
lv_grad_conical_init(&grad, LV_GRAD_CENTER, LV_GRAD_CENTER, 0, 120, LV_GRAD_EXTEND_REFLECT);
|
||||
#elif LV_GRADIENT_MAX_STOPS >= 3
|
||||
lv_grad_conical_init(&grad, LV_GRAD_CENTER, LV_GRAD_CENTER, 45, 125, LV_GRAD_EXTEND_REFLECT);
|
||||
#else
|
||||
lv_grad_conical_init(&grad, LV_GRAD_CENTER, LV_GRAD_CENTER, 45, 110, LV_GRAD_EXTEND_REFLECT);
|
||||
#endif
|
||||
|
||||
/*Set gradient as background*/
|
||||
lv_style_set_bg_grad(&style, &grad);
|
||||
|
||||
/*Create an object with the new style*/
|
||||
lv_obj_t * obj = lv_obj_create(lv_screen_active());
|
||||
lv_obj_add_style(obj, &style, 0);
|
||||
lv_obj_set_size(obj, 200, 200);
|
||||
lv_obj_center(obj);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void lv_example_style_16(void)
|
||||
{
|
||||
lv_obj_t * label = lv_label_create(lv_screen_active());
|
||||
lv_obj_set_width(label, LV_PCT(80));
|
||||
lv_label_set_text(label, "LV_USE_DRAW_SW_COMPLEX_GRADIENTS is not enabled");
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
#endif /*LV_USE_DRAW_SW_COMPLEX_GRADIENTS*/
|
||||
|
||||
#endif /*LV_BUILD_EXAMPLES*/
|
||||
53
libraries/lvgl/examples/styles/lv_example_style_17.c
Normal file
53
libraries/lvgl/examples/styles/lv_example_style_17.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES
|
||||
|
||||
#if LV_USE_DRAW_SW_COMPLEX_GRADIENTS
|
||||
|
||||
/**
|
||||
* Using radial gradient as background
|
||||
*/
|
||||
void lv_example_style_17(void)
|
||||
{
|
||||
static const lv_color_t grad_colors[2] = {
|
||||
LV_COLOR_MAKE(0x9B, 0x18, 0x42),
|
||||
LV_COLOR_MAKE(0x00, 0x00, 0x00),
|
||||
};
|
||||
|
||||
int32_t width = lv_display_get_horizontal_resolution(NULL);
|
||||
int32_t height = lv_display_get_vertical_resolution(NULL);
|
||||
|
||||
static lv_style_t style;
|
||||
lv_style_init(&style);
|
||||
|
||||
/*First define a color gradient. In this example we use a purple to black color map.*/
|
||||
static lv_grad_dsc_t grad;
|
||||
|
||||
lv_gradient_init_stops(&grad, grad_colors, NULL, NULL, sizeof(grad_colors) / sizeof(lv_color_t));
|
||||
|
||||
/*Make a radial gradient with the center in the middle of the object, extending to the farthest corner*/
|
||||
lv_grad_radial_init(&grad, LV_GRAD_CENTER, LV_GRAD_CENTER, LV_GRAD_RIGHT, LV_GRAD_BOTTOM, LV_GRAD_EXTEND_PAD);
|
||||
|
||||
/*Set gradient as background*/
|
||||
lv_style_set_bg_grad(&style, &grad);
|
||||
|
||||
/*Create an object with the new style*/
|
||||
lv_obj_t * obj = lv_obj_create(lv_screen_active());
|
||||
lv_obj_add_style(obj, &style, 0);
|
||||
lv_obj_set_size(obj, width, height);
|
||||
lv_obj_center(obj);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void lv_example_style_17(void)
|
||||
{
|
||||
lv_obj_t * label = lv_label_create(lv_screen_active());
|
||||
lv_obj_set_width(label, LV_PCT(80));
|
||||
lv_label_set_text(label, "LV_USE_DRAW_SW_COMPLEX_GRADIENTS is not enabled");
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
#endif /*LV_USE_DRAW_SW_COMPLEX_GRADIENTS*/
|
||||
|
||||
#endif /*LV_BUILD_EXAMPLES*/
|
||||
99
libraries/lvgl/examples/styles/lv_example_style_18.c
Normal file
99
libraries/lvgl/examples/styles/lv_example_style_18.c
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES
|
||||
|
||||
#if LV_USE_DRAW_SW_COMPLEX_GRADIENTS
|
||||
|
||||
/**
|
||||
* Using various gradients for button background
|
||||
*/
|
||||
void lv_example_style_18(void)
|
||||
{
|
||||
static const lv_color_t grad_colors[2] = {
|
||||
LV_COLOR_MAKE(0x26, 0xa0, 0xda),
|
||||
LV_COLOR_MAKE(0x31, 0x47, 0x55),
|
||||
};
|
||||
|
||||
/*Create a linear gradient going from the top left corner to the bottom at an angle, with reflected color map*/
|
||||
static lv_style_t style_with_linear_gradient_bg;
|
||||
static lv_grad_dsc_t linear_gradient_dsc; /*NOTE: the gradient descriptor must be static or global variable!*/
|
||||
|
||||
lv_style_init(&style_with_linear_gradient_bg);
|
||||
lv_gradient_init_stops(&linear_gradient_dsc, grad_colors, NULL, NULL, sizeof(grad_colors) / sizeof(lv_color_t));
|
||||
lv_grad_linear_init(&linear_gradient_dsc, lv_pct(0), lv_pct(0), lv_pct(20), lv_pct(100), LV_GRAD_EXTEND_REFLECT);
|
||||
lv_style_set_bg_grad(&style_with_linear_gradient_bg, &linear_gradient_dsc);
|
||||
lv_style_set_bg_opa(&style_with_linear_gradient_bg, LV_OPA_COVER);
|
||||
|
||||
/*Create a radial gradient with the center in the top left 1/3rd of the object, extending to the bottom right corner, with reflected color map*/
|
||||
static lv_style_t style_with_radial_gradient_bg;
|
||||
static lv_grad_dsc_t radial_gradient_dsc; /*NOTE: the gradient descriptor must be static or global variable!*/
|
||||
|
||||
lv_style_init(&style_with_radial_gradient_bg);
|
||||
lv_gradient_init_stops(&radial_gradient_dsc, grad_colors, NULL, NULL, sizeof(grad_colors) / sizeof(lv_color_t));
|
||||
lv_grad_radial_init(&radial_gradient_dsc, lv_pct(30), lv_pct(30), lv_pct(100), lv_pct(100), LV_GRAD_EXTEND_REFLECT);
|
||||
lv_style_set_bg_grad(&style_with_radial_gradient_bg, &radial_gradient_dsc);
|
||||
lv_style_set_bg_opa(&style_with_radial_gradient_bg, LV_OPA_COVER);
|
||||
|
||||
/*Create buttons with different gradient styles*/
|
||||
|
||||
lv_obj_t * btn;
|
||||
lv_obj_t * label;
|
||||
|
||||
/*Simple horizontal gradient*/
|
||||
btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_set_style_bg_color(btn, grad_colors[0], 0);
|
||||
lv_obj_set_style_bg_grad_color(btn, grad_colors[1], 0);
|
||||
lv_obj_set_style_bg_grad_dir(btn, LV_GRAD_DIR_HOR, 0);
|
||||
lv_obj_set_size(btn, 150, 50);
|
||||
lv_obj_align(btn, LV_ALIGN_CENTER, 0, -100);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Horizontal");
|
||||
lv_obj_center(label);
|
||||
|
||||
/*Simple vertical gradient*/
|
||||
btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_set_style_bg_color(btn, grad_colors[0], 0);
|
||||
lv_obj_set_style_bg_grad_color(btn, grad_colors[1], 0);
|
||||
lv_obj_set_style_bg_grad_dir(btn, LV_GRAD_DIR_VER, 0);
|
||||
lv_obj_set_size(btn, 150, 50);
|
||||
lv_obj_align(btn, LV_ALIGN_CENTER, 0, -40);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Vertical");
|
||||
lv_obj_center(label);
|
||||
|
||||
/*Complex linear gradient*/
|
||||
btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_add_style(btn, &style_with_linear_gradient_bg, 0);
|
||||
lv_obj_set_size(btn, 150, 50);
|
||||
lv_obj_align(btn, LV_ALIGN_CENTER, 0, 20);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Linear");
|
||||
lv_obj_center(label);
|
||||
|
||||
/*Complex radial gradient*/
|
||||
btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_add_style(btn, &style_with_radial_gradient_bg, 0);
|
||||
lv_obj_set_size(btn, 150, 50);
|
||||
lv_obj_align(btn, LV_ALIGN_CENTER, 0, 80);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Radial");
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void lv_example_style_18(void)
|
||||
{
|
||||
lv_obj_t * label = lv_label_create(lv_screen_active());
|
||||
lv_obj_set_width(label, LV_PCT(80));
|
||||
lv_label_set_text(label, "LV_USE_DRAW_SW_COMPLEX_GRADIENTS is not enabled");
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
#endif /*LV_USE_DRAW_SW_COMPLEX_GRADIENTS*/
|
||||
|
||||
#endif /*LV_BUILD_EXAMPLES*/
|
||||
35
libraries/lvgl/examples/styles/lv_example_style_2.c
Normal file
35
libraries/lvgl/examples/styles/lv_example_style_2.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES
|
||||
|
||||
/**
|
||||
* Using the background style properties
|
||||
*/
|
||||
void lv_example_style_2(void)
|
||||
{
|
||||
static lv_style_t style;
|
||||
lv_style_init(&style);
|
||||
lv_style_set_radius(&style, 5);
|
||||
|
||||
/*Make a gradient*/
|
||||
lv_style_set_bg_opa(&style, LV_OPA_COVER);
|
||||
static lv_grad_dsc_t grad;
|
||||
grad.dir = LV_GRAD_DIR_VER;
|
||||
grad.stops_count = 2;
|
||||
grad.stops[0].color = lv_palette_lighten(LV_PALETTE_GREY, 1);
|
||||
grad.stops[0].opa = LV_OPA_COVER;
|
||||
grad.stops[1].color = lv_palette_main(LV_PALETTE_BLUE);
|
||||
grad.stops[1].opa = LV_OPA_COVER;
|
||||
|
||||
/*Shift the gradient to the bottom*/
|
||||
grad.stops[0].frac = 128;
|
||||
grad.stops[1].frac = 192;
|
||||
|
||||
lv_style_set_bg_grad(&style, &grad);
|
||||
|
||||
/*Create an object with the new style*/
|
||||
lv_obj_t * obj = lv_obj_create(lv_screen_active());
|
||||
lv_obj_add_style(obj, &style, 0);
|
||||
lv_obj_center(obj);
|
||||
}
|
||||
|
||||
#endif
|
||||
29
libraries/lvgl/examples/styles/lv_example_style_3.c
Normal file
29
libraries/lvgl/examples/styles/lv_example_style_3.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES
|
||||
|
||||
/**
|
||||
* Using the border style properties
|
||||
*/
|
||||
void lv_example_style_3(void)
|
||||
{
|
||||
static lv_style_t style;
|
||||
lv_style_init(&style);
|
||||
|
||||
/*Set a background color and a radius*/
|
||||
lv_style_set_radius(&style, 10);
|
||||
lv_style_set_bg_opa(&style, LV_OPA_COVER);
|
||||
lv_style_set_bg_color(&style, lv_palette_lighten(LV_PALETTE_GREY, 1));
|
||||
|
||||
/*Add border to the bottom+right*/
|
||||
lv_style_set_border_color(&style, lv_palette_main(LV_PALETTE_BLUE));
|
||||
lv_style_set_border_width(&style, 5);
|
||||
lv_style_set_border_opa(&style, LV_OPA_50);
|
||||
lv_style_set_border_side(&style, LV_BORDER_SIDE_BOTTOM | LV_BORDER_SIDE_RIGHT);
|
||||
|
||||
/*Create an object with the new style*/
|
||||
lv_obj_t * obj = lv_obj_create(lv_screen_active());
|
||||
lv_obj_add_style(obj, &style, 0);
|
||||
lv_obj_center(obj);
|
||||
}
|
||||
|
||||
#endif
|
||||
28
libraries/lvgl/examples/styles/lv_example_style_4.c
Normal file
28
libraries/lvgl/examples/styles/lv_example_style_4.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES
|
||||
|
||||
/**
|
||||
* Using the outline style properties
|
||||
*/
|
||||
void lv_example_style_4(void)
|
||||
{
|
||||
static lv_style_t style;
|
||||
lv_style_init(&style);
|
||||
|
||||
/*Set a background color and a radius*/
|
||||
lv_style_set_radius(&style, 5);
|
||||
lv_style_set_bg_opa(&style, LV_OPA_COVER);
|
||||
lv_style_set_bg_color(&style, lv_palette_lighten(LV_PALETTE_GREY, 1));
|
||||
|
||||
/*Add outline*/
|
||||
lv_style_set_outline_width(&style, 2);
|
||||
lv_style_set_outline_color(&style, lv_palette_main(LV_PALETTE_BLUE));
|
||||
lv_style_set_outline_pad(&style, 8);
|
||||
|
||||
/*Create an object with the new style*/
|
||||
lv_obj_t * obj = lv_obj_create(lv_screen_active());
|
||||
lv_obj_add_style(obj, &style, 0);
|
||||
lv_obj_center(obj);
|
||||
}
|
||||
|
||||
#endif
|
||||
27
libraries/lvgl/examples/styles/lv_example_style_5.c
Normal file
27
libraries/lvgl/examples/styles/lv_example_style_5.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES
|
||||
|
||||
/**
|
||||
* Using the Shadow style properties
|
||||
*/
|
||||
void lv_example_style_5(void)
|
||||
{
|
||||
static lv_style_t style;
|
||||
lv_style_init(&style);
|
||||
|
||||
/*Set a background color and a radius*/
|
||||
lv_style_set_radius(&style, 5);
|
||||
lv_style_set_bg_opa(&style, LV_OPA_COVER);
|
||||
lv_style_set_bg_color(&style, lv_palette_lighten(LV_PALETTE_GREY, 1));
|
||||
|
||||
/*Add a shadow*/
|
||||
lv_style_set_shadow_width(&style, 55);
|
||||
lv_style_set_shadow_color(&style, lv_palette_main(LV_PALETTE_BLUE));
|
||||
|
||||
/*Create an object with the new style*/
|
||||
lv_obj_t * obj = lv_obj_create(lv_screen_active());
|
||||
lv_obj_add_style(obj, &style, 0);
|
||||
lv_obj_center(obj);
|
||||
}
|
||||
|
||||
#endif
|
||||
33
libraries/lvgl/examples/styles/lv_example_style_6.c
Normal file
33
libraries/lvgl/examples/styles/lv_example_style_6.c
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES && LV_USE_IMAGE
|
||||
|
||||
/**
|
||||
* Using the Image style properties
|
||||
*/
|
||||
void lv_example_style_6(void)
|
||||
{
|
||||
static lv_style_t style;
|
||||
lv_style_init(&style);
|
||||
|
||||
/*Set a background color and a radius*/
|
||||
lv_style_set_radius(&style, 5);
|
||||
lv_style_set_bg_opa(&style, LV_OPA_COVER);
|
||||
lv_style_set_bg_color(&style, lv_palette_lighten(LV_PALETTE_GREY, 3));
|
||||
lv_style_set_border_width(&style, 2);
|
||||
lv_style_set_border_color(&style, lv_palette_main(LV_PALETTE_BLUE));
|
||||
|
||||
lv_style_set_image_recolor(&style, lv_palette_main(LV_PALETTE_BLUE));
|
||||
lv_style_set_image_recolor_opa(&style, LV_OPA_50);
|
||||
lv_style_set_transform_rotation(&style, 300);
|
||||
|
||||
/*Create an object with the new style*/
|
||||
lv_obj_t * obj = lv_image_create(lv_screen_active());
|
||||
lv_obj_add_style(obj, &style, 0);
|
||||
|
||||
LV_IMAGE_DECLARE(img_cogwheel_argb);
|
||||
lv_image_set_src(obj, &img_cogwheel_argb);
|
||||
|
||||
lv_obj_center(obj);
|
||||
}
|
||||
|
||||
#endif
|
||||
20
libraries/lvgl/examples/styles/lv_example_style_7.c
Normal file
20
libraries/lvgl/examples/styles/lv_example_style_7.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES && LV_USE_ARC
|
||||
|
||||
/**
|
||||
* Using the Arc style properties
|
||||
*/
|
||||
void lv_example_style_7(void)
|
||||
{
|
||||
static lv_style_t style;
|
||||
lv_style_init(&style);
|
||||
|
||||
lv_style_set_arc_color(&style, lv_palette_main(LV_PALETTE_RED));
|
||||
lv_style_set_arc_width(&style, 4);
|
||||
|
||||
/*Create an object with the new style*/
|
||||
lv_obj_t * obj = lv_arc_create(lv_screen_active());
|
||||
lv_obj_add_style(obj, &style, 0);
|
||||
lv_obj_center(obj);
|
||||
}
|
||||
#endif
|
||||
33
libraries/lvgl/examples/styles/lv_example_style_8.c
Normal file
33
libraries/lvgl/examples/styles/lv_example_style_8.c
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES && LV_USE_LABEL
|
||||
|
||||
/**
|
||||
* Using the text style properties
|
||||
*/
|
||||
void lv_example_style_8(void)
|
||||
{
|
||||
static lv_style_t style;
|
||||
lv_style_init(&style);
|
||||
|
||||
lv_style_set_radius(&style, 5);
|
||||
lv_style_set_bg_opa(&style, LV_OPA_COVER);
|
||||
lv_style_set_bg_color(&style, lv_palette_lighten(LV_PALETTE_GREY, 2));
|
||||
lv_style_set_border_width(&style, 2);
|
||||
lv_style_set_border_color(&style, lv_palette_main(LV_PALETTE_BLUE));
|
||||
lv_style_set_pad_all(&style, 10);
|
||||
|
||||
lv_style_set_text_color(&style, lv_palette_main(LV_PALETTE_BLUE));
|
||||
lv_style_set_text_letter_space(&style, 5);
|
||||
lv_style_set_text_line_space(&style, 20);
|
||||
lv_style_set_text_decor(&style, LV_TEXT_DECOR_UNDERLINE);
|
||||
|
||||
/*Create an object with the new style*/
|
||||
lv_obj_t * obj = lv_label_create(lv_screen_active());
|
||||
lv_obj_add_style(obj, &style, 0);
|
||||
lv_label_set_text(obj, "Text of\n"
|
||||
"a label");
|
||||
|
||||
lv_obj_center(obj);
|
||||
}
|
||||
|
||||
#endif
|
||||
26
libraries/lvgl/examples/styles/lv_example_style_9.c
Normal file
26
libraries/lvgl/examples/styles/lv_example_style_9.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES && LV_USE_LINE
|
||||
|
||||
/**
|
||||
* Using the line style properties
|
||||
*/
|
||||
void lv_example_style_9(void)
|
||||
{
|
||||
static lv_style_t style;
|
||||
lv_style_init(&style);
|
||||
|
||||
lv_style_set_line_color(&style, lv_palette_main(LV_PALETTE_GREY));
|
||||
lv_style_set_line_width(&style, 6);
|
||||
lv_style_set_line_rounded(&style, true);
|
||||
|
||||
/*Create an object with the new style*/
|
||||
lv_obj_t * obj = lv_line_create(lv_screen_active());
|
||||
lv_obj_add_style(obj, &style, 0);
|
||||
|
||||
static lv_point_precise_t p[] = {{10, 30}, {30, 50}, {100, 0}};
|
||||
lv_line_set_points(obj, p, 3);
|
||||
|
||||
lv_obj_center(obj);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user