first commit
This commit is contained in:
61
src/main.c
Normal file
61
src/main.c
Normal file
@@ -0,0 +1,61 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include "lvgl.h"
|
||||
#include "../lib/lv_drivers/display/monitor.h"
|
||||
|
||||
#define screen_witdh 1920
|
||||
#define screen_height 480
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
// SDL initialiseren
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
printf("SDL kon niet worden geïnitialiseerd: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// LVGL initialiseren
|
||||
lv_init();
|
||||
|
||||
// SDL display driver initialiseren
|
||||
lv_disp_t *disp = lv_sdl_window_create(screen_witdh, screen_witdh);
|
||||
if (!disp) {
|
||||
printf("Kon SDL-venster niet maken\n");
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Venstertitel instellen
|
||||
lv_sdl_window_set_title(disp, "LVGL met SDL");
|
||||
|
||||
// Thema instellen (optioneel)
|
||||
lv_theme_t *th = lv_theme_default_init(disp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), LV_THEME_DEFAULT_DARK, LV_FONT_DEFAULT);
|
||||
lv_disp_set_theme(disp, th);
|
||||
|
||||
// Een label maken
|
||||
lv_obj_t *label = lv_label_create(lv_scr_act());
|
||||
lv_label_set_text(label, "Hallo, LVGL!");
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, -40);
|
||||
|
||||
// Een knop maken
|
||||
lv_obj_t *btn = lv_btn_create(lv_scr_act());
|
||||
lv_obj_align(btn, LV_ALIGN_CENTER, 0, 40);
|
||||
|
||||
// Label op de knop
|
||||
lv_obj_t *btn_label = lv_label_create(btn);
|
||||
lv_label_set_text(btn_label, "Klik mij");
|
||||
lv_obj_center(btn_label);
|
||||
|
||||
// Event loop
|
||||
while (1) {
|
||||
// LVGL taken verwerken
|
||||
lv_timer_handler();
|
||||
SDL_Delay(5);
|
||||
}
|
||||
|
||||
// Opruimen
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user