Refactor: results expose Element as a named field

Every component result type now names its element Element instead of
embedding *ui.Element. The eleven element-plus-changed results
(AccordionView, CarouselView, CollapsibleView, ImageViewerView,
PaginationResult, StepsResult, SidebarResult, TabsResult, RatingParts,
FileDropZoneParts, TransferParts) fold into ChoiceResult.

Fixes four Gallery demos where .Width(...).Changed() read the element's
flag instead of the component's: Accordion, MultiSelect, Cascader,
TreeSelect. TestDataAccordionDemoLogsChange covers the Accordion.
This commit is contained in:
ZacharyZhang-NY committed 2026-10-05 13:35:53 -04:00
1 parent 078dcab8b4
commit 8880865021
73 files changed
+163 -245

No files matched your search

+1 -1
View File
@@ -29,7 +29,7 @@ mujica.AppShell(c, &collapsed, mujica.AppShellOptions{
| `SidebarWidth` | `float32` | 240 | 展开时侧栏宽度(DIP);负数 panic。 |
| `ContentScroll` | `*ui.ScrollState` | nil | 保存主内容滚动位置;nil 时按位置保留。 |
返回 `AppShellResult`,内嵌 `*ui.Element`。
返回 `AppShellResult`,`Element` 字段是组件元素。
## 状态
+2 -2
View File
@@ -11,7 +11,7 @@ split := mujica.SplitPaneState{Size: 160}
mujica.SplitPane(c, &split, mujica.SplitPaneOptions{MinFirst: 120, Collapsible: mujica.SplitPaneFirst},
func() { ui.Text(c, "Files") },
func() { ui.Text(c, "Editor") },
).Fill()
).Element.Fill()
```
签名:`func SplitPane(c *ui.Context, state *SplitPaneState, opts SplitPaneOptions, first, second func()) SplitPaneResult`
@@ -33,7 +33,7 @@ mujica.SplitPane(c, &split, mujica.SplitPaneOptions{MinFirst: 120, Collapsible:
| `MinFirst`, `MinSecond` | `float32` | 10 单位(默认 40 DIP) | 两栏最小尺寸;负数 panic。 |
| `Collapsible` | `SplitPaneSide` | `SplitPaneNeither` | 可折叠的栏:`SplitPaneFirst` 或 `SplitPaneSecond`。 |
返回 `SplitPaneResult`,内嵌 `*ui.Element`。
返回 `SplitPaneResult`,`Element` 字段是组件元素。
## 状态
+1 -1
View File
@@ -15,7 +15,7 @@ if r.Submitted() {
签名:`func TextInput(c *ui.Context, value *string, opts TextInputOptions) InputResult`
`InputResult` 内嵌外层 `*ui.Element`,`Input` 字段是内部编辑元素,`Changed()`、`Submitted()` 报告事件。
`InputResult` 的 `Element` 字段是外层元素,`Input` 字段是内部编辑元素,`Changed()`、`Submitted()` 报告事件。
## 参数
+1 -1
View File
@@ -35,7 +35,7 @@ ui.Render(view, 400, 300, 1)
## 事件
`RatingParts.Changed()` 用户设置了新值;同值点击不触发。
`ChoiceResult.Changed()` 用户设置了新值;同值点击不触发。
## 键盘操作
+1 -1
View File
@@ -36,7 +36,7 @@ ui.Render(view, 400, 300, 1)
## 事件
`FileDropZoneParts.Changed()` 添加或移除了文件。被拒绝的条目只显示在组件内,可单独关闭。
`ChoiceResult.Changed()` 添加或移除了文件。被拒绝的条目只显示在组件内,可单独关闭。
## 键盘操作
+1 -1
View File
@@ -34,7 +34,7 @@ ui.Render(view, 400, 300, 1)
## 事件
`TransferParts.Changed()` 有条目移动。
`ChoiceResult.Changed()` 有条目移动。
## 键盘操作
+1 -1
View File
@@ -19,7 +19,7 @@ ui.Render(view, 400, 300, 1)
## 参数
`func Calendar(c *ui.Context, value *Date, opts CalendarOptions) DateTimeResult`,返回值嵌入 `*ui.Element`。
`func Calendar(c *ui.Context, value *Date, opts CalendarOptions) DateTimeResult`,返回值的 `Element` 字段是组件元素。
| 字段 | 类型 | 默认值 | 含义 |
| --- | --- | --- | --- |
+1 -1
View File
@@ -21,7 +21,7 @@ ui.Render(view, 400, 300, 1)
## 参数
`func DatePicker(c *ui.Context, value *Date, opts DatePickerOptions) DateTimeResult`,返回值嵌入 `*ui.Element`。
`func DatePicker(c *ui.Context, value *Date, opts DatePickerOptions) DateTimeResult`,返回值的 `Element` 字段是组件元素。
| 字段 | 类型 | 默认值 | 含义 |
| --- | --- | --- | --- |
+1 -1
View File
@@ -20,7 +20,7 @@ ui.Render(view, 400, 300, 1)
## 参数
`func DateRangePicker(c *ui.Context, value *DateRange, opts DateRangePickerOptions) DateTimeResult`,返回值嵌入 `*ui.Element`。
`func DateRangePicker(c *ui.Context, value *DateRange, opts DateRangePickerOptions) DateTimeResult`,返回值的 `Element` 字段是组件元素。
| 字段 | 类型 | 默认值 | 含义 |
| --- | --- | --- | --- |
+1 -1
View File
@@ -20,7 +20,7 @@ ui.Render(view, 400, 300, 1)
## 参数
`func TimePicker(c *ui.Context, value *TimeOfDay, opts TimePickerOptions) DateTimeResult`,返回值嵌入 `*ui.Element`。
`func TimePicker(c *ui.Context, value *TimeOfDay, opts TimePickerOptions) DateTimeResult`,返回值的 `Element` 字段是组件元素。
| 字段 | 类型 | 默认值 | 含义 |
| --- | --- | --- | --- |
+1 -1
View File
@@ -20,7 +20,7 @@ ui.Render(view, 400, 300, 1)
## 参数
`func TimeRangePicker(c *ui.Context, value *TimeRange, opts TimeRangePickerOptions) DateTimeResult`,返回值嵌入 `*ui.Element`。
`func TimeRangePicker(c *ui.Context, value *TimeRange, opts TimeRangePickerOptions) DateTimeResult`,返回值的 `Element` 字段是组件元素。
| 字段 | 类型 | 默认值 | 含义 |
| --- | --- | --- | --- |
+1 -1
View File
@@ -24,7 +24,7 @@ ui.Render(view, 400, 300, 1)
## 参数
`func DateTimePicker(c *ui.Context, value *time.Time, opts DateTimePickerOptions) DateTimeResult`,返回值嵌入 `*ui.Element`。
`func DateTimePicker(c *ui.Context, value *time.Time, opts DateTimePickerOptions) DateTimeResult`,返回值的 `Element` 字段是组件元素。
| 字段 | 类型 | 默认值 | 含义 |
| --- | --- | --- | --- |
+1 -1
View File
@@ -20,7 +20,7 @@ ui.Render(view, 400, 300, 1)
## 参数
`func MonthPicker(c *ui.Context, value *YearMonth, opts MonthPickerOptions) DateTimeResult`,返回值嵌入 `*ui.Element`。
`func MonthPicker(c *ui.Context, value *YearMonth, opts MonthPickerOptions) DateTimeResult`,返回值的 `Element` 字段是组件元素。
| 字段 | 类型 | 默认值 | 含义 |
| --- | --- | --- | --- |
+1 -1
View File
@@ -20,7 +20,7 @@ ui.Render(view, 400, 300, 1)
## 参数
`func YearPicker(c *ui.Context, value *int, opts YearPickerOptions) DateTimeResult`,返回值嵌入 `*ui.Element`。
`func YearPicker(c *ui.Context, value *int, opts YearPickerOptions) DateTimeResult`,返回值的 `Element` 字段是组件元素。
| 字段 | 类型 | 默认值 | 含义 |
| --- | --- | --- | --- |
+2 -2
View File
@@ -14,7 +14,7 @@ mujica.Tabs(c, &tab, []mujica.Tab{
}, mujica.TabsOptions{Label: "Settings"})
```
签名:`func Tabs(c *ui.Context, selected *int, tabs []Tab, opts TabsOptions) TabsResult`
签名:`func Tabs(c *ui.Context, selected *int, tabs []Tab, opts TabsOptions) ChoiceResult`
## 参数
@@ -36,7 +36,7 @@ mujica.Tabs(c, &tab, []mujica.Tab{
| `Vertical` | `bool` | false | 标签竖排在左侧,面板在右侧。 |
| `Label` | `string` | "" | 标签列表的无障碍名称。 |
返回 `TabsResult`,内嵌包含标签与面板的 `*ui.Element`。
返回 `ChoiceResult`,`Element` 字段是包含标签与面板的元素。
## 状态
+1 -1
View File
@@ -33,7 +33,7 @@ if i, ok := mujica.Breadcrumb(c, path, mujica.BreadcrumbOptions{}).Chosen(); ok
| `MaxItemWidth` | `float32` | 0(即 160 DIP) | 单项文字最大宽度,超出以省略号截断。 |
| `Label` | `string` | 内置“路径导航” | 整组的无障碍名称。 |
返回 `BreadcrumbResult`,内嵌 `*ui.Element`。
返回 `BreadcrumbResult`,`Element` 字段是组件元素。
## 状态
+2 -2
View File
@@ -12,7 +12,7 @@ if mujica.Pagination(c, &page, &size, mujica.PaginationOptions{Total: 420, PageS
}
```
签名:`func Pagination(c *ui.Context, page, pageSize *int, opts PaginationOptions) PaginationResult`
签名:`func Pagination(c *ui.Context, page, pageSize *int, opts PaginationOptions) ChoiceResult`
## 参数
@@ -28,7 +28,7 @@ if mujica.Pagination(c, &page, &size, mujica.PaginationOptions{Total: 420, PageS
| `Siblings` | `int` | 0(即 1) | 当前页两侧显示的页码数;为负 panic。 |
| `Disabled` | `bool` | false | 整体禁用。 |
返回 `PaginationResult`,内嵌 `*ui.Element`。
返回 `ChoiceResult`,`Element` 字段是组件元素。
## 状态
+2 -2
View File
@@ -14,7 +14,7 @@ mujica.Steps(c, &current, []mujica.Step{
}, mujica.StepsOptions{Label: "Sign-up"})
```
签名:`func Steps(c *ui.Context, current *int, steps []Step, opts StepsOptions) StepsResult`
签名:`func Steps(c *ui.Context, current *int, steps []Step, opts StepsOptions) ChoiceResult`
## 参数
@@ -36,7 +36,7 @@ mujica.Steps(c, &current, []mujica.Step{
| `Vertical` | `bool` | false | 纵向排列,连接线在标记下方。 |
| `Label` | `string` | "" | 整组的无障碍名称。 |
返回 `StepsResult`,内嵌 `*ui.Element`。
返回 `ChoiceResult`,`Element` 字段是组件元素。
## 状态
+2 -2
View File
@@ -15,7 +15,7 @@ mujica.Sidebar(c, &selected, []mujica.SidebarSection{
}, mujica.SidebarOptions{})
```
签名:`func Sidebar(c *ui.Context, selected *string, sections []SidebarSection, opts SidebarOptions) SidebarResult`
签名:`func Sidebar(c *ui.Context, selected *string, sections []SidebarSection, opts SidebarOptions) ChoiceResult`
## 参数
@@ -45,7 +45,7 @@ mujica.Sidebar(c, &selected, []mujica.SidebarSection{
| `Compact` | `bool` | false | 图标栏:隐藏文字与组标题,组之间以旧金细线分隔,名称作为悬停提示。 |
| `Width` | `float32` | 0(240,紧凑时 56) | 宽度,DIP。高度填满父容器。 |
返回 `SidebarResult`,内嵌 `*ui.Element`。展开折叠状态由组件保存。
返回 `ChoiceResult`,`Element` 字段是组件元素。展开折叠状态由组件保存。
## 状态
+1 -1
View File
@@ -45,7 +45,7 @@ if id, ok := res.Chosen(); ok && id == "wrap" {
| --- | --- | --- | --- |
| `Label` | `string` | 内置“菜单栏” | 菜单栏的无障碍名称。 |
返回 `MenubarResult`,内嵌菜单栏 `*ui.Element`。
返回 `MenubarResult`,`Element` 字段是菜单栏元素。
## 状态
+2 -2
View File
@@ -15,7 +15,7 @@ view := func(c *ui.Context) {
Key: func(i int) string { return names[i] },
Label: func(i int) string { return names[i] },
}, func(i int) { ui.Text(c, names[i]) })
v.Size(240, 200)
v.Element.Size(240, 200)
if v.Changed() {
key, _ := state.Selected()
fmt.Println("chose", key)
@@ -26,7 +26,7 @@ ui.Render(view, 400, 300, 1)
## 参数
`func List[K comparable](c *ui.Context, s *ListState[K], n int, opts ListOptions[K], item func(i int)) ListView`。`ListView` 嵌入 `*ui.Element`;`ListState` 由调用方持有,零值表示未选择。`state.Selected()` 返回所选键,多选时 `state.Selection` 保存全部键;`state.ScrollTo(i)` 滚动到第 i 项。
`func List[K comparable](c *ui.Context, s *ListState[K], n int, opts ListOptions[K], item func(i int)) ListView`。`ListView` 的 `Element` 字段是列表元素;`ListState` 由调用方持有,零值表示未选择。`state.Selected()` 返回所选键,多选时 `state.Selection` 保存全部键;`state.ScrollTo(i)` 滚动到第 i 项。
| 字段 | 类型 | 默认值 | 含义 |
| --- | --- | --- | --- |
+1 -1
View File
@@ -27,7 +27,7 @@ opts := mujica.DataTableOptions[relic, int]{
}
view := func(c *ui.Context) {
mujica.Use(c, mujica.Settings{})
mujica.DataTable(c, &state, rows, opts).Size(360, 240)
mujica.DataTable(c, &state, rows, opts).Element.Size(360, 240)
}
ui.Render(view, 400, 300, 1)
```
+1 -1
View File
@@ -15,7 +15,7 @@ view := func(c *ui.Context) {
Roots: []string{"Nave", "Sacristy"},
Children: func(n string) []string { return kids[n] },
Label: func(n string) string { return n },
}).Size(280, 240)
}).Element.Size(280, 240)
}
ui.Render(view, 400, 300, 1)
```
+1 -1
View File
@@ -22,7 +22,7 @@ view := func(c *ui.Context) {
{ID: "size", Title: "Size", Width: 80, Align: ui.End,
Cell: func(n string) { ui.Text(c, strconv.Itoa(size[n])) }},
},
}).Size(360, 240)
}).Element.Size(360, 240)
}
ui.Render(view, 400, 300, 1)
```
+2 -2
View File
@@ -20,7 +20,7 @@ ui.Render(view, 400, 300, 1)
## 参数
`func Accordion(c *ui.Context, open *[]string, items []AccordionItem, opts AccordionOptions) AccordionView`。`*open` 是展开区段的 ID 列表;`AccordionItem` 字段:`ID`(必填、唯一)、`Title`、`Content`(必填)、`Disabled`。
`func Accordion(c *ui.Context, open *[]string, items []AccordionItem, opts AccordionOptions) ChoiceResult`。`*open` 是展开区段的 ID 列表;`AccordionItem` 字段:`ID`(必填、唯一)、`Title`、`Content`(必填)、`Disabled`。
| 字段 | 类型 | 默认值 | 含义 |
| --- | --- | --- | --- |
@@ -33,7 +33,7 @@ ui.Render(view, 400, 300, 1)
## 事件
`AccordionView.Changed()`:某区段因用户操作而展开或关闭,`*open` 已更新。外部直接修改 `*open` 不触发事件。
`ChoiceResult.Changed()`:某区段因用户操作而展开或关闭,`*open` 已更新。外部直接修改 `*open` 不触发事件。
## 键盘操作
+2 -2
View File
@@ -19,7 +19,7 @@ ui.Render(view, 400, 300, 1)
## 参数
`func Collapsible(c *ui.Context, open *bool, opts CollapsibleOptions, content func()) CollapsibleView`。
`func Collapsible(c *ui.Context, open *bool, opts CollapsibleOptions, content func()) ChoiceResult`。
| 字段 | 类型 | 默认值 | 含义 |
| --- | --- | --- | --- |
@@ -33,7 +33,7 @@ ui.Render(view, 400, 300, 1)
## 事件
`CollapsibleView.Changed()`:用户点击或按键切换了展开状态。
`ChoiceResult.Changed()`:用户点击或按键切换了展开状态。
## 键盘操作
+2 -2
View File
@@ -18,7 +18,7 @@ ui.Render(view, 400, 300, 1)
## 参数
`func ImageViewer(c *ui.Context, open *bool, index *int, images []ViewerImage) ImageViewerView`。`ViewerImage` 字段:`Source`(`*ui.Bitmap` 或 `*ui.SVG`,必填)、`Alt`(说明文字与无障碍名称)。关闭时返回的 `Element` 为 nil。
`func ImageViewer(c *ui.Context, open *bool, index *int, images []ViewerImage) ChoiceResult`。`ViewerImage` 字段:`Source`(`*ui.Bitmap` 或 `*ui.SVG`,必填)、`Alt`(说明文字与无障碍名称)。关闭时返回的 `Element` 为 nil。
| 字段 | 类型 | 默认值 | 含义 |
| --- | --- | --- | --- |
@@ -32,7 +32,7 @@ ui.Render(view, 400, 300, 1)
## 事件
`ImageViewerView.Changed()`:切换了图片,`*index` 已更新。关闭通过 `*open` 变为 false 观察。
`ChoiceResult.Changed()`:切换了图片,`*index` 已更新。关闭通过 `*open` 变为 false 观察。
## 键盘操作
+3 -3
View File
@@ -12,14 +12,14 @@ view := func(c *ui.Context) {
mujica.Use(c, mujica.Settings{})
mujica.Carousel(c, &index, 3, mujica.CarouselOptions{Label: "Windows", Autoplay: true}, func(i int) {
ui.Text(c, fmt.Sprintf("Rose window %d", i+1)).Padding(24)
}).Size(360, 220)
}).Element.Size(360, 220)
}
ui.Render(view, 400, 300, 1)
```
## 参数
`func Carousel(c *ui.Context, index *int, n int, opts CarouselOptions, slide func(i int)) CarouselView`。
`func Carousel(c *ui.Context, index *int, n int, opts CarouselOptions, slide func(i int)) ChoiceResult`。
| 字段 | 类型 | 默认值 | 含义 |
| --- | --- | --- | --- |
@@ -34,7 +34,7 @@ ui.Render(view, 400, 300, 1)
## 事件
`CarouselView.Changed()`:当前项变化,`*index` 已更新;同时向读屏软件播报“第 N 项,共 M 项”。
`ChoiceResult.Changed()`:当前项变化,`*index` 已更新;同时向读屏软件播报“第 N 项,共 M 项”。
## 键盘操作