binding

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package binding provides support for binding data to widgets. All APIs in the binding package are safe to invoke directly from any goroutine.

Index

Constants

View Source
const DataTreeRootID = ""

DataTreeRootID const is the value used as ID for the root of any tree binding.

Variables

This section is empty.

Functions

func CleanupPreferences

func CleanupPreferences(p bellui.Preferences)

CleanupPreferences removes all bindings associated with the given preferences instance. This should be called when a preferences instance is no longer needed (e.g. when a window is closed) to allow garbage collection.

Since: 1.0

func UnbindPreference

func UnbindPreference(key string, p bellui.Preferences)

UnbindPreference removes the binding for the given key from the given preferences, allowing it to be garbage collected. Future calls to BindPreference* with the same key will create a new binding.

Since: 1.0

Types

type Bool

type Bool = Item[bool]

Bool supports binding a bool value.

Since: 1.0

func And

func And(data ...Bool) Bool

And returns a Bool binding that return true when all the passed Bool binding are true and false otherwise. It does apply a logical and boolean operation on all passed Bool bindings. This binding is two way. In case of a Set, it will propagate the value identically to all the Bool bindings used for its construction.

Since: 1.0

func BindPreferenceBool

func BindPreferenceBool(key string, p bellui.Preferences) Bool

BindPreferenceBool returns a bindable bool value that is managed by the application preferences. Changes to this value will be saved to application storage and when the app starts the previous values will be read.

Since: 1.0

func NewBool

func NewBool() Bool

NewBool returns a bindable bool value that is managed internally.

Since: 1.0

func Not

func Not(data Bool) Bool

Not returns a Bool binding that invert the value of the given data binding. This is providing the logical Not boolean operation as a data binding.

Since: 1.0

func Or

func Or(data ...Bool) Bool

Or returns a Bool binding that return true when at least one of the passed Bool binding is true and false otherwise. It does apply a logical or boolean operation on all passed Bool bindings. This binding is two way. In case of a Set, it will propagate the value identically to all the Bool bindings used for its construction.

Since: 1.0

func StringToBool

func StringToBool(str String) Bool

StringToBool creates a binding that connects a String data item to a Bool. Changes to the String will be parsed and pushed to the Bool if the parse was successful, and setting the Bool update the String binding.

Since: 1.0

func StringToBoolWithFormat

func StringToBoolWithFormat(str String, format string) Bool

StringToBoolWithFormat creates a binding that connects a String data item to a Bool and is presented using the specified format. Changes to the Bool will be parsed and if the format matches and the parse is successful it will be pushed to the String. Setting the Bool will push a formatted value into the String.

Since: 1.0

type BoolList

type BoolList = List[bool]

BoolList supports binding a list of bool values.

Since: 1.0

func BindPreferenceBoolList

func BindPreferenceBoolList(key string, p bellui.Preferences) BoolList

BindPreferenceBoolList returns a bound list of bool values that is managed by the application preferences. Changes to this value will be saved to application storage and when the app starts the previous values will be read.

Since: 1.0

type BoolTree

type BoolTree = Tree[bool]

BoolTree supports binding a tree of bool values.

Since: 1.0

type Bytes

type Bytes = Item[[]byte]

Bytes supports binding a []byte value.

Since: 1.0

func NewBytes

func NewBytes() Bytes

NewBytes returns a bindable []byte value that is managed internally.

Since: 1.0

type BytesList

type BytesList = List[[]byte]

BytesList supports binding a list of []byte values.

Since: 1.0

type BytesTree

type BytesTree = Tree[[]byte]

BytesTree supports binding a tree of []byte values.

Since: 1.0

type DataItem

type DataItem interface {
	// AddListener attaches a new change listener to this DataItem.
	// Listeners are called each time the data inside this DataItem changes.
	// Additionally, the listener will be triggered upon successful connection to get the current value.
	AddListener(DataListener)
	// RemoveListener will detach the specified change listener from the DataItem.
	// Disconnected listener will no longer be triggered when changes occur.
	RemoveListener(DataListener)
}

