ferroui-base 0.3.0

The base library of FerroUI: the property system, layout, input, styling, media, text, animation, data binding and the compositor
Documentation
// @generated by scripts/generate_composition.py — do not edit

//! `CompositionSimpleRadialGradientBrush` (server only).
//!
//! Schema attributes: internal.

use bitflags::bitflags;
use crate::RelativePoint;
use crate::RelativeScalar;
use crate::rendering::composition::expressions::ExpressionVariant;
use crate::rendering::composition::server::CompositionProperty;
use crate::rendering::composition::server::CompositionPropertyOf;
use crate::rendering::composition::server::IServerPropertyHost;
use crate::rendering::composition::server::ServerPropertyValue;
use crate::rendering::composition::server::ServerValueChange;
use crate::rendering::composition::server::props_of;
use crate::rendering::composition::transport::BatchStreamReader;
use crate::rendering::composition::transport::BatchStreamWriter;
use crate::rendering::composition::transport::BatchValue;
use crate::rendering::composition::transport::BatchValueReader;
use std::any::Any;
use std::any::TypeId;
use std::cell::Cell;
use std::sync::OnceLock;
use std::time::Duration;

bitflags! {
    /// The fields of `CompositionSimpleRadialGradientBrush` that changed since its last serialization.
    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
    pub struct CompositionSimpleRadialGradientBrushChangedFields: u8 {
        const CENTER = 1;
        const GRADIENT_ORIGIN = 2;
        const RADIUS_X = 4;
        const RADIUS_Y = 8;
    }
}

impl BatchValue for CompositionSimpleRadialGradientBrushChangedFields {
    #[inline]
    fn write_to(&self, out: &mut Vec<u8>) {
        self.bits().write_to(out);
    }

    #[inline]
    fn read_from(input: &mut BatchValueReader<'_>) -> Self {
        CompositionSimpleRadialGradientBrushChangedFields::from_bits_retain(u8::read_from(input))
    }
}

