text/plain
•
3.03 KB
•
88 lines
#include "moon.h"
#include "lvgl.h"
uint8_t button_state;
static lv_obj_t *title_label;
static lv_obj_t *status_label;
static lv_obj_t *test_btn;
static lv_obj_t *spinner;
static lv_obj_t *progress_bar;
// Wrapper for lv_bar_set_value to work with animations
static void bar_anim_cb(void *obj, int32_t value) {
lv_bar_set_value(obj, value, LV_ANIM_OFF);
}
static void btn_event_cb(lv_event_t *e) {
lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_CLICKED) {
static int click_count = 0;
click_count++;
lv_label_set_text_fmt(status_label, "Clicks: %d", click_count);
// Animate progress bar on click
int32_t new_val = (click_count * 10) % 110;
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, progress_bar);
lv_anim_set_values(&a, lv_bar_get_value(progress_bar), new_val);
lv_anim_set_duration(&a, 300);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)bar_anim_cb);
lv_anim_start(&a);
}
}
void setup(void) {
// Create title label at top
title_label = lv_label_create(lv_screen_active());
lv_label_set_text(title_label, "The Onigiri");
lv_obj_set_style_text_font(title_label, &lv_font_montserrat_14, 0);
lv_obj_align(title_label, LV_ALIGN_TOP_MID, 0, 8);
// Create a small spinner in top-left corner
spinner = lv_spinner_create(lv_screen_active());
lv_obj_set_size(spinner, 20, 20);
lv_obj_align(spinner, LV_ALIGN_TOP_LEFT, 4, 4);
lv_spinner_set_anim_params(spinner, 1000, 200); // 1s rotation, 200 arc length
// Create status label (with CJK test)
status_label = lv_label_create(lv_screen_active());
lv_label_set_text(status_label, "Ready 音楽");
lv_obj_set_style_text_font(status_label, &lv_font_source_han_sans_sc_14_cjk, 0);
lv_obj_align(status_label, LV_ALIGN_CENTER, 0, -15);
// Create animated progress bar
progress_bar = lv_bar_create(lv_screen_active());
lv_obj_set_size(progress_bar, 120, 8);
lv_obj_align(progress_bar, LV_ALIGN_CENTER, 0, 10);
lv_bar_set_value(progress_bar, 30, LV_ANIM_OFF);
// Create test button at bottom
test_btn = lv_button_create(lv_screen_active());
lv_obj_align(test_btn, LV_ALIGN_BOTTOM_MID, 0, -8);
lv_obj_add_event_cb(test_btn, btn_event_cb, LV_EVENT_CLICKED, NULL);
lv_obj_set_size(test_btn, 80, 30);
lv_obj_t *btn_label = lv_label_create(test_btn);
lv_label_set_text(btn_label, "Test");
lv_obj_center(btn_label);
}
void loop(void) {
// Button input handling - simulate LVGL encoder/button events
static uint8_t prev_state = 0;
if ((button_state & BUTTON_STATE_OK) && !(prev_state & BUTTON_STATE_OK)) {
// OK pressed - simulate click on focused object
lv_obj_t *focused = lv_group_get_focused(lv_group_get_default());
if (focused) {
lv_obj_send_event(focused, LV_EVENT_CLICKED, NULL);
} else {
// If no group, just click the button
lv_obj_send_event(test_btn, LV_EVENT_CLICKED, NULL);
}
}
prev_state = button_state;
}