DataItem is the base interface for all bindable data items. All APIs on bindable data items are safe to invoke directly fron any goroutine.

Since: 1.0

type DataList

type DataList interface {
	DataItem
	GetItem(index int) (DataItem, error)
	Length() int
}

DataList is the base interface for all bindable data lists.

Since: 1.0

type DataListener

type DataListener interface {
	DataChanged()
}

DataListener is any object that can register for changes in a bindable DataItem. See NewDataListener to define a new listener using just an inline function.

Since: 1.0

func NewDataListener

func NewDataListener(fn func()) DataListener

NewDataListener is a helper function that creates a new listener type from a simple callback function.

Since: 1.0

type DataMap

type DataMap interface {
	DataItem
	GetItem(string) (DataItem, error)
	Keys() []string
}

DataMap is the base interface for all bindable data maps.

Since: 1.0

type DataTree

type DataTree interface {
	DataItem
	GetItem(id string) (DataItem, error)
	ChildIDs(string) []string
}

DataTree is the base interface for all bindable data trees.

Since: 1.0

type ExternalBool

type ExternalBool = ExternalItem[bool]

ExternalBool supports binding a bool value to an external value.

Since: 1.0

func BindBool

func BindBool(v *bool) ExternalBool

BindBool returns a new bindable value that controls the contents of the provided bool variable. If your code changes the content of the variable this refers to you should call Reload() to inform the bindings.

Since: 1.0

type ExternalBoolList

type ExternalBoolList = ExternalList[bool]

ExternalBoolList supports binding a list of bool values from an external variable.

Since: 1.0

type ExternalBoolTree

type ExternalBoolTree = ExternalTree[bool]

ExternalBoolTree supports binding a tree of bool values from an external variable.

Since: 1.0

type ExternalBytes

type ExternalBytes = ExternalItem[[]byte]

ExternalBytes supports binding a []byte value to an external value.

Since: 1.0

func BindBytes

func BindBytes(v *[]byte) ExternalBytes

BindBytes returns a new bindable value that controls the contents of the provided []byte variable. If your code changes the content of the variable this refers to you should call Reload() to inform the bindings.

Since: 1.0

type ExternalBytesList

type ExternalBytesList = ExternalList[[]byte]

ExternalBytesList supports binding a list of []byte values from an external variable.

Since: 1.0

type ExternalBytesTree

type ExternalBytesTree = ExternalTree[[]byte]

ExternalBytesTree supports binding a tree of []byte values from an external variable.

Since: 1.0

type ExternalFloat

type ExternalFloat = ExternalItem[float64]

ExternalFloat supports binding a float64 value to an external value.

Since: 1.0

func BindFloat

func BindFloat(v *float64) ExternalFloat

BindFloat returns a new bindable value that controls the contents of the provided float64 variable. If your code changes the content of the variable this refers to you should call Reload() to inform the bindings.

Since: 1.0

type ExternalFloatList

type ExternalFloatList = ExternalList[float64]

ExternalFloatList supports binding a list of float64 values from an external variable.

Since: 1.0

type ExternalFloatTree

type ExternalFloatTree = ExternalTree[float64]

ExternalFloatTree supports binding a tree of float64 values from an external variable.

Since: 1.0

type ExternalInt

type ExternalInt = ExternalItem[int]

ExternalInt supports binding a int value to an external value.

Since: 1.0

func BindInt

func BindInt(v *int) ExternalInt

BindInt returns a new bindable value that controls the contents of the provided int variable. If your code changes the content of the variable this refers to you should call Reload() to inform the bindings.

Since: 1.0

type ExternalIntList

type ExternalIntList = ExternalList[int]

ExternalIntList supports binding a list of int values from an external variable.

Since: 1.0

