Elements are now pass-scoped value handles: tests that read bounds after a frame bind a ui.Handle. pixel tells frames apart by the build pass's root, since the Tester clock no longer moves on its own. Fix the regressions the upgrade brought: - Clipboard reads in input handlers go through c.Services(). - MyGo notes an overlay's opener after building it, so AutoFocus inside lost it; pixel.AutoFocus focuses through a Handle, and archtest bans the raw call. Dialogs hand the focus back again. - Elements around a press stay hovered: Tooltip tells a press-given focus by focus arriving under the pointer. - The web host moves the Tester clock with real time, at most 500 ms a call, and gives components the real clock. The gallery's source index also accepts CRLF checkouts. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
package data
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
// Property is one row; set exactly one value.
|
|
type Property struct {
|
|
Name string
|
|
Text *string
|
|
Number *float64
|
|
Switch *bool
|
|
// Min and Max bound Number as NumberInput's do.
|
|
Min, Max float64
|
|
}
|
|
|
|
type PropertyGridOptions struct {
|
|
// NameWidth is the names' column in dots; zero means 80.
|
|
NameWidth int
|
|
Disabled bool
|
|
}
|
|
|
|
type PropertyGridResult struct {
|
|
Element ui.Element
|
|
Changed bool
|
|
}
|
|
|
|
// PropertyGrid edits named text, number and switch values.
|
|
func PropertyGrid(c *ui.Context, text string, props []Property, o PropertyGridOptions) PropertyGridResult {
|
|
k := pixel.K(c)
|
|
nw := pixel.Or("PropertyGrid NameWidth", o.NameWidth, 80)
|
|
col := ui.Column(c).Gap(k.D(2)).Role(ui.RoleGroup).Label(text)
|
|
res := PropertyGridResult{Element: col}
|
|
col.Children(func() {
|
|
for _, p := range props {
|
|
ui.Row(c).Gap(k.D(4)).AlignItems(ui.Center).Children(func() {
|
|
ui.Box(c).Width(k.D(nw)).Shrink(0).Children(func() {
|
|
pixel.Text(c, p.Name, pixel.TextOptions{Slot: pixel.Faint})
|
|
})
|
|
switch {
|
|
case p.Text != nil && p.Number == nil && p.Switch == nil:
|
|
res.Changed = input.TextInput(c, p.Name, p.Text, input.TextInputOptions{Disabled: o.Disabled}).Changed || res.Changed
|
|
case p.Number != nil && p.Text == nil && p.Switch == nil:
|
|
res.Changed = input.NumberInput(c, p.Name, p.Number, input.NumberInputOptions{Min: p.Min, Max: p.Max, Disabled: o.Disabled}).Changed || res.Changed
|
|
case p.Switch != nil && p.Text == nil && p.Number == nil:
|
|
res.Changed = input.Switch(c, "", p.Switch, input.SwitchOptions{Label: p.Name, Disabled: o.Disabled}).Changed || res.Changed
|
|
default:
|
|
panic(fmt.Sprintf("data: Property %q needs exactly one value", p.Name))
|
|
}
|
|
})
|
|
}
|
|
})
|
|
if res.Changed {
|
|
slog.Debug("8bit: property grid", "label", text)
|
|
}
|
|
return res
|
|
}
|