Refactor: a disabled wrapper alone blocks choice bases
TestBasesBlockedByDisabledWrapper focuses CheckboxBase, RadioBase, SwitchBase and ToggleBase, flips their wrapper to Disabled and presses Space: none changes its value, and each does without the flip. So choiceTarget goes from Switch, Toggle and MultiSelect, and PopupMenu Check drops its copy; TestChoiceDisabledWhileFocused and TestDropdownMenuCheckDisabledThisFrameKeepsValue still pass. ComboboxBase is different: TestComboboxBaseIgnoresDisabledWrapper shows a focused one still takes typing under a disabled wrapper, so Combobox keeps a copy, now inline as its only user.
This commit is contained in:
6 files changed
+70
-22
No files matched your search
@@ -30,9 +30,9 @@ func Switch(c *ui.Context, on *bool, label string, opts SwitchOptions) *ui.Eleme
|
||||
d := Density(c)
|
||||
blocked := opts.Disabled || opts.Loading
|
||||
var sw *ui.Element
|
||||
// Disabled on a wrapper, and a copy, block the base before it takes input.
|
||||
// Disabled on a wrapper blocks the base before it takes input.
|
||||
ui.Row(c).Shrink(0).Disabled(blocked).Children(func() {
|
||||
sw = ui.SwitchBase(c, choiceTarget(on, blocked)).Gap(d.Unit() * 2).AlignItems(ui.Center).
|
||||
sw = ui.SwitchBase(c, on).Gap(d.Unit() * 2).AlignItems(ui.Center).
|
||||
MinHeight(d.ControlHeight()).FocusRing(false)
|
||||
})
|
||||
if opts.Description != "" {
|
||||
@@ -82,15 +82,6 @@ func Switch(c *ui.Context, on *bool, label string, opts SwitchOptions) *ui.Eleme
|
||||
return sw
|
||||
}
|
||||
|
||||
// choiceTarget is v, or a throwaway copy of it while input is blocked.
|
||||
func choiceTarget[T any](v *T, blocked bool) *T {
|
||||
if !blocked {
|
||||
return v
|
||||
}
|
||||
cp := *v
|
||||
return &cp
|
||||
}
|
||||
|
||||
func switchFloat(b bool) float32 {
|
||||
if b {
|
||||
return 1
|
||||
|
||||
Reference in new issue
Block a user