Documentation
¶
Overview ¶
Package mvvmtk is the binding glue between github.com/go-widgets/mvvm (Observable / Command / ObservableList) and github.com/go-widgets/toolkit widgets.
mvvm is deliberately toolkit-agnostic: it binds through a pointer to a widget's value field and a pointer to its callback slot, and never imports any widget package. toolkit, in turn, never imports mvvm. This module is the one place that knows BOTH, so an app can wire a ViewModel to a widget in a single call and never touch widget state fields directly:
unbind := mvvmtk.BindText(entry, vm.Query, win.Invalidate)
Each helper is a thin, correct wrapper over the generic mvvm adapters (BindField / OneWay / BindList / BindCommand) with the widget's real field and callback names filled in — no business logic. Every helper returns an unbind func that detaches the binding and restores any prior callback.
Index ¶
- func BindChecked(cb *toolkit.CheckButton, obs *mvvm.Observable[bool], invalidate func()) (unbind func())
- func BindCommand(b *toolkit.Button, c *mvvm.Command, invalidate func()) (unbind func())
- func BindDropDownOptions[T any](d *toolkit.DropDown, l *mvvm.ObservableList[T], project func(T) string, ...) (unbind func())
- func BindEntryText(e *toolkit.Entry, obs *mvvm.Observable[string], invalidate func()) (unbind func())
- func BindLabel(l *toolkit.Label, obs *mvvm.Observable[string], invalidate func()) (unbind func())
- func BindListItems[T any](lb *toolkit.ListBox, l *mvvm.ObservableList[T], project func(T) string, ...) (unbind func())
- func BindListSelection(lb *toolkit.ListBox, obs *mvvm.Observable[int], invalidate func()) (unbind func())
- func BindProgress(p *toolkit.ProgressBar, obs *mvvm.Observable[float64], invalidate func()) (unbind func())
- func BindSelectedIndex(d *toolkit.DropDown, obs *mvvm.Observable[int], invalidate func()) (unbind func())
- func BindSpin(s *toolkit.SpinButton, obs *mvvm.Observable[int], invalidate func()) (unbind func())
- func BindText(e *toolkit.SearchEntry, obs *mvvm.Observable[string], invalidate func()) (unbind func())
- func BindTree[T any](tt *toolkit.TreeTable, l *mvvm.ObservableList[T], ...) (unbind func())
- func BindViewSwitcher(v *toolkit.ViewSwitcher, obs *mvvm.Observable[int], invalidate func()) (unbind func())
- func BindViews[T any](v *toolkit.ViewSwitcher, l *mvvm.ObservableList[T], project func(T) string, ...) (unbind func())
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindChecked ¶
func BindChecked(cb *toolkit.CheckButton, obs *mvvm.Observable[bool], invalidate func()) (unbind func())
BindChecked two-way-binds a CheckButton's Checked to a bool observable (fields CheckButton.Checked / CheckButton.OnToggle).
func BindCommand ¶
BindCommand wires a Command to a Button: it composes Execute into the button's OnClick and reflects executability by greying the button — swapping its Style to ButtonSecondary when the command cannot execute and restoring the original Style when it can (a Button has no boolean "disabled" field, so this backend-specific greying is how CanExecute surfaces). invalidate (may be nil) requests a repaint on each executability change. The returned unbind restores the prior OnClick and detaches.
func BindDropDownOptions ¶
func BindDropDownOptions[T any](d *toolkit.DropDown, l *mvvm.ObservableList[T], project func(T) string, invalidate func()) (unbind func())
BindDropDownOptions binds an ObservableList to a DropDown's Options slice (field DropDown.Options), projecting each element to its option string.
func BindEntryText ¶
func BindEntryText(e *toolkit.Entry, obs *mvvm.Observable[string], invalidate func()) (unbind func())
BindEntryText two-way-binds an Entry's Text to a string observable (fields Entry.Text / Entry.OnChange).
func BindLabel ¶
func BindLabel(l *toolkit.Label, obs *mvvm.Observable[string], invalidate func()) (unbind func())
BindLabel one-way-binds a string observable to a Label's Text (field Label.Text; a Label has no edit callback).
func BindListItems ¶
func BindListItems[T any](lb *toolkit.ListBox, l *mvvm.ObservableList[T], project func(T) string, invalidate func()) (unbind func())
BindListItems binds an ObservableList to a ListBox's Items slice (field ListBox.Items), projecting each element to its row string.
func BindListSelection ¶
func BindListSelection(lb *toolkit.ListBox, obs *mvvm.Observable[int], invalidate func()) (unbind func())
BindListSelection two-way-binds a ListBox's Selected row to an int observable (fields ListBox.Selected / ListBox.OnActivate). Note OnActivate fires on row activation (its only value/index callback slot), so the view→VM edge updates the observable when a row is activated; the VM→view edge sets Selected on any observable change.
func BindProgress ¶
func BindProgress(p *toolkit.ProgressBar, obs *mvvm.Observable[float64], invalidate func()) (unbind func())
BindProgress one-way-binds a float64 observable to a ProgressBar's Fraction (field ProgressBar.Fraction; a ProgressBar has no edit callback). Callers keep the value in the widget's [0,1] domain.
func BindSelectedIndex ¶
func BindSelectedIndex(d *toolkit.DropDown, obs *mvvm.Observable[int], invalidate func()) (unbind func())
BindSelectedIndex two-way-binds a DropDown's Selected index to an int observable (fields DropDown.Selected / DropDown.OnSelect).
func BindSpin ¶
func BindSpin(s *toolkit.SpinButton, obs *mvvm.Observable[int], invalidate func()) (unbind func())
BindSpin two-way-binds a SpinButton's Value to an int observable (fields SpinButton.Value / SpinButton.OnChange).
func BindText ¶
func BindText(e *toolkit.SearchEntry, obs *mvvm.Observable[string], invalidate func()) (unbind func())
BindText two-way-binds a SearchEntry's Text to a string observable (fields SearchEntry.Text / SearchEntry.OnChange).
func BindTree ¶
func BindTree[T any](tt *toolkit.TreeTable, l *mvvm.ObservableList[T], project func(T) *toolkit.TreeTableNode, invalidate func()) (unbind func())
BindTree binds an ObservableList to a TreeTable's Root forest: on every list change it rebuilds Root (field TreeTable.Root, a []*TreeTableNode forest — not a flat []string, so mvvm.BindList can't drive it) by projecting each element to a node, then calls invalidate. project owns building each node's Cells and Children; this helper only wires the rebuild-on-change. The returned unbind detaches the list subscription.
func BindViewSwitcher ¶
func BindViewSwitcher(v *toolkit.ViewSwitcher, obs *mvvm.Observable[int], invalidate func()) (unbind func())
BindViewSwitcher two-way-binds a ViewSwitcher's Current segment to an int observable (fields ViewSwitcher.Current / ViewSwitcher.OnChange).
func BindViews ¶
func BindViews[T any](v *toolkit.ViewSwitcher, l *mvvm.ObservableList[T], project func(T) string, invalidate func()) (unbind func())
BindViews binds an ObservableList to a ViewSwitcher's Views slice (field ViewSwitcher.Views), projecting each element to its segment label.
Types ¶
This section is empty.