type ExternalIntTree

type ExternalIntTree = ExternalTree[int]

ExternalIntTree supports binding a tree of int values from an external variable.

Since: 1.0

type ExternalItem

type ExternalItem[T any] interface {
	Item[T]
	Reload() error
}

ExternalItem supports binding any external value of type T.

Since: 1.0

func BindItem

func BindItem[T any](val *T, comparator func(T, T) bool) ExternalItem[T]

BindItem returns a new bindable value that controls the contents of the provided variable of type T. If your code changes the content of the variable this refers to you should call Reload() to inform the bindings.

Since: 1.0

type ExternalList

type ExternalList[T any] interface {
	List[T]

	Reload() error
}

ExternalList supports binding a list of values, with type T, from an external variable.

Since: 1.0

func BindBoolList

func BindBoolList(v *[]bool) ExternalList[bool]

BindBoolList returns a bound list of bool values, based on the contents of the passed slice. If your code changes the content of the slice this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindBytesList

func BindBytesList(v *[][]byte) ExternalList[[]byte]

BindBytesList returns a bound list of []byte values, based on the contents of the passed slice. If your code changes the content of the slice this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindFloatList

func BindFloatList(v *[]float64) ExternalList[float64]

BindFloatList returns a bound list of float64 values, based on the contents of the passed slice. If your code changes the content of the slice this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindIntList

func BindIntList(v *[]int) ExternalList[int]

BindIntList returns a bound list of int values, based on the contents of the passed slice. If your code changes the content of the slice this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindList

func BindList[T any](v *[]T, comparator func(T, T) bool) ExternalList[T]

BindList returns a bound list of values with type T, based on the contents of the passed slice. If your code changes the content of the slice this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindRuneList

func BindRuneList(v *[]rune) ExternalList[rune]

BindRuneList returns a bound list of rune values, based on the contents of the passed slice. If your code changes the content of the slice this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindStringList

func BindStringList(v *[]string) ExternalList[string]

BindStringList returns a bound list of string values, based on the contents of the passed slice. If your code changes the content of the slice this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindURIList

func BindURIList(v *[]bellui.URI) ExternalList[bellui.URI]

BindURIList returns a bound list of bellui.URI values, based on the contents of the passed slice. If your code changes the content of the slice this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindUntypedList

func BindUntypedList(v *[]any) ExternalList[any]

BindUntypedList returns a bound list of any values, based on the contents of the passed slice. If your code changes the content of the slice this refers to you should call Reload() to inform the bindings.

Since: 1.0

type ExternalRune

type ExternalRune = ExternalItem[rune]

ExternalRune supports binding a rune value to an external value.

Since: 1.0

func BindRune

func BindRune(v *rune) ExternalRune

BindRune returns a new bindable value that controls the contents of the provided rune variable. If your code changes the content of the variable this refers to you should call Reload() to inform the bindings.

Since: 1.0

type ExternalRuneList

type ExternalRuneList = ExternalList[rune]

ExternalRuneList supports binding a list of rune values from an external variable.

Since: 1.0

type ExternalRuneTree

type ExternalRuneTree = ExternalTree[rune]

ExternalRuneTree supports binding a tree of rune values from an external variable.

Since: 1.0

type ExternalString

type ExternalString = ExternalItem[string]

ExternalString supports binding a string value to an external value.

Since: 1.0

func BindString

func BindString(v *string) ExternalString

BindString returns a new bindable value that controls the contents of the provided string variable. If your code changes the content of the variable this refers to you should call Reload() to inform the bindings.

Since: 1.0

type ExternalStringList

type ExternalStringList = ExternalList[string]

ExternalStringList supports binding a list of string values from an external variable.

Since: 1.0

type ExternalStringTree

type ExternalStringTree = ExternalTree[string]

ExternalStringTree supports binding a tree of string values from an external variable.

Since: 1.0

type ExternalTree

