This commit is contained in:
parent
d37c1a2d20
commit
47cd37a415
4
.vscode/c_cpp_properties.json
vendored
4
.vscode/c_cpp_properties.json
vendored
@ -7,7 +7,9 @@
|
||||
"${workspaceFolder}/build/_deps/kylin-src/Universal",
|
||||
"/opt/Libraries/boost_1_86_0/include",
|
||||
"/opt/Libraries/wt-4.11.1/include",
|
||||
"/opt/Libraries/ZLMediaKit/include"
|
||||
"/opt/Libraries/ZLMediaKit/include",
|
||||
"build/LvglApplication",
|
||||
"/home/amass/emsdk/upstream/emscripten/system/include"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
|
44
LvglApplication/CMakeLists.txt
Normal file
44
LvglApplication/CMakeLists.txt
Normal file
@ -0,0 +1,44 @@
|
||||
cmake_minimum_required(VERSION 3.17)
|
||||
|
||||
project(LvglApplication)
|
||||
|
||||
find_package(SDL2 REQUIRED)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -s USE_SDL=2")
|
||||
|
||||
# 使用这个可以帮助查看如何使用和集成wasm
|
||||
set(CMAKE_EXECUTABLE_SUFFIX ".html")
|
||||
|
||||
add_executable(lvglapp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
target_link_options(lvglapp
|
||||
PRIVATE --shell-file=${CMAKE_CURRENT_SOURCE_DIR}/lvgl_shell.html
|
||||
)
|
||||
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
lvgl
|
||||
GIT_REPOSITORY https://github.com/lvgl/lvgl.git
|
||||
GIT_TAG v9.2.2
|
||||
SOURCE_DIR lvgl
|
||||
)
|
||||
set(LV_CONF_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lv_conf.h)
|
||||
set(LV_CONF_BUILD_DISABLE_EXAMPLES ON)
|
||||
# set(LV_CONF_BUILD_DISABLE_DEMOS ON)
|
||||
FetchContent_MakeAvailable(lvgl)
|
||||
|
||||
target_include_directories(lvglapp
|
||||
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
# sudo apt-get install libsdl2-dev
|
||||
target_link_libraries(lvglapp
|
||||
PRIVATE lvgl::demos
|
||||
PRIVATE lvgl::lvgl
|
||||
PRIVATE lvgl::thorvg
|
||||
PRIVATE embind
|
||||
PRIVATE SDL2
|
||||
)
|
1261
LvglApplication/lv_conf.h
Normal file
1261
LvglApplication/lv_conf.h
Normal file
File diff suppressed because it is too large
Load Diff
54
LvglApplication/lvgl_shell.html
Normal file
54
LvglApplication/lvgl_shell.html
Normal file
@ -0,0 +1,54 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no'/>
|
||||
<style type="text/css">
|
||||
html, body {
|
||||
margin: 0;
|
||||
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-width: 100%;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
#output {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p id="output">
|
||||
<canvas id="canvas"></canvas>
|
||||
</p>
|
||||
<script>
|
||||
var siteURL = new URL(window.location.href);
|
||||
var w = siteURL.searchParams.get("w") || "800";
|
||||
var h = siteURL.searchParams.get("h") || "480";
|
||||
var canvas = document.getElementById('canvas');
|
||||
canvas.setAttribute("width", w);
|
||||
canvas.setAttribute("height", h);
|
||||
console.log("Requested " + w + "x" + h + " px");
|
||||
var Module = {
|
||||
print: function(text) {
|
||||
console.log(text);
|
||||
},
|
||||
printErr: function(text) {
|
||||
console.error(text);
|
||||
},
|
||||
canvas: (function() {
|
||||
return canvas;
|
||||
})(),
|
||||
arguments: [ siteURL.searchParams.get("w") || "800", siteURL.searchParams.get("h") || "480", siteURL.searchParams.get("example") ?? "default" ]
|
||||
};
|
||||
window.addEventListener("click", () => window.focus());
|
||||
</script>
|
||||
{{{ SCRIPT }}}
|
||||
</body>
|
||||
</html>
|
65
LvglApplication/main.cpp
Normal file
65
LvglApplication/main.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include <emscripten.h>
|
||||
#include <emscripten/bind.h>
|
||||
#include <iostream>
|
||||
#include <lvgl/lvgl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace emscripten;
|
||||
|
||||
void setCanvasSize(int width, int height) {
|
||||
std::cout << "canvas size: " << width << "*" << height << std::endl;
|
||||
}
|
||||
|
||||
EMSCRIPTEN_BINDINGS(lvglapp) {
|
||||
function("setCanvasSize", &setCanvasSize);
|
||||
}
|
||||
|
||||
int monitor_hor_res, monitor_ver_res;
|
||||
static void hal_init(void);
|
||||
|
||||
extern "C" {
|
||||
void lv_demo_widgets(void);
|
||||
void do_loop();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
monitor_hor_res = atoi(argv[1]);
|
||||
monitor_ver_res = atoi(argv[2]);
|
||||
printf("Starting with screen resolution of %dx%d px\n", monitor_hor_res, monitor_ver_res);
|
||||
|
||||
lv_init();
|
||||
hal_init();
|
||||
|
||||
lv_demo_widgets();
|
||||
|
||||
emscripten_set_main_loop(do_loop, -1, true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void do_loop() {
|
||||
/* Periodically call the lv_task handler.
|
||||
* It could be done in a timer interrupt or an OS task too.*/
|
||||
lv_task_handler();
|
||||
}
|
||||
|
||||
static void hal_init(void) {
|
||||
lv_display_t *disp = lv_sdl_window_create(monitor_hor_res, monitor_ver_res);
|
||||
|
||||
lv_group_t *g = lv_group_create();
|
||||
lv_group_set_default(g);
|
||||
|
||||
lv_sdl_mouse_create();
|
||||
lv_sdl_mousewheel_create();
|
||||
lv_sdl_keyboard_create();
|
||||
|
||||
lv_indev_t *mouse = lv_sdl_mouse_create();
|
||||
lv_indev_set_group(mouse, lv_group_get_default());
|
||||
|
||||
lv_indev_t *mousewheel = lv_sdl_mousewheel_create();
|
||||
lv_indev_set_group(mousewheel, lv_group_get_default());
|
||||
|
||||
lv_indev_t *keyboard = lv_sdl_keyboard_create();
|
||||
lv_indev_set_group(keyboard, lv_group_get_default());
|
||||
}
|
@ -111,6 +111,12 @@ function build_docker_images(){
|
||||
fi
|
||||
}
|
||||
|
||||
function lvgl(){
|
||||
emcmake cmake -DSDL2_DIR=/home/amass/emsdk/upstream/emscripten/system/lib/cmake/SDL2 -S LvglApplication -B ${build_path}/LvglApplication
|
||||
cmake --build ${build_path}/LvglApplication --target all
|
||||
# python3 -m http.server -d ./build/LvglApplication
|
||||
}
|
||||
|
||||
|
||||
function main() {
|
||||
local cmd=$1
|
||||
@ -128,6 +134,9 @@ function main() {
|
||||
init)
|
||||
init
|
||||
;;
|
||||
lvgl)
|
||||
lvgl
|
||||
;;
|
||||
*)
|
||||
build
|
||||
;;
|
||||
|
Loading…
Reference in New Issue
Block a user