分组页
用途
ui.themes.widgets.sections 用来排「分组标题 + 若干行」的整页内容:按实测高度装页(有无副标题行高不一),翻页条钉在底部,只有一页时不画翻页条。月读设置页就是这样排的。标题和它的第一行绑在一起,不会单独落在页尾。
行必须是构建函数:按页宽现建,不要预先创建好再塞进去。
主要参数
Sections.widget(opts) 返回 body, page(实际落到的页码,越界会被夹住):
| 字段 | 作用 |
|---|---|
width / height | 物理像素,整块内容区 |
page | 希望停留的页 |
sections | { { title = "书库", rows = { function(width) return Row.widget({...}) end } } }。title 可省略,省略则只排行 |
on_page | 翻页时回调,调用方应记下页码并重绘 |
分组标题用 caption + muted(彩色时走 Theme.chrome() 更常见的是标题色;本组件按代码用 muted/caption)。分组间隔是 space.md。
和三种风格的差异
行的分割线和行高跟 Row 走。柔和设置页因此更「无分割线、卡片感」;高对比行更高、线更粗。
示例
local Sections = require("ui.themes.widgets.sections")local Row = require("ui.themes.widgets.row")local body, page = Sections.widget({ width = w, height = h, page = self.page, sections = { { title = _("书库"), rows = { function(width) return Row.widget({ width = width, icon = "source", title = _("书籍来源"), status = _("微信读书"), chevron = true, callback = open_sources, }) end, }, }, { title = _("桌面"), rows = { function(width) return Row.widget({ width = width, title = _("顶栏问候"), toggle = greet, callback = toggle_greet, }) end, }, }, }, on_page = function(p) self.page = p self:redraw() end,})本文已加密,请输入访问密码