type ExternalTree[T any] interface {
	Tree[T]

	Reload() error
}

ExternalTree supports binding a tree of values, of type T, from an external variable.

Since: 1.0

func BindBoolTree

func BindBoolTree(ids *map[string][]string, v *map[string]bool) ExternalTree[bool]

BindBoolTree returns a bound tree of bool values, based on the contents of the passed values. The ids map specifies how each item relates to its parent (with id ""), with the values being in the v map. If your code changes the content of the maps this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindBytesTree

func BindBytesTree(ids *map[string][]string, v *map[string][]byte) ExternalTree[[]byte]

BindBytesTree returns a bound tree of []byte values, based on the contents of the passed values. The ids map specifies how each item relates to its parent (with id ""), with the values being in the v map. If your code changes the content of the maps this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindFloatTree

func BindFloatTree(ids *map[string][]string, v *map[string]float64) ExternalTree[float64]

BindFloatTree returns a bound tree of float64 values, based on the contents of the passed values. The ids map specifies how each item relates to its parent (with id ""), with the values being in the v map. If your code changes the content of the maps this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindIntTree

func BindIntTree(ids *map[string][]string, v *map[string]int) ExternalTree[int]

BindIntTree returns a bound tree of int values, based on the contents of the passed values. The ids map specifies how each item relates to its parent (with id ""), with the values being in the v map. If your code changes the content of the maps this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindRuneTree

func BindRuneTree(ids *map[string][]string, v *map[string]rune) ExternalTree[rune]

BindRuneTree returns a bound tree of rune values, based on the contents of the passed values. The ids map specifies how each item relates to its parent (with id ""), with the values being in the v map. If your code changes the content of the maps this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindStringTree

func BindStringTree(ids *map[string][]string, v *map[string]string) ExternalTree[string]

BindStringTree returns a bound tree of string values, based on the contents of the passed values. The ids map specifies how each item relates to its parent (with id ""), with the values being in the v map. If your code changes the content of the maps this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindTree

func BindTree[T any](ids *map[string][]string, v *map[string]T, comparator func(T, T) bool) ExternalTree[T]

BindTree returns a bound tree of values with type T, based on the contents of the passed values. The ids map specifies how each item relates to its parent (with id ""), with the values being in the v map. If your code changes the content of the maps this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindURITree

func BindURITree(ids *map[string][]string, v *map[string]bellui.URI) ExternalTree[bellui.URI]

BindURITree returns a bound tree of bellui.URI values, based on the contents of the passed values. The ids map specifies how each item relates to its parent (with id ""), with the values being in the v map. If your code changes the content of the maps this refers to you should call Reload() to inform the bindings.

Since: 1.0

func BindUntypedTree

func BindUntypedTree(ids *map[string][]string, v *map[string]any) ExternalTree[any]

BindUntypedTree returns a bound tree of any values, based on the contents of the passed values. The ids map specifies how each item relates to its parent (with id ""), with the values being in the v map. If your code changes the content of the maps this refers to you should call Reload() to inform the bindings.

Since: 1.0

type ExternalURI

type ExternalURI = ExternalItem[bellui.URI]

ExternalURI supports binding a bellui.URI value to an external value.

Since: 1.0

func BindURI

func BindURI(v *bellui.URI) ExternalURI

BindURI returns a new bindable value that controls the contents of the provided bellui.URI variable. If your code changes the content of the variable this refers to you should call Reload() to inform the bindings.

Since: 1.0

type ExternalURIList

type ExternalURIList = ExternalList[bellui.URI]

ExternalURIList supports binding a list of bellui.URI values from an external variable.

Since: 1.0

type ExternalURITree

type ExternalURITree = ExternalTree[bellui.URI]

ExternalURITree supports binding a tree of bellui.URI values from an external variable.

Since: 1.0

type ExternalUntyped

type ExternalUntyped = ExternalItem[any]

