tkbind

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package tkbind holds the MVVM binding adapters that are specific to the pixel toolkit (github.com/go-widgets/toolkit) — the widgets whose value/callback shape the generic mvvm adapters can't express, such as a two-handle range slider (a multi-argument OnChange). It is the ONLY MVVM package that imports toolkit; the core mvvm package stays backend-free.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindCardActive added in v0.3.0

func BindCardActive(sel *mvvm.Observable[int], c *toolkit.Container, card *toolkit.CardLayout, invalidate func()) (unbind func())

BindCardActive one-way-binds an Observable[int] to a CardLayout's Active index, re-arranging its container so the newly selected card becomes the visible one. Which card shows is a view-model concern (driven by a bound active index), so the binding is VM→view only. Returns an unbind that detaches the subscription.

func BindContainer added in v0.3.0

func BindContainer[T any](l *mvvm.ObservableList[T], c *toolkit.Container, factory func(T) toolkit.Item, invalidate func()) (unbind func())

BindContainer drives a toolkit.Container's children from an ObservableList: on every list change it rebuilds the container's items via factory (each element → a layout Item) and calls invalidate. This is the data-driven half of the toolkit container/layout model — the view's children follow the view model's collection. It mirrors mvvm.BindList's full-rebuild shape (the child count is view-scale) while producing widget Items rather than strings. Returns an unbind that detaches the list subscription.

func BindRange

func BindRange(low, high *mvvm.Observable[float64], rs *toolkit.RangeSlider, invalidate func()) (unbind func())

BindRange two-way-binds a RangeSlider's Low/High to a pair of observables. The slider fires OnChange(low, high) on every drag — a shape the generic single-value BindField can't take — so this adapter fans it out to both observables and pushes each back to the matching field. Loop-free: the field writes are silent and Observable.Set skips equal values. Returns an unbind that restores the prior OnChange and detaches both subscriptions.

Types

type BrowserVM added in v0.4.0

type BrowserVM struct {
	URL        *mvvm.Observable[string]
	Title      *mvvm.Observable[string]
	Loading    *mvvm.Observable[bool]
	Progress   *mvvm.Observable[float64]
	CanBack    *mvvm.Observable[bool]
	CanForward *mvvm.Observable[bool]
	TabCount   *mvvm.Observable[int]
	Zoom       *mvvm.Observable[float64]
	Back       *mvvm.Command
	Forward    *mvvm.Command
	Reload     *mvvm.Command
	ZoomIn     *mvvm.Command
	ZoomOut    *mvvm.Command
}

BrowserVM is the observable ViewModel for a toolkit.Browser: its navigable state exposed as Observables (for read-only binding to labels/indicators) and its actions as Commands (with Can… guards). The Browser widget itself stays a plain View in toolkit — it never imports mvvm — so this adapter is the MVVM seam: it mirrors the widget's state into the observables (via the widget's OnChange hook) and drives the widget from the commands.

func BindBrowser added in v0.4.0

func BindBrowser(b *toolkit.Browser, invalidate func()) (*BrowserVM, func())

BindBrowser builds a BrowserVM bound to b and returns it with an unbind func. The widget is the source of truth (it owns the tabs/history); the VM mirrors its state on every change and its commands invoke the widget's actions. The commands' CanExecute tracks the widget's Can… guards, and their enabled state is refreshed on every widget change. invalidate (optional) is called after each sync so a host can schedule a redraw.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL