gi-gobject-2.0.12: GObject bindings

CopyrightWill Thompson Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria (garetxe@gmail.com)
Safe HaskellNone
LanguageHaskell2010

GI.GObject.Objects.Binding

Contents

Description

Binding is the representation of a binding between a property on a Object instance (or source) and another property on another Object instance (or target). Whenever the source property changes, the same value is applied to the target property; for instance, the following binding:

C code

 g_object_bind_property (object1, "property-a",
                         object2, "property-b",
                         G_BINDING_DEFAULT);

will cause the property named "property-b" of object2 to be updated every time g_object_set() or the specific accessor changes the value of the property "property-a" of object1.

It is possible to create a bidirectional binding between two properties of two Object instances, so that if either property changes, the other is updated as well, for instance:

C code

 g_object_bind_property (object1, "property-a",
                         object2, "property-b",
                         G_BINDING_BIDIRECTIONAL);

will keep the two properties in sync.

It is also possible to set a custom transformation function (in both directions, in case of a bidirectional binding) to apply a custom transformation from the source value to the target value before applying it; for instance, the following binding:

C code

 g_object_bind_property_full (adjustment1, "value",
                              adjustment2, "value",
                              G_BINDING_BIDIRECTIONAL,
                              celsius_to_fahrenheit,
                              fahrenheit_to_celsius,
                              NULL, NULL);

will keep the "value" property of the two adjustments in sync; the celsiusToFahrenheit function will be called whenever the "value" property of adjustment1 changes and will transform the current value of the property before applying it to the "value" property of adjustment2.

Vice versa, the fahrenheitToCelsius function will be called whenever the "value" property of adjustment2 changes, and will transform the current value of the property before applying it to the "value" property of adjustment1.

Note that Binding does not resolve cycles by itself; a cycle like

 object1:propertyA -> object2:propertyB
 object2:propertyB -> object3:propertyC
 object3:propertyC -> object1:propertyA

might lead to an infinite loop. The loop, in this particular case, can be avoided if the objects emit the Object::notify signal only if the value has effectively been changed. A binding is implemented using the Object::notify signal, so it is susceptible to all the various ways of blocking a signal emission, like signalStopEmission or signalHandlerBlock.

A binding will be severed, and the resources it allocates freed, whenever either one of the Object instances it refers to are finalized, or when the Binding instance loses its last reference.

Bindings for languages with garbage collection can use bindingUnbind to explicitly release a binding between the source and target properties, instead of relying on the last reference on the binding, source, and target instances to drop.

Binding is available since GObject 2.26

Synopsis

Exported types

newtype Binding #

Constructors

Binding (ManagedPtr Binding) 

Instances

GObject Binding # 
IsObject Binding # 
IsBinding Binding # 
((~) * info (ResolveBindingMethod t Binding), MethodInfo * info Binding p) => IsLabel t (Binding -> p) # 

Methods

fromLabel :: Proxy# Symbol t -> Binding -> p #

((~) * info (ResolveBindingMethod t Binding), MethodInfo * info Binding p) => IsLabelProxy t (Binding -> p) # 

Methods

fromLabelProxy :: Proxy Symbol t -> Binding -> p #

HasAttributeList * Binding # 
type AttributeList Binding # 
type SignalList Binding # 

toBinding :: (MonadIO m, IsBinding o) => o -> m Binding #

Methods

getFlags

data BindingGetFlagsMethodInfo #

Instances

((~) * signature (m [BindingFlags]), MonadIO m, IsBinding a) => MethodInfo * BindingGetFlagsMethodInfo a signature # 

bindingGetFlags #

Arguments

:: (HasCallStack, MonadIO m, IsBinding a) 
=> a

binding: a Binding

-> m [BindingFlags]

Returns: the BindingFlags used by the Binding

Retrieves the flags passed when constructing the Binding.

Since: 2.26

getSource

data BindingGetSourceMethodInfo #

Instances

((~) * signature (m Object), MonadIO m, IsBinding a) => MethodInfo * BindingGetSourceMethodInfo a signature # 

bindingGetSource #

Arguments

:: (HasCallStack, MonadIO m, IsBinding a) 
=> a

binding: a Binding

-> m Object

Returns: the source Object

Retrieves the Object instance used as the source of the binding.

Since: 2.26

