Refactor: CheckboxGroup and RadioGroup return ChoiceResult

They returned InputResult with an Input nobody read (nil for RadioGroup).
This commit is contained in:
ZacharyZhang-NY committed 2026-10-05 13:36:29 -04:00
1 parent 8880865021
commit dd1e9597af
4 files changed
+6 -7

No files matched your search

+2 -3
View File
@@ -102,7 +102,7 @@ type CheckboxGroupOptions struct {
}
// CheckboxGroup shows a select-all box over items: checked, mixed or clear.
func CheckboxGroup(c *ui.Context, label string, items []CheckboxItem, opts CheckboxGroupOptions) InputResult {
func CheckboxGroup(c *ui.Context, label string, items []CheckboxItem, opts CheckboxGroupOptions) ChoiceResult {
if len(items) == 0 {
panic("mujica: CheckboxGroup needs items")
}
@@ -122,12 +122,11 @@ func CheckboxGroup(c *ui.Context, label string, items []CheckboxItem, opts Check
}
}
}
var r InputResult
var r ChoiceResult
r.Element = ui.Column(c).Shrink(0).Disabled(opts.Disabled || enabled == 0)
r.Element.Children(func() {
all := on == len(items)
head := Checkbox(c, &all, label, CheckboxOptions{Indeterminate: on > 0 && !all})
r.Input = head
if head.Changed() {
// Select-all leaves disabled items alone.
target := enabledOn < enabled
+1 -1
View File
@@ -17,7 +17,7 @@ mujica.CheckboxGroup(c, "Notifications", []mujica.CheckboxItem{
```go
func Checkbox(c *ui.Context, value *bool, label string, opts CheckboxOptions) *ui.Element
func CheckboxGroup(c *ui.Context, label string, items []CheckboxItem, opts CheckboxGroupOptions) InputResult
func CheckboxGroup(c *ui.Context, label string, items []CheckboxItem, opts CheckboxGroupOptions) ChoiceResult
```
## 参数
+1 -1
View File
@@ -13,7 +13,7 @@ if mujica.RadioGroup(c, &size, items, mujica.RadioGroupOptions{Label: "Size"}).C
}
```
签名:`func RadioGroup[T comparable](c *ui.Context, value *T, items []RadioItem[T], opts RadioGroupOptions) InputResult`
签名:`func RadioGroup[T comparable](c *ui.Context, value *T, items []RadioItem[T], opts RadioGroupOptions) ChoiceResult`
## 参数
+2 -2
View File
@@ -27,7 +27,7 @@ type RadioGroupOptions struct {
}
// RadioGroup chooses one item's Value into *value; arrows move the choice.
func RadioGroup[T comparable](c *ui.Context, value *T, items []RadioItem[T], opts RadioGroupOptions) InputResult {
func RadioGroup[T comparable](c *ui.Context, value *T, items []RadioItem[T], opts RadioGroupOptions) ChoiceResult {
if value == nil {
panic("mujica: RadioGroup needs a value")
}
@@ -43,7 +43,7 @@ func RadioGroup[T comparable](c *ui.Context, value *T, items []RadioItem[T], opt
}
k := Tokens(c)
d := Density(c)
var r InputResult
var r ChoiceResult
// Disabled on a wrapper blocks the bases' clicks before they choose.
wrap := ui.Box(c).Shrink(0).Disabled(opts.Disabled)
// Keys by first appearance of each value: fmt keys would merge equal-looking values.