Skip to main content

AbstractNotifyPropertyChanged

Struct AbstractNotifyPropertyChanged 

Source
pub struct AbstractNotifyPropertyChanged { /* private fields */ }
Expand description

The base of an object that notifies the changes of its properties (AbstractNotifyPropertyChanged).

Deviation (DEVIATIONS.md, DynamicData): upstream’s abstract class is a part that a type embeds; the type implements INotifyPropertyChanged by returning property_changed, and its setters call set_and_raise with the property name that [CallerMemberName] gives upstream (the PascalCase name of the getter, which prop! derives).

use ferroui_dynamic_data::binding::AbstractNotifyPropertyChanged;
use ferroui_system::component_model::INotifyPropertyChanged;
use ferroui_system::events::Event;
use std::cell::Cell;

#[derive(Default)]
struct Item { notify: AbstractNotifyPropertyChanged, age: Cell<i32> }
impl Item {
    fn age(&self) -> i32 { self.age.get() }
    fn set_age(&self, value: i32) { self.notify.set_and_raise(&self.age, value, "Age") }
}
impl INotifyPropertyChanged for Item {
    fn property_changed(&self) -> &Event<str> { self.notify.property_changed() }
}

let item = Item::default();
item.set_age(3);
assert_eq!(item.age(), 3);

Implementations§

Source§

impl AbstractNotifyPropertyChanged

Source

pub fn new() -> Self

A part without handlers.

Source

pub fn property_changed(&self) -> &Event<str>

The event raised when a property value has changed (PropertyChanged).

Source

pub fn on_property_changed(&self, property_name: &str)

Raises PropertyChanged for property_name; an empty name means every property (OnPropertyChanged(string? propertyName), where null is every property). Nothing is raised while the notifications are suspended.

Source

pub fn set_and_raise<T: PartialEq>( &self, field: &impl BackingField<T>, value: T, property_name: &str, )

Assigns value to field and raises PropertyChanged for property_name, unless the field already holds an equal value (SetAndRaise<T>(ref T, T, string?)).

Source

pub fn set_and_raise_with<T>( &self, field: &impl BackingField<T>, value: T, comparer: impl Fn(&T, &T) -> bool, property_name: &str, )

set_and_raise with an equality comparer (SetAndRaise<T>(ref T, T, IEqualityComparer<T>?, string?)).

Source

pub fn suspend_notifications( &self, invoke_property_changed_event_when_finished: bool, ) -> Rc<dyn IDisposable>

Suspends the notifications until the result is disposed; then, when invoke_property_changed_event_when_finished is true, raises PropertyChanged for every property (SuspendNotifications(bool invokePropertyChangeEventWhenDisposed = true)).

Deviation (DEVIATIONS.md, DynamicData): the reference checkout no longer has this member; the earlier API marked it obsolete (“This never worked properly in the first place”). It is ported from that API: the suspension is one flag, so the first disposal of nested suspensions ends it.

Trait Implementations§

Source§

impl Debug for AbstractNotifyPropertyChanged

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AbstractNotifyPropertyChanged

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl INotifyPropertyChanged for AbstractNotifyPropertyChanged

Source§

fn property_changed(&self) -> &Event<str>

The event raised when a property value changes.
Source§

fn as_notify_property_changing(&self) -> Option<&dyn INotifyPropertyChanging>

The object as INotifyPropertyChanging, when it also raises the event of a property that is about to change; None by default. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.