|
|
@@ -16,7 +16,6 @@
|
|
|
]]
|
|
|
|
|
|
local function ui_main()
|
|
|
-
|
|
|
-- 显示触摸初始化
|
|
|
hw_font_drv.init()
|
|
|
|
|
|
@@ -28,40 +27,45 @@ local function ui_main()
|
|
|
|
|
|
-- 启用横向滚动,将两页内容并排布置
|
|
|
local page_w, page_h = lcd.getSize()
|
|
|
- local totalW = page_w * 2
|
|
|
+ local totalW = math.floor(page_w * 2)
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-- 创建横向滑动窗口
|
|
|
- win:enable_scroll({
|
|
|
- direction = "horizontal",
|
|
|
- content_width = totalW,
|
|
|
- threshold = 8,
|
|
|
- page_width = page_w
|
|
|
+ win:enable_scroll({
|
|
|
+ direction = "horizontal",
|
|
|
+ content_width = totalW,
|
|
|
+ threshold = 8,
|
|
|
+ page_width = page_w
|
|
|
})
|
|
|
|
|
|
-- 创建网格按钮函数
|
|
|
local function makeGrid(offset_x, label_prefix)
|
|
|
local cols, rows = 3, 4
|
|
|
local bw, bh = 200, 80
|
|
|
- local mx, my = (page_w - cols * bw - (cols-1) * 20) / 2 + offset_x, 80
|
|
|
+ local mx, my = math.floor((page_w - cols * bw - (cols - 1) * 20) / 2 + offset_x), 80
|
|
|
local gapx, gapy = 20, 20
|
|
|
local n = 1
|
|
|
-
|
|
|
+
|
|
|
-- 添加页面标题
|
|
|
local page_title = ui.label({
|
|
|
- x = mx, y = my - 50,
|
|
|
+ x = mx,
|
|
|
+ y = my - 50,
|
|
|
text = "页面 " .. label_prefix,
|
|
|
color = ui.COLOR_BLACK,
|
|
|
size = 22
|
|
|
})
|
|
|
win:add(page_title)
|
|
|
-
|
|
|
+
|
|
|
for r = 0, rows - 1 do
|
|
|
for c = 0, cols - 1 do
|
|
|
local x = mx + c * (bw + gapx)
|
|
|
local y = my + r * (bh + gapy)
|
|
|
- local btn = ui.button({
|
|
|
- x = x, y = y,
|
|
|
- w = bw, h = bh,
|
|
|
+ local btn = ui.button({
|
|
|
+ x = x,
|
|
|
+ y = y,
|
|
|
+ w = bw,
|
|
|
+ h = bh,
|
|
|
text = string.format("%s-按钮%d", label_prefix, n),
|
|
|
size = 16
|
|
|
})
|
|
|
@@ -73,7 +77,8 @@ local function ui_main()
|
|
|
|
|
|
-- 创建总标题
|
|
|
local title = ui.label({
|
|
|
- x = 250, y = 30,
|
|
|
+ x = 250,
|
|
|
+ y = 30,
|
|
|
text = "横向滑动页面演示",
|
|
|
color = ui.COLOR_BLACK,
|
|
|
size = 24
|
|
|
@@ -81,13 +86,14 @@ local function ui_main()
|
|
|
win:add(title)
|
|
|
|
|
|
-- 创建左页和右页内容
|
|
|
- makeGrid(0, "一") -- 第一页
|
|
|
- makeGrid(page_w, "二") -- 第二页
|
|
|
+ makeGrid(0, "一") -- 第一页
|
|
|
+ makeGrid(page_w, "二") -- 第二页
|
|
|
|
|
|
-- 添加提示标签
|
|
|
local hint = ui.label({
|
|
|
- x = 600, y = 50,
|
|
|
- text = "← 左右滑动切换页面 →",
|
|
|
+ x = 600,
|
|
|
+ y = 50,
|
|
|
+ text = "左右滑动切换页面",
|
|
|
color = ui.COLOR_GRAY,
|
|
|
size = 16
|
|
|
})
|
|
|
@@ -95,12 +101,6 @@ local function ui_main()
|
|
|
|
|
|
-- 注册窗口到UI系统
|
|
|
ui.add(win)
|
|
|
-
|
|
|
- -- 启动exeasyui刷新主循环
|
|
|
- while true do
|
|
|
- ui.refresh()
|
|
|
- sys.wait(30)
|
|
|
- end
|
|
|
end
|
|
|
|
|
|
sys.taskInit(ui_main)
|