ExternalUntyped supports binding a any value to an external value.

Since: 1.0

func BindUntyped

func BindUntyped(v any) ExternalUntyped

BindUntyped returns a bindable any value that is bound to an external type. The parameter must be a pointer to the type you wish to bind.

Since: 1.0

type ExternalUntypedList

type ExternalUntypedList = ExternalList[any]

ExternalUntypedList supports binding a list of any values from an external variable.

Since: 1.0

type ExternalUntypedMap

type ExternalUntypedMap interface {
	UntypedMap
	Reload() error
}

ExternalUntypedMap is a map data binding with all values untyped (any), connected to an external data source.

Since: 1.0

func BindUntypedMap

func BindUntypedMap(d *map[string]any) ExternalUntypedMap

BindUntypedMap creates a new map binding of string to any based on the data passed. If your code changes the content of the map this refers to you should call Reload() to inform the bindings.

Since: 1.0

type ExternalUntypedTree

type ExternalUntypedTree = ExternalTree[any]

ExternalUntypedTree supports binding a tree of any values from an external variable.

Since: 1.0

type Float

type Float = Item[float64]

Float supports binding a float64 value.

Since: 1.0

func BindPreferenceFloat

func BindPreferenceFloat(key string, p bellui.Preferences) Float

BindPreferenceFloat returns a bindable float64 value that is managed by the application preferences. Changes to this value will be saved to application storage and when the app starts the previous values will be read.

Since: 1.0

func IntToFloat

func IntToFloat(val Int) Float

IntToFloat creates a binding that connects an Int data item to a Float.

Since: 1.0

func NewFloat

func NewFloat() Float

NewFloat returns a bindable float64 value that is managed internally.

Since: 1.0

func StringToFloat

func StringToFloat(str String) Float

StringToFloat creates a binding that connects a String data item to a Float. Changes to the String will be parsed and pushed to the Float if the parse was successful, and setting the Float update the String binding.

Since: 1.0

func StringToFloatWithFormat

func StringToFloatWithFormat(str String, format string) Float

StringToFloatWithFormat creates a binding that connects a String data item to a Float and is presented using the specified format. Changes to the Float will be parsed and if the format matches and the parse is successful it will be pushed to the String. Setting the Float will push a formatted value into the String.

Since: 1.0

type FloatList

type FloatList = List[float64]

FloatList supports binding a list of float64 values.

Since: 1.0

func BindPreferenceFloatList

func BindPreferenceFloatList(key string, p bellui.Preferences) FloatList

BindPreferenceFloatList returns a bound list of float64 values that is managed by the application preferences. Changes to this value will be saved to application storage and when the app starts the previous values will be read.

Since: 1.0

type FloatTree

type FloatTree = Tree[float64]

FloatTree supports binding a tree of float64 values.

Since: 1.0

type Int

type Int = Item[int]

Int supports binding a int value.

Since: 1.0

func BindPreferenceInt

func BindPreferenceInt(key string, p bellui.Preferences) Int

BindPreferenceInt returns a bindable int value that is managed by the application preferences. Changes to this value will be saved to application storage and when the app starts the previous values will be read.

Since: 1.0

func FloatToInt

func FloatToInt(v Float) Int

FloatToInt creates a binding that connects a Float data item to an Int.

Since: 1.0

func NewInt

func NewInt() Int

NewInt returns a bindable int value that is managed internally.

Since: 1.0

func StringToInt

func StringToInt(str String) Int

StringToInt creates a binding that connects a String data item to a Int. Changes to the String will be parsed and pushed to the Int if the parse was successful, and setting the Int update the String binding.

Since: 1.0

func StringToIntWithFormat

func StringToIntWithFormat(str String, format string) Int

StringToIntWithFormat creates a binding that connects a String data item to a Int and is presented using the specified format. Changes to the Int will be parsed and if the format matches and the parse is successful it will be pushed to the String. Setting the Int will push a formatted value into the String.

