make lvgl resize.
Some checks failed
Deploy / Build (push) Failing after 3m22s

This commit is contained in:
luocai 2024-11-22 19:25:57 +08:00
parent 6df4a1bffd
commit a43929fb81
3 changed files with 23 additions and 8 deletions

View File

@ -17,9 +17,12 @@
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
#output { #output, #canvas {
margin: 0; margin: 0;
padding: 0; padding: 0;
width: 100%;
height: 100%;
background-color: burlywood;
} }
</style> </style>
</head> </head>
@ -29,12 +32,10 @@
</p> </p>
<script> <script>
var siteURL = new URL(window.location.href); 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'); var canvas = document.getElementById('canvas');
canvas.setAttribute("width", w); let rect = canvas.getBoundingClientRect();
canvas.setAttribute("height", h); canvas.setAttribute("width", rect.width);
console.log("Requested " + w + "x" + h + " px"); canvas.setAttribute("height", rect.height);
var Module = { var Module = {
print: function(text) { print: function(text) {
console.log(text); console.log(text);
@ -45,7 +46,20 @@
canvas: (function() { canvas: (function() {
return canvas; return canvas;
})(), })(),
arguments: [ siteURL.searchParams.get("w") || "800", siteURL.searchParams.get("h") || "480", siteURL.searchParams.get("example") ?? "default" ] arguments: [ String(rect.width), String(rect.height), siteURL.searchParams.get("example") ?? "default" ],
onRuntimeInitialized: function () {
// const canvas = document.getElementById('canvas');
// const observer = new ResizeObserver(entries => {
// for (let entry of entries) {
// const width = entry.contentRect.width;
// const height = entry.contentRect.height;
// Module.setCanvasSize(width, height); // 调用 Wasm 函数
// canvas.setAttribute("width", width);
// canvas.setAttribute("height", height);
// }
// });
// observer.observe(canvas);
}
}; };
window.addEventListener("click", () => window.focus()); window.addEventListener("click", () => window.focus());
</script> </script>

View File

@ -46,7 +46,7 @@ void do_loop() {
static void hal_init(void) { static void hal_init(void) {
lv_display_t *disp = lv_sdl_window_create(monitor_hor_res, monitor_ver_res); lv_display_t *disp = lv_sdl_window_create(monitor_hor_res, monitor_ver_res);
lv_sdl_window_set_resizeable(disp, true);
lv_group_t *g = lv_group_create(); lv_group_t *g = lv_group_create();
lv_group_set_default(g); lv_group_set_default(g);

View File

@ -112,6 +112,7 @@ function build_docker_images(){
} }
function lvgl(){ function lvgl(){
rm ${build_path}/LvglApplication/lvglapp.html
emcmake cmake -DSDL2_DIR=/home/amass/emsdk/upstream/emscripten/system/lib/cmake/SDL2 -S LvglApplication -B ${build_path}/LvglApplication 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 cmake --build ${build_path}/LvglApplication --target all
# python3 -m http.server -d ./build/LvglApplication # python3 -m http.server -d ./build/LvglApplication