Refactor: CheckboxGroup and RadioGroup return ChoiceResult
They returned InputResult with an Input nobody read (nil for RadioGroup).
This commit is contained in:
4 files changed
+6
-7
No files matched your search
+2
-3
@@ -102,7 +102,7 @@ type CheckboxGroupOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CheckboxGroup shows a select-all box over items: checked, mixed or clear.
|
// 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 {
|
if len(items) == 0 {
|
||||||
panic("mujica: CheckboxGroup needs items")
|
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 = ui.Column(c).Shrink(0).Disabled(opts.Disabled || enabled == 0)
|
||||||
r.Element.Children(func() {
|
r.Element.Children(func() {
|
||||||
all := on == len(items)
|
all := on == len(items)
|
||||||
head := Checkbox(c, &all, label, CheckboxOptions{Indeterminate: on > 0 && !all})
|
head := Checkbox(c, &all, label, CheckboxOptions{Indeterminate: on > 0 && !all})
|
||||||
r.Input = head
|
|
||||||
if head.Changed() {
|
if head.Changed() {
|
||||||
// Select-all leaves disabled items alone.
|
// Select-all leaves disabled items alone.
|
||||||
target := enabledOn < enabled
|
target := enabledOn < enabled
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ mujica.CheckboxGroup(c, "Notifications", []mujica.CheckboxItem{
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
func Checkbox(c *ui.Context, value *bool, label string, opts CheckboxOptions) *ui.Element
|
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
|
||||||
```
|
```
|
||||||
|
|
||||||
## 参数
|
## 参数
|
||||||
|
|||||||
@@ -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
@@ -27,7 +27,7 @@ type RadioGroupOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RadioGroup chooses one item's Value into *value; arrows move the choice.
|
// 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 {
|
if value == nil {
|
||||||
panic("mujica: RadioGroup needs a value")
|
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)
|
k := Tokens(c)
|
||||||
d := Density(c)
|
d := Density(c)
|
||||||
var r InputResult
|
var r ChoiceResult
|
||||||
// Disabled on a wrapper blocks the bases' clicks before they choose.
|
// Disabled on a wrapper blocks the bases' clicks before they choose.
|
||||||
wrap := ui.Box(c).Shrink(0).Disabled(opts.Disabled)
|
wrap := ui.Box(c).Shrink(0).Disabled(opts.Disabled)
|
||||||
// Keys by first appearance of each value: fmt keys would merge equal-looking values.
|
// Keys by first appearance of each value: fmt keys would merge equal-looking values.
|
||||||
|
|||||||
Reference in new issue
Block a user