Since: 1.0

type IntList

type IntList = List[int]

IntList supports binding a list of int values.

Since: 1.0

func BindPreferenceIntList

func BindPreferenceIntList(key string, p bellui.Preferences) IntList

BindPreferenceIntList returns a bound list of int values that is managed by the application preferences. Changes to this value will be saved to application storage and when the app starts the previous values will be read.

Since: 1.0

type IntTree

type IntTree = Tree[int]

IntTree supports binding a tree of int values.

Since: 1.0

type Item

type Item[T any] interface {
	DataItem
	Get() (T, error)
	Set(T) error
}

Item supports binding any type T generically.

Since: 1.0

func NewItem

func NewItem[T any](comparator func(T, T) bool) Item[T]

NewItem returns a bindable value of type T that is managed internally.

Since: 1.0

type List

type List[T any] interface {
	DataList

	Append(value T) error
	Get() ([]T, error)
	GetValue(index int) (T, error)
	Prepend(value T) error
	Remove(value T) error
	Set(list []T) error
	SetValue(index int, value T) error
}

List supports binding a list of values with type T.

Since: 1.0

func NewBoolList

func NewBoolList() List[bool]

NewBoolList returns a bindable list of bool values.

Since: 1.0

func NewBytesList

func NewBytesList() List[[]byte]

NewBytesList returns a bindable list of []byte values.

Since: 1.0

func NewFloatList

func NewFloatList() List[float64]

NewFloatList returns a bindable list of float64 values.

Since: 1.0

func NewIntList

func NewIntList() List[int]

NewIntList returns a bindable list of int values.

Since: 1.0

func NewList

func NewList[T any](comparator func(T, T) bool) List[T]

NewList returns a bindable list of values with type T.

Since: 1.0

func NewRuneList

func NewRuneList() List[rune]

NewRuneList returns a bindable list of rune values.

Since: 1.0

func NewStringList

func NewStringList() List[string]

NewStringList returns a bindable list of string values.

Since: 1.0

func NewURIList

func NewURIList() List[bellui.URI]

NewURIList returns a bindable list of bellui.URI values.

Since: 1.0

func NewUntypedList

func NewUntypedList() List[any]

NewUntypedList returns a bindable list of any values.

Since: 1.0

type Rune

type Rune = Item[rune]

Rune supports binding a rune value.

Since: 1.0

func NewRune

func NewRune() Rune

NewRune returns a bindable rune value that is managed internally.

Since: 1.0

type RuneList

type RuneList = List[rune]

RuneList supports binding a list of rune values.

Since: 1.0

type RuneTree

type RuneTree = Tree[rune]

RuneTree supports binding a tree of rune values.

Since: 1.0

type String

type String = Item[string]

String supports binding a string value.

Since: 1.0

func BindPreferenceString

func BindPreferenceString(key string, p bellui.Preferences) String

BindPreferenceString returns a bindable string value that is managed by the application preferences. Changes to this value will be saved to application storage and when the app starts the previous values will be read.

Since: 1.0

func BoolToString

func BoolToString(v Bool) String

BoolToString creates a binding that connects a Bool data item to a String. Changes to the Bool will be pushed to the String and setting the string will parse and set the Bool if the parse was successful.

Since: 1.0

func BoolToStringWithFormat

func BoolToStringWithFormat(v Bool, format string) String

BoolToStringWithFormat creates a binding that connects a Bool data item to a String and is presented using the specified format. Changes to the Bool will be pushed to the String and setting the string will parse and set the Bool if the string matches the format and its parse was successful.

Since: 1.0

func FloatToString

func FloatToString(v Float) String

FloatToString creates a binding that connects a Float data item to a String. Changes to the Float will be pushed to the String and setting the string will parse and set the Float if the parse was successful.

Since: 1.0

func FloatToStringWithFormat

func FloatToStringWithFormat(v Float, format string) String