/// The partial methods of `ServerCompositionSimpleRadialGradientBrush`: implemented by the class that embeds
/// [`ServerCompositionSimpleRadialGradientBrushProps`]. Every hook defaults to doing nothing.
pub trait ServerCompositionSimpleRadialGradientBrushHooks: IServerPropertyHost {
    /// `base.DeserializeChangesCore(reader, committedAt)`: reads the changes of
    /// the hand-written base class `ServerCompositionSimpleGradientBrush`.
    fn base_deserialize_changes_core(&self, reader: &mut BatchStreamReader<'_>, committed_at: Duration);

    fn deserialize_changes_extra(&self, _reader: &mut BatchStreamReader<'_>) {}
    fn on_fields_deserialized(&self, _changed: CompositionSimpleRadialGradientBrushChangedFields) {}

    fn on_center_changed(&self) {}
    fn on_center_changing(&self) {}

    fn on_gradient_origin_changed(&self) {}
    fn on_gradient_origin_changing(&self) {}

    fn on_radius_x_changed(&self) {}
    fn on_radius_x_changing(&self) {}

    fn on_radius_y_changed(&self) {}
    fn on_radius_y_changing(&self) {}
}

/// The server-side properties of `ServerCompositionSimpleRadialGradientBrush`.
pub struct ServerCompositionSimpleRadialGradientBrushProps {
    center: Cell<RelativePoint>,
    gradient_origin: Cell<RelativePoint>,
    radius_x: Cell<RelativeScalar>,
    radius_y: Cell<RelativeScalar>,
}

impl Default for ServerCompositionSimpleRadialGradientBrushProps {
    fn default() -> Self {
        Self::new()
    }
}

impl ServerCompositionSimpleRadialGradientBrushProps {
    /// Creates the properties with every field at the default of its type; the
    /// values of the UI thread arrive with the first batch.
    pub fn new() -> Self {
        Self {
            center: Cell::new(Default::default()),
            gradient_origin: Cell::new(Default::default()),
            radius_x: Cell::new(Default::default()),
            radius_y: Cell::new(Default::default()),
        }
    }

    /// This block or the block of a base class, by type: what
    /// `IServerObject::get_props` of the embedding class returns.
    pub fn find_props(&self, type_id: TypeId) -> Option<&dyn Any> {
        if type_id == TypeId::of::<Self>() {
            return Some(self);
        }
        None
    }

    /// The composition property of `Center`.
    pub fn id_of_center_property() -> &'static CompositionPropertyOf<RelativePoint> {
        static PROPERTY: OnceLock<CompositionPropertyOf<RelativePoint>> = OnceLock::new();
        PROPERTY.get_or_init(|| {
            CompositionProperty::register::<ServerCompositionSimpleRadialGradientBrushProps, RelativePoint>(
                "Center",
                "ServerCompositionSimpleRadialGradientBrush",
                |obj| props_of::<ServerCompositionSimpleRadialGradientBrushProps>(obj).center.get(),
                |obj, v| props_of::<ServerCompositionSimpleRadialGradientBrushProps>(obj).center.set(v),
                Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionSimpleRadialGradientBrushProps>(obj).center.get())),
                None,
            )
        })
    }

    /// `Center`.
    pub fn center(&self) -> RelativePoint {
        self.center.get()
    }

    pub fn set_center(&self, host: &dyn ServerCompositionSimpleRadialGradientBrushHooks, value: RelativePoint) {
        let old_value = self.center.get();
        let mut changed = false;
        if old_value.differs(&value) {
            ServerCompositionSimpleRadialGradientBrushHooks::on_center_changing(host);
            changed = true;
        }
        host.set_value(
            Self::id_of_center_property().base(),
            ServerValueChange {
                equal: old_value.default_equals(&value),
                old_resource: None,
                new_resource: None,
                assign: &mut || self.center.set(value),
            },
        );
        if changed {
            ServerCompositionSimpleRadialGradientBrushHooks::on_center_changed(host);
        }
    }

    /// The composition property of `GradientOrigin`.
    pub fn id_of_gradient_origin_property() -> &'static CompositionPropertyOf<RelativePoint> {
        static PROPERTY: OnceLock<CompositionPropertyOf<RelativePoint>> = OnceLock::new();
        PROPERTY.get_or_init(|| {
            CompositionProperty::register::<ServerCompositionSimpleRadialGradientBrushProps, RelativePoint>(
                "GradientOrigin",
                "ServerCompositionSimpleRadialGradientBrush",
                |obj| props_of::<ServerCompositionSimpleRadialGradientBrushProps>(obj).gradient_origin.get(),
                |obj, v| props_of::<ServerCompositionSimpleRadialGradientBrushProps>(obj).gradient_origin.set(v),
                Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionSimpleRadialGradientBrushProps>(obj).gradient_origin.get())),
                None,
            )
        })
    }

    /// `GradientOrigin`.
    pub fn gradient_origin(&self) -> RelativePoint {
        self.gradient_origin.get()
    }

    pub fn set_gradient_origin(&self, host: &dyn ServerCompositionSimpleRadialGradientBrushHooks, value: RelativePoint) {
        let old_value = self.gradient_origin.get();
        let mut changed = false;
        if old_value.differs(&value) {
            ServerCompositionSimpleRadialGradientBrushHooks::on_gradient_origin_changing(host);
            changed = true;
        }
        host.set_value(
            Self::id_of_gradient_origin_property().base(),
            ServerValueChange {
                equal: old_value.default_equals(&value),
                old_resource: None,
                new_resource: None,
                assign: &mut || self.gradient_origin.set(value),
            },
        );
        if changed {
            ServerCompositionSimpleRadialGradientBrushHooks::on_gradient_origin_changed(host);
        }
    }

    /// The composition property of `RadiusX`.
    pub fn id_of_radius_x_property() -> &'static CompositionPropertyOf<RelativeScalar> {
        static PROPERTY: OnceLock<CompositionPropertyOf<RelativeScalar>> = OnceLock::new();
        PROPERTY.get_or_init(|| {
            CompositionProperty::register::<ServerCompositionSimpleRadialGradientBrushProps, RelativeScalar>(
                "RadiusX",
                "ServerCompositionSimpleRadialGradientBrush",
                |obj| props_of::<ServerCompositionSimpleRadialGradientBrushProps>(obj).radius_x.get(),
                |obj, v| props_of::<ServerCompositionSimpleRadialGradientBrushProps>(obj).radius_x.set(v),
                Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionSimpleRadialGradientBrushProps>(obj).radius_x.get())),
                None,
            )
        })
    }

    /// `RadiusX`.
    pub fn radius_x(&self) -> RelativeScalar {
        self.radius_x.get()
    }

    pub fn set_radius_x(&self, host: &dyn ServerCompositionSimpleRadialGradientBrushHooks, value: RelativeScalar) {
        let old_value = self.radius_x.get();
        let mut changed = false;
        if old_value.differs(&value) {
            ServerCompositionSimpleRadialGradientBrushHooks::on_radius_x_changing(host);
            changed = true;
        }
        host.set_value(
            Self::id_of_radius_x_property().base(),
            ServerValueChange {
                equal: old_value.default_equals(&value),
                old_resource: None,
                new_resource: None,
                assign: &mut || self.radius_x.set(value),
            },
        );
        if changed {
            ServerCompositionSimpleRadialGradientBrushHooks::on_radius_x_changed(host);
        }
    }

    /// The composition property of `RadiusY`.
    pub fn id_of_radius_y_property() -> &'static CompositionPropertyOf<RelativeScalar> {
        static PROPERTY: OnceLock<CompositionPropertyOf<RelativeScalar>> = OnceLock::new();
        PROPERTY.get_or_init(|| {
            CompositionProperty::register::<ServerCompositionSimpleRadialGradientBrushProps, RelativeScalar>(
                "RadiusY",
                "ServerCompositionSimpleRadialGradientBrush",
                |obj| props_of::<ServerCompositionSimpleRadialGradientBrushProps>(obj).radius_y.get(),
                |obj, v| props_of::<ServerCompositionSimpleRadialGradientBrushProps>(obj).radius_y.set(v),
                Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionSimpleRadialGradientBrushProps>(obj).radius_y.get())),
                None,
            )
        })
    }

    /// `RadiusY`.
    pub fn radius_y(&self) -> RelativeScalar {
        self.radius_y.get()
    }

    pub fn set_radius_y(&self, host: &dyn ServerCompositionSimpleRadialGradientBrushHooks, value: RelativeScalar) {
        let old_value = self.radius_y.get();
        let mut changed = false;
        if old_value.differs(&value) {
            ServerCompositionSimpleRadialGradientBrushHooks::on_radius_y_changing(host);
            changed = true;
        }
        host.set_value(
            Self::id_of_radius_y_property().base(),
            ServerValueChange {
                equal: old_value.default_equals(&value),
                old_resource: None,
                new_resource: None,
                assign: &mut || self.radius_y.set(value),
            },
        );
        if changed {
            ServerCompositionSimpleRadialGradientBrushHooks::on_radius_y_changed(host);
        }
    }

    /// Reads the changes of the object: the base class first, then the
    /// changed-fields mask and the changed members of this class.
    pub fn deserialize_changes_core(
        &self,
        host: &dyn ServerCompositionSimpleRadialGradientBrushHooks,
        reader: &mut BatchStreamReader<'_>,
        committed_at: Duration,
    ) {
        ServerCompositionSimpleRadialGradientBrushHooks::base_deserialize_changes_core(host, reader, committed_at);
        ServerCompositionSimpleRadialGradientBrushHooks::deserialize_changes_extra(host, reader);
        let changed = reader.read::<CompositionSimpleRadialGradientBrushChangedFields>();
        if changed.contains(CompositionSimpleRadialGradientBrushChangedFields::CENTER) {
            let value = reader.read::<RelativePoint>();
            self.set_center(host, value);
        }
        if changed.contains(CompositionSimpleRadialGradientBrushChangedFields::GRADIENT_ORIGIN) {
            let value = reader.read::<RelativePoint>();
            self.set_gradient_origin(host, value);
        }
        if changed.contains(CompositionSimpleRadialGradientBrushChangedFields::RADIUS_X) {
            let value = reader.read::<RelativeScalar>();
            self.set_radius_x(host, value);
        }
        if changed.contains(CompositionSimpleRadialGradientBrushChangedFields::RADIUS_Y) {
            let value = reader.read::<RelativeScalar>();
            self.set_radius_y(host, value);
        }
        ServerCompositionSimpleRadialGradientBrushHooks::on_fields_deserialized(host, changed);
    }

    /// Writes every property of the class, in the form
    /// [`deserialize_changes_core`](Self::deserialize_changes_core) reads.
    pub fn serialize_all_changes(
        writer: &mut BatchStreamWriter<'_>,
        center: RelativePoint,
        gradient_origin: RelativePoint,
        radius_x: RelativeScalar,
        radius_y: RelativeScalar,
    ) {
        writer.write(CompositionSimpleRadialGradientBrushChangedFields::CENTER | CompositionSimpleRadialGradientBrushChangedFields::GRADIENT_ORIGIN | CompositionSimpleRadialGradientBrushChangedFields::RADIUS_X | CompositionSimpleRadialGradientBrushChangedFields::RADIUS_Y);
        writer.write(center);
        writer.write(gradient_origin);
        writer.write(radius_x);
        writer.write(radius_y);
    }
}