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

//! `CompositionContainerVisual`.

use crate::rendering::composition::animations::ICompositionAnimation;
use crate::rendering::composition::expressions::ExpressionVariant;
use crate::rendering::composition::server::CompositionProperty;
use crate::rendering::composition::transport::BatchStreamReader;
use crate::rendering::composition::transport::BatchStreamWriter;
use std::any::Any;
use std::any::TypeId;
use std::time::Duration;
use super::CompositionVisualHooks;
use super::CompositionVisualProps;
use super::ServerCompositionVisualHooks;
use super::ServerCompositionVisualProps;

/// The partial methods of `CompositionContainerVisual`: implemented by the class that embeds
/// [`CompositionContainerVisualProps`]. Every hook defaults to doing nothing.
pub trait CompositionContainerVisualHooks: CompositionVisualHooks {
    fn initialize_defaults_extra(&self) {}
}

/// The UI-thread properties of `CompositionContainerVisual`.
pub struct CompositionContainerVisualProps {
    base: CompositionVisualProps,
}

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

impl CompositionContainerVisualProps {
    /// Creates the properties with every field at the default of its type.
    /// The defaults of the schema are applied by
    /// [`initialize_defaults`](Self::initialize_defaults).
    pub fn new() -> Self {
        Self {
            base: CompositionVisualProps::new(),
        }
    }

    /// The properties of the base class.
    pub fn base(&self) -> &CompositionVisualProps {
        &self.base
    }

    /// The `InitializeDefaults` calls of the constructor chain: the base
    /// classes first, then this class.
    pub fn initialize_defaults(&self, host: &dyn CompositionContainerVisualHooks) {
        self.base.initialize_defaults(host);
        self.initialize_own_defaults(host);
    }

    /// `InitializeDefaults` of this class alone.
    pub fn initialize_own_defaults(&self, host: &dyn CompositionContainerVisualHooks) {
        CompositionContainerVisualHooks::initialize_defaults_extra(host);
    }

    /// Connects an animation with the named property. Returns `false` when
    /// neither this class nor its generated bases have an animated property
    /// of that name: the caller continues with its hand-written base.
    pub fn start_animation(
        &self,
        host: &dyn CompositionContainerVisualHooks,
        property_name: &str,
        animation: &dyn ICompositionAnimation,
        final_value: Option<ExpressionVariant>,
    ) -> bool {
        self.base.start_animation(host, property_name, animation, final_value)
    }

    /// Writes the changes of the object: the base class first, then the
    /// changed-fields mask and the changed members of this class.
    pub fn serialize_changes_core(&self, host: &dyn CompositionContainerVisualHooks, writer: &mut BatchStreamWriter<'_>) {
        self.base.serialize_changes_core(host, writer);
    }
}

/// The partial methods of `ServerCompositionContainerVisual`: implemented by the class that embeds
/// [`ServerCompositionContainerVisualProps`]. Every hook defaults to doing nothing.
pub trait ServerCompositionContainerVisualHooks: ServerCompositionVisualHooks {
}

/// The server-side properties of `ServerCompositionContainerVisual`.
pub struct ServerCompositionContainerVisualProps {
    base: ServerCompositionVisualProps,
}

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

impl ServerCompositionContainerVisualProps {
    /// 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 {
            base: ServerCompositionVisualProps::new(),
        }
    }

    /// The properties of the base class.
    pub fn base(&self) -> &ServerCompositionVisualProps {
        &self.base
    }

    /// 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);
        }
        self.base.find_props(type_id)
    }

    /// 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 ServerCompositionContainerVisualHooks,
        reader: &mut BatchStreamReader<'_>,
        committed_at: Duration,
    ) {
        self.base.deserialize_changes_core(host, reader, committed_at);
    }

    /// The composition property with the given name, among the properties
    /// of this class and of its generated bases that have a variant form.
    pub fn get_composition_property(name: &str) -> Option<&'static CompositionProperty> {
        ServerCompositionVisualProps::get_composition_property(name)
    }
}