ferroui-base 0.2.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

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

use bitflags::bitflags;
use crate::RelativePoint;
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 `CompositionSimpleLinearGradientBrush` that changed since its last serialization.
    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
    pub struct CompositionSimpleLinearGradientBrushChangedFields: u8 {
        const START_POINT = 1;
        const END_POINT = 2;
    }
}

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

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

/// The partial methods of `ServerCompositionSimpleLinearGradientBrush`: implemented by the class that embeds
/// [`ServerCompositionSimpleLinearGradientBrushProps`]. Every hook defaults to doing nothing.
pub trait ServerCompositionSimpleLinearGradientBrushHooks: 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: CompositionSimpleLinearGradientBrushChangedFields) {}

    fn on_start_point_changed(&self) {}
    fn on_start_point_changing(&self) {}

    fn on_end_point_changed(&self) {}
    fn on_end_point_changing(&self) {}
}

/// The server-side properties of `ServerCompositionSimpleLinearGradientBrush`.
pub struct ServerCompositionSimpleLinearGradientBrushProps {
    start_point: Cell<RelativePoint>,
    end_point: Cell<RelativePoint>,
}

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

impl ServerCompositionSimpleLinearGradientBrushProps {
    /// 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 {
            start_point: Cell::new(Default::default()),
            end_point: 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 `StartPoint`.
    pub fn id_of_start_point_property() -> &'static CompositionPropertyOf<RelativePoint> {
        static PROPERTY: OnceLock<CompositionPropertyOf<RelativePoint>> = OnceLock::new();
        PROPERTY.get_or_init(|| {
            CompositionProperty::register::<ServerCompositionSimpleLinearGradientBrushProps, RelativePoint>(
                "StartPoint",
                "ServerCompositionSimpleLinearGradientBrush",
                |obj| props_of::<ServerCompositionSimpleLinearGradientBrushProps>(obj).start_point.get(),
                |obj, v| props_of::<ServerCompositionSimpleLinearGradientBrushProps>(obj).start_point.set(v),
                Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionSimpleLinearGradientBrushProps>(obj).start_point.get())),
                None,
            )
        })
    }

    /// `StartPoint`.
    pub fn start_point(&self) -> RelativePoint {
        self.start_point.get()
    }

    pub fn set_start_point(&self, host: &dyn ServerCompositionSimpleLinearGradientBrushHooks, value: RelativePoint) {
        let old_value = self.start_point.get();
        let mut changed = false;
        if old_value.differs(&value) {
            ServerCompositionSimpleLinearGradientBrushHooks::on_start_point_changing(host);
            changed = true;
        }
        host.set_value(
            Self::id_of_start_point_property().base(),
            ServerValueChange {
                equal: old_value.default_equals(&value),
                old_resource: None,
                new_resource: None,
                assign: &mut || self.start_point.set(value),
            },
        );
        if changed {
            ServerCompositionSimpleLinearGradientBrushHooks::on_start_point_changed(host);
        }
    }

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

    /// `EndPoint`.
    pub fn end_point(&self) -> RelativePoint {
        self.end_point.get()
    }

    pub fn set_end_point(&self, host: &dyn ServerCompositionSimpleLinearGradientBrushHooks, value: RelativePoint) {
        let old_value = self.end_point.get();
        let mut changed = false;
        if old_value.differs(&value) {
            ServerCompositionSimpleLinearGradientBrushHooks::on_end_point_changing(host);
            changed = true;
        }
        host.set_value(
            Self::id_of_end_point_property().base(),
            ServerValueChange {
                equal: old_value.default_equals(&value),
                old_resource: None,
                new_resource: None,
                assign: &mut || self.end_point.set(value),
            },
        );
        if changed {
            ServerCompositionSimpleLinearGradientBrushHooks::on_end_point_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 ServerCompositionSimpleLinearGradientBrushHooks,
        reader: &mut BatchStreamReader<'_>,
        committed_at: Duration,
    ) {
        ServerCompositionSimpleLinearGradientBrushHooks::base_deserialize_changes_core(host, reader, committed_at);
        ServerCompositionSimpleLinearGradientBrushHooks::deserialize_changes_extra(host, reader);
        let changed = reader.read::<CompositionSimpleLinearGradientBrushChangedFields>();
        if changed.contains(CompositionSimpleLinearGradientBrushChangedFields::START_POINT) {
            let value = reader.read::<RelativePoint>();
            self.set_start_point(host, value);
        }
        if changed.contains(CompositionSimpleLinearGradientBrushChangedFields::END_POINT) {
            let value = reader.read::<RelativePoint>();
            self.set_end_point(host, value);
        }
        ServerCompositionSimpleLinearGradientBrushHooks::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<'_>,
        start_point: RelativePoint,
        end_point: RelativePoint,
    ) {
        writer.write(CompositionSimpleLinearGradientBrushChangedFields::START_POINT | CompositionSimpleLinearGradientBrushChangedFields::END_POINT);
        writer.write(start_point);
        writer.write(end_point);
    }
}