xentara-workbench-plugin v1.0.1
The Xentara Workbench Plugin Framework
Loading...
Searching...
No Matches
xentara::workbench::bindings::PropertyHandle Class Reference

A handle for accessing a property. More...

#include <xentara/workbench/bindings/PropertyHandle.hpp>

Public Member Functions

constexpr PropertyHandle () noexcept=default
 Default constructor that constructs a null handle that does not reference a property.
 
constexpr operator bool () const noexcept
 Checks whether the handle references a property.
 
template<PropertyChangedInvocable ChangeCallback>
auto subscribe (ChangeCallback &&changeCallback) const -> PropertyController::Subscription
 Subscribes to the property.
 
auto subscribe (PropertyController::SubscriptionCallbacks callbacks) const -> PropertyController::Subscription
 Subscribes to the property, with support for specialized callbacks.
 
auto publish (Action action=Action::ValueChanged, std::size_t index={}) const -> void
 Publishes a value and state change for the property.
 
auto publishValue (Action action=Action::ValueChanged, std::size_t index={}) const -> void
 Publishes a change to only the value of the property.
 
auto publishState () const -> void
 Publishes a change in the state of the property.
 
auto publishVisibility () const -> void
 Publishes a change in the visibility of the property.
 
auto state () const -> const utils::eh::expected< void, ui::String > &
 Gets the state of the property.
 
auto visible () const -> bool
 Gets the visibility of the property.
 
constexpr auto controller () const noexcept -> PropertyController &
 Gets the controller.
 
constexpr auto property () const noexcept -> const PropertyId &
 Gets the ID of the handled property.
 

Detailed Description

A handle for accessing a property.

This object allows publishing and subscribing to a property without needing access to the controller.

Constructor & Destructor Documentation

◆ PropertyHandle()

constexpr xentara::workbench::bindings::PropertyHandle::PropertyHandle ( )
constexprdefaultnoexcept

Default constructor that constructs a null handle that does not reference a property.

Member Function Documentation

◆ controller()

constexpr auto xentara::workbench::bindings::PropertyHandle::controller ( ) const -> PropertyController &
constexprnoexcept

Gets the controller.

Precondition
Must not be called on a null object
Returns
The controller

◆ operator bool()

constexpr xentara::workbench::bindings::PropertyHandle::operator bool ( ) const
explicitconstexprnoexcept

Checks whether the handle references a property.

Returns
Return true if the handle is valid, or false if this is a ID that does not reference a property.

◆ property()

constexpr auto xentara::workbench::bindings::PropertyHandle::property ( ) const -> const PropertyId &
constexprnoexcept

Gets the ID of the handled property.

Precondition
Must not be called on a null object
Returns
The property ID

◆ publish()

auto xentara::workbench::bindings::PropertyHandle::publish ( Action  action = Action::ValueChanged,
std::size_t  index = {} 
) const -> void

Publishes a value and state change for the property.

This function publishes both a value and a state change. To publish value and state changes separately, use publishValue() and publishState(), respectively. A visibility change is not published.

It is safe to call this function on a null handle. If the handle is null, the function will do nothing.

Parameters
actionThe action that is being published
indexThe index of the element that changed. This parameter is ignored if action is Action::ValueChanged.

◆ publishState()

auto xentara::workbench::bindings::PropertyHandle::publishState ( ) const -> void

Publishes a change in the state of the property.

◆ publishValue()

auto xentara::workbench::bindings::PropertyHandle::publishValue ( Action  action = Action::ValueChanged,
std::size_t  index = {} 
) const -> void

Publishes a change to only the value of the property.

Parameters
actionThe action that is being published
indexThe index of the element that changed. This parameter is ignored if action is Action::ValueChanged.

◆ publishVisibility()

auto xentara::workbench::bindings::PropertyHandle::publishVisibility ( ) const -> void

Publishes a change in the visibility of the property.

It is safe to call this function on a null handle. If the handle is null, the function will do nothing.

Note
A change in visibility may also result in an implicit change in state, since invisible properties cannot have an error state. If the change in visibility also results in a change of state, the state will be published as well.

◆ state()

auto xentara::workbench::bindings::PropertyHandle::state ( ) const -> const utils::eh::expected<void, ui::String> &

Gets the state of the property.

Returns

The current state of the property. The state will be either a short localized text describing the error, or a default constructed expected if there is no error.

Invisible properties cannot have error states. If the property is invisible, this function will always return a default constructed expected.

◆ subscribe() [1/2]

template<PropertyChangedInvocable ChangeCallback>
auto xentara::workbench::bindings::PropertyHandle::subscribe ( ChangeCallback &&  changeCallback) const -> PropertyController::Subscription

Subscribes to the property.

It is safe to call this function on a null handle. If the handle is null, the function will return a null subscription.

Parameters
changeCallbackA callback that will be called whenever the property’s value has changed.
Returns
An automatic object that can be used to unsubscribe the subscription.

◆ subscribe() [2/2]

auto xentara::workbench::bindings::PropertyHandle::subscribe ( PropertyController::SubscriptionCallbacks  callbacks) const -> PropertyController::Subscription

Subscribes to the property, with support for specialized callbacks.

It is safe to call this function on a null handle. If the handle is null, the function will do nothing.

Parameters
callbacksThe callbacks.
Returns
An automatic object that can be used to unsubscribe the subscription.

◆ visible()

auto xentara::workbench::bindings::PropertyHandle::visible ( ) const -> bool

Gets the visibility of the property.

Returns
Returns true if the property is visible, or false if it is hidden.