FloatToStringWithFormat creates a binding that connects a Float data item to a String and is presented using the specified format. Changes to the Float will be pushed to the String and setting the string will parse and set the Float if the string matches the format and its parse was successful.

Since: 1.0

func IntToString

func IntToString(v Int) String

IntToString creates a binding that connects a Int data item to a String. Changes to the Int will be pushed to the String and setting the string will parse and set the Int if the parse was successful.

Since: 1.0

func IntToStringWithFormat

func IntToStringWithFormat(v Int, format string) String

IntToStringWithFormat creates a binding that connects a Int data item to a String and is presented using the specified format. Changes to the Int will be pushed to the String and setting the string will parse and set the Int if the string matches the format and its parse was successful.

Since: 1.0

func NewLocalizedPlural

func NewLocalizedPlural(key string, count Int, data ...any) String

NewLocalizedPlural returns a String binding whose value is the plural-form translation of key for the current value of count (resolved via lang.LocalizePlural, i.e. the same lookup as lang.N). It re-derives whenever the active locale changes through lang.SetLocale or count changes, so both a language switch and a count change update a bound widget without a rebuild.

count is an Int binding so the plural form tracks a live count; for a fixed count, pass a NewInt you Set once.

Since: 1.0

func NewLocalizedPluralWithKey

func NewLocalizedPluralWithKey(key, fallback string, count Int, data ...any) String

NewLocalizedPluralWithKey is the explicit-fallback form of NewLocalizedPlural, resolving via lang.LocalizePluralKey (i.e. the same lookup as lang.XN).

Since: 1.0

func NewLocalizedString

func NewLocalizedString(key string, data ...any) String

NewLocalizedString returns a String binding whose value is the translation of key (resolved via lang.Localize, i.e. the same lookup as lang.L) and which re-derives that translation whenever the active locale changes through lang.SetLocale. Bind it to a widget — e.g. with github.com/belluikit/bellui/widget.NewLabelWithData — and the widget's text follows a live language switch without a manual rebuild.

Any template data is forwarded to lang.Localize on every (re-)evaluation, so pass values, not pre-formatted strings, for them to localize correctly.

Since: 1.0

func NewLocalizedStringWithKey

func NewLocalizedStringWithKey(key, fallback string, data ...any) String

NewLocalizedStringWithKey returns a String binding whose value is the translation looked up by key, falling back to fallback when no translation is found (resolved via lang.LocalizeKey, i.e. the same lookup as lang.X). Like NewLocalizedString it re-derives on a live lang.SetLocale change.

Use this when your message IDs are distinct from the default text, the common pattern for larger translation catalogues.

Since: 1.0

func NewSprintf

func NewSprintf(format string, b ...DataItem) String

NewSprintf returns a String binding that format its content using the format string and the provide additional parameter that must be other data bindings. This data binding use fmt.Sprintf and fmt.Scanf internally and will have all the same limitation as those function.

Since: 1.0

func NewString

func NewString() String

NewString returns a bindable string value that is managed internally.

Since: 1.0

func StringToStringWithFormat

func StringToStringWithFormat(str String, format string) String

StringToStringWithFormat creates a binding that converts a string to another string using the specified format. Changes to the returned String will be pushed to the passed in String and setting a new string value will parse and set the underlying String if it matches the format and the parse was successful.

Since: 1.0

func URIToString

func URIToString(v URI) String

URIToString creates a binding that connects a URI data item to a String. Changes to the URI will be pushed to the String and setting the string will parse and set the URI if the parse was successful.

Since: 1.0

type StringList

type StringList = List[string]

StringList supports binding a list of string values.

Since: 1.0

func BindPreferenceStringList

func BindPreferenceStringList(key string, p bellui.Preferences) StringList

BindPreferenceStringList returns a bound list of string values that is managed by the application preferences. Changes to this value will be saved to application storage and when the app starts the previous values will be read.

