Lifecycle
Every dado component follows the same four-phase lifecycle.
1. Construct
Section titled “1. Construct”Instantiate with the New constructor:
badge := components.NewBadge()grid := components.NewDataGrid()modal := components.NewModal()Constructors return a fully initialised component with sensible defaults. No options are required.
2. Configure
Section titled “2. Configure”Chain Set* methods before mounting:
badge. SetLabel("OK"). SetVariant(components.BadgeVariantSuccess)All Set* methods return the receiver so chains compose cleanly.
3. Mount
Section titled “3. Mount”Components satisfy tview.Primitive, so they slot directly into tview layouts
with no adapter code:
flex := tview.NewFlex(). AddItem(sidebar, 24, 0, false). AddItem(grid, 0, 1, true)That layout becomes visible by living inside a view that you push onto the app’s page stack. See Views & Navigation for how to wrap components in a view and move between screens.
4. Events
Section titled “4. Events”Wire callbacks after constructing:
grid.OnActivate(func(row int) { … })form.OnSubmit(func(e components.SubmitEvent) { … })input.OnChange(func(e components.ChangeEvent) { … })Callbacks are called on the tview goroutine. For background work use
app.QueueUpdateDraw to push updates back to the UI thread.
ComponentBase and StatefulComponentBase
Section titled “ComponentBase and StatefulComponentBase”All dado widgets embed one of these two base types:
| Base | When used |
|---|---|
ComponentBase | Stateless display components (Badge, Spinner, …) |
StatefulComponentBase | Components with mutable internal state (DataGrid, Form, …) |
You rarely interact with these directly, but they appear in the API docs as the
source of shared methods (SetBorder, SetTitle, SetTheme, …).
Teardown
Section titled “Teardown”dado components have no explicit teardown. When a component is removed from the view tree and goes out of scope the Go garbage collector reclaims it. Long-lived background goroutines spawned inside a component should be stopped explicitly before unmounting.