getSourceProperty

bindingGetSourceProperty #

Arguments

:: (HasCallStack, MonadIO m, IsBinding a) 
=> a

binding: a Binding

-> m Text

Returns: the name of the source property

Retrieves the name of the property of Binding:source used as the source of the binding.

Since: 2.26

getTarget

data BindingGetTargetMethodInfo #

Instances

((~) * signature (m Object), MonadIO m, IsBinding a) => MethodInfo * BindingGetTargetMethodInfo a signature # 

bindingGetTarget #

Arguments

:: (HasCallStack, MonadIO m, IsBinding a) 
=> a

binding: a Binding

-> m Object

Returns: the target Object

Retrieves the Object instance used as the target of the binding.

Since: 2.26

getTargetProperty

bindingGetTargetProperty #

Arguments

:: (HasCallStack, MonadIO m, IsBinding a) 
=> a

binding: a Binding

-> m Text

Returns: the name of the target property

Retrieves the name of the property of Binding:target used as the target of the binding.

Since: 2.26

unbind

data BindingUnbindMethodInfo #

Instances

((~) * signature (m ()), MonadIO m, IsBinding a) => MethodInfo * BindingUnbindMethodInfo a signature # 

bindingUnbind #

Arguments

:: (HasCallStack, MonadIO m, IsBinding a) 
=> a

binding: a Binding

-> m () 

Explicitly releases the binding between the source and the target property expressed by binding.

This function will release the reference that is being held on the binding instance; if you want to hold on to the Binding instance after calling bindingUnbind, you will need to hold a reference to it.

Since: 2.38

Properties

flags

data BindingFlagsPropertyInfo #

Instances

AttrInfo BindingFlagsPropertyInfo # 
type AttrOrigin BindingFlagsPropertyInfo # 
type AttrLabel BindingFlagsPropertyInfo # 
type AttrGetType BindingFlagsPropertyInfo # 
type AttrBaseTypeConstraint BindingFlagsPropertyInfo # 
type AttrSetTypeConstraint BindingFlagsPropertyInfo # 
type AttrAllowedOps BindingFlagsPropertyInfo # 

source

data BindingSourcePropertyInfo #

Instances

AttrInfo BindingSourcePropertyInfo # 
type AttrOrigin BindingSourcePropertyInfo # 
type AttrLabel BindingSourcePropertyInfo # 
type AttrGetType BindingSourcePropertyInfo # 
type AttrBaseTypeConstraint BindingSourcePropertyInfo # 
type AttrSetTypeConstraint BindingSourcePropertyInfo # 
type AttrAllowedOps BindingSourcePropertyInfo # 

sourceProperty

data BindingSourcePropertyPropertyInfo #

Instances

AttrInfo BindingSourcePropertyPropertyInfo # 
type AttrOrigin BindingSourcePropertyPropertyInfo # 
type AttrLabel BindingSourcePropertyPropertyInfo # 
type AttrGetType BindingSourcePropertyPropertyInfo # 
type AttrBaseTypeConstraint BindingSourcePropertyPropertyInfo # 
type AttrSetTypeConstraint BindingSourcePropertyPropertyInfo # 
type AttrAllowedOps BindingSourcePropertyPropertyInfo # 

target

data BindingTargetPropertyInfo #

Instances

AttrInfo BindingTargetPropertyInfo # 
type AttrOrigin BindingTargetPropertyInfo # 
type AttrLabel BindingTargetPropertyInfo # 
type AttrGetType BindingTargetPropertyInfo # 
type AttrBaseTypeConstraint BindingTargetPropertyInfo # 
type AttrSetTypeConstraint BindingTargetPropertyInfo # 
type AttrAllowedOps BindingTargetPropertyInfo # 

targetProperty

data BindingTargetPropertyPropertyInfo #

Instances

AttrInfo BindingTargetPropertyPropertyInfo # 
type AttrOrigin BindingTargetPropertyPropertyInfo # 
type AttrLabel BindingTargetPropertyPropertyInfo # 
type AttrGetType BindingTargetPropertyPropertyInfo # 
type AttrBaseTypeConstraint BindingTargetPropertyPropertyInfo # 
type AttrSetTypeConstraint BindingTargetPropertyPropertyInfo # 
type AttrAllowedOps BindingTargetPropertyPropertyInfo #