Since: 1.0

type StringTree

type StringTree = Tree[string]

StringTree supports binding a tree of string values.

Since: 1.0

type Struct

type Struct interface {
	DataMap
	GetValue(string) (any, error)
	SetValue(string, any) error
	Reload() error
}

Struct is the base interface for a bound struct type.

Since: 1.0

func BindStruct

func BindStruct(i any) Struct

BindStruct creates a new map binding of string to any using the struct passed as data. The key for each item is a string representation of each exported field with the value set as an any. Only exported fields are included.

Since: 1.0

type Tree

type Tree[T any] interface {
	DataTree

	Append(parent, id string, value T) error
	Get() (map[string][]string, map[string]T, error)
	GetValue(id string) (T, error)
	Prepend(parent, id string, value T) error
	Remove(id string) error
	Set(ids map[string][]string, values map[string]T) error
	SetValue(id string, value T) error
}

Tree supports binding a tree of values with type T.

Since: 1.0

func NewBoolTree

func NewBoolTree() Tree[bool]

NewBoolTree returns a bindable tree of bool values.

Since: 1.0

func NewBytesTree

func NewBytesTree() Tree[[]byte]

NewBytesTree returns a bindable tree of []byte values.

Since: 1.0

func NewFloatTree

func NewFloatTree() Tree[float64]

NewFloatTree returns a bindable tree of float64 values.

Since: 1.0

func NewIntTree

func NewIntTree() Tree[int]

NewIntTree returns a bindable tree of int values.

Since: 1.0

func NewRuneTree

func NewRuneTree() Tree[rune]

NewRuneTree returns a bindable tree of rune values.

Since: 1.0

func NewStringTree

func NewStringTree() Tree[string]

NewStringTree returns a bindable tree of string values.

Since: 1.0

func NewTree

func NewTree[T any](comparator func(T, T) bool) Tree[T]

NewTree returns a bindable tree of values with type T.

Since: 1.0

func NewURITree

func NewURITree() Tree[bellui.URI]

NewURITree returns a bindable tree of bellui.URI values.

Since: 1.0

func NewUntypedTree

func NewUntypedTree() Tree[any]

NewUntypedTree returns a bindable tree of any values.

Since: 1.0

type URI

type URI = Item[bellui.URI]

URI supports binding a bellui.URI value.

Since: 1.0

func NewURI

func NewURI() URI

NewURI returns a bindable bellui.URI value that is managed internally.

Since: 1.0

func StringToURI

func StringToURI(str String) URI

StringToURI creates a binding that connects a String data item to a URI. Changes to the String will be parsed and pushed to the URI if the parse was successful, and setting the URI update the String binding.

Since: 1.0

type URIList

type URIList = List[bellui.URI]

URIList supports binding a list of bellui.URI values.

Since: 1.0

type URITree

type URITree = Tree[bellui.URI]

URITree supports binding a tree of bellui.URI values.

Since: 1.0

type Untyped

type Untyped = Item[any]

Untyped supports binding an any value.

Since: 1.0

func NewUntyped

func NewUntyped() Untyped

NewUntyped returns a bindable any value that is managed internally.

Since: 1.0

type UntypedList

type UntypedList = List[any]

UntypedList supports binding a list of any values.

Since: 1.0

type UntypedMap

type UntypedMap interface {
	DataMap
	Delete(string)
	Get() (map[string]any, error)
	GetValue(string) (any, error)
	Set(map[string]any) error
	SetValue(string, any) error
}

UntypedMap is a map data binding with all values Untyped (any).

Since: 1.0

func NewUntypedMap

func NewUntypedMap() UntypedMap

NewUntypedMap creates a new, empty map binding of string to any.

Since: 1.0

type UntypedTree

type UntypedTree = Tree[any]

UntypedTree supports binding a tree of any values.

Since: 1.0

Jump to

Keyboard shortcuts

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