refactor: minor refactoring and widget docs update
This commit is contained in:
40
examples/widgets/button/lv_example_button_1.c
Normal file
40
examples/widgets/button/lv_example_button_1.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_BTN && LV_BUILD_EXAMPLES
|
||||
|
||||
static void event_handler(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
|
||||
if(code == LV_EVENT_CLICKED) {
|
||||
LV_LOG_USER("Clicked");
|
||||
}
|
||||
else if(code == LV_EVENT_VALUE_CHANGED) {
|
||||
LV_LOG_USER("Toggled");
|
||||
}
|
||||
}
|
||||
|
||||
void lv_example_button_1(void)
|
||||
{
|
||||
lv_obj_t * label;
|
||||
|
||||
lv_obj_t * btn1 = lv_button_create(lv_screen_active());
|
||||
lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
|
||||
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -40);
|
||||
lv_obj_remove_flag(btn1, LV_OBJ_FLAG_PRESS_LOCK);
|
||||
|
||||
label = lv_label_create(btn1);
|
||||
lv_label_set_text(label, "Button");
|
||||
lv_obj_center(label);
|
||||
|
||||
lv_obj_t * btn2 = lv_button_create(lv_screen_active());
|
||||
lv_obj_add_event_cb(btn2, event_handler, LV_EVENT_ALL, NULL);
|
||||
lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 40);
|
||||
lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
|
||||
lv_obj_set_height(btn2, LV_SIZE_CONTENT);
|
||||
|
||||
label = lv_label_create(btn2);
|
||||
lv_label_set_text(label, "Toggle");
|
||||
lv_obj_center(label);
|
||||
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user