UI 的 Hello World
让我们从一个最简单的 Hello World 示例开始,通过它来理解 dxUi 的基本概念。
完整代码
import dxui from "../dxmodules/dxUi.js";
import std from "../dxmodules/dxStd.js";
import logger from "../dxmodules/dxLogger.js";
dxui.init({ orientation: 1 });
const screenMain = dxui.View.build("mainid", dxui.Utils.LAYER.MAIN);
const button = dxui.Button.build("buttonid", screenMain);
button.setPos(100, 400);
button.setSize(400, 400);
const buttonLabel = dxui.Label.build("buttonLabelid", button);
buttonLabel.text("Click me");
buttonLabel.setPos(150, 200);
button.on(dxui.Utils.EVENT.CLICK, () => {
logger.info("Button clicked");
});
dxui.loadMain(screenMain);
std.setInterval(() => {
dxui.handler();
}, 10);
运行效果

UI 结构分析
虽然这是一个最简单的示例,但它展示了 LVGL 的树状 UI 结构:
screenMain (View)
└── button (Button)
└── buttonLabel (Label)
简单来说,我们在屏幕上创建了一个按钮,并在按钮内添加了文字标签。