| name | widget |
| description | Create a new go-gui widget with proper Cfg struct and factory function |
| disable-model-invocation | true |
New Widget
Create a new widget in the gui/ package following established conventions.
Arguments
name (required): widget name (e.g., "Slider", "ColorPicker")
Widget Structure
Every widget consists of:
- A
*Cfg struct (zero-initializable, exported fields)
- A factory function returning
View
- Event callbacks using
func(*Layout, *Event, *Window) signature
Template
package gui
type <Name>Cfg struct {
ID string
Focusable bool
OnClick func(*Layout, *Event, *Window)
}
func <Name>(cfg <Name>Cfg) View {
}
Rules
- File name:
view_<lowercase_name>.go in gui/
- Cfg struct must be zero-initializable (sensible defaults)
- Event callbacks:
func(*Layout, *Event, *Window), set e.IsHandled = true
- Focus needs both
Focusable (or default-on with no FocusDisabled)
and a non-empty ID; the requiredid analyzer flags
Focusable: true without an ID
- No variable shadowing (use
= not := for outer-scope vars)
- Read existing widgets (e.g.,
view_button.go, view_slider.go) for patterns
- Must pass
golangci-lint run ./gui/...