From dd1e9597aff6078bbca7505c53cd5871ef5d962f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Mon, 5 Oct 2026 13:36:29 -0400 Subject: [PATCH] Refactor: CheckboxGroup and RadioGroup return ChoiceResult They returned InputResult with an Input nobody read (nil for RadioGroup). --- checkbox.go | 5 ++--- docs/components/029-checkbox.md | 2 +- docs/components/030-radio-group.md | 2 +- radio_group.go | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/checkbox.go b/checkbox.go index 5a420ee..766da06 100644 --- a/checkbox.go +++ b/checkbox.go @@ -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 diff --git a/docs/components/029-checkbox.md b/docs/components/029-checkbox.md index d71bae6..6b892b7 100644 --- a/docs/components/029-checkbox.md +++ b/docs/components/029-checkbox.md @@ -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 ``` ## 参数 diff --git a/docs/components/030-radio-group.md b/docs/components/030-radio-group.md index 3f6c9b7..7b166d3 100644 --- a/docs/components/030-radio-group.md +++ b/docs/components/030-radio-group.md @@ -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` ## 参数 diff --git a/radio_group.go b/radio_group.go index 9f6b11c..d12eecd 100644 --- a/radio_group.go +++ b/radio_group.go @@ -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.