use bitflags::bitflags;
use crate::Vector;
use crate::rendering::composition::CompositionStretch;
use crate::rendering::composition::ICompositionObjectHost;
use crate::rendering::composition::animations::AnimationInstanceFactory;
use crate::rendering::composition::animations::ICompositionAnimation;
use crate::rendering::composition::expressions::ExpressionVariant;
use crate::rendering::composition::server::CompositionProperty;
use crate::rendering::composition::server::CompositionPropertyOf;
use crate::rendering::composition::server::IServerAnimatedPropertyHost;
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! {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct CompositionViewBoxChangedFields: u16 {
const HORIZONTAL_ALIGNMENT_RATIO = 1;
const HORIZONTAL_ALIGNMENT_RATIO_ANIMATED = 2;
const OFFSET = 4;
const OFFSET_ANIMATED = 8;
const SIZE = 16;
const SIZE_ANIMATED = 32;
const STRETCH = 64;
const VERTICAL_ALIGNMENT_RATIO = 128;
const VERTICAL_ALIGNMENT_RATIO_ANIMATED = 256;
}
}
impl BatchValue for CompositionViewBoxChangedFields {
#[inline]
fn write_to(&self, out: &mut Vec<u8>) {
self.bits().write_to(out);
}
#[inline]
fn read_from(input: &mut BatchValueReader<'_>) -> Self {
CompositionViewBoxChangedFields::from_bits_retain(u16::read_from(input))
}
}
pub trait CompositionViewBoxHooks: ICompositionObjectHost {
fn initialize_defaults_extra(&self) {}
fn validate_horizontal_alignment_ratio_change(&self, _old_value: f32, _new_value: f32) {}
fn on_horizontal_alignment_ratio_changed(&self) {}
fn on_horizontal_alignment_ratio_changing(&self) {}
fn validate_offset_change(&self, _old_value: Vector, _new_value: Vector) {}
fn on_offset_changed(&self) {}
fn on_offset_changing(&self) {}
fn validate_size_change(&self, _old_value: Vector, _new_value: Vector) {}
fn on_size_changed(&self) {}
fn on_size_changing(&self) {}
fn validate_stretch_change(&self, _old_value: CompositionStretch, _new_value: CompositionStretch) {}
fn on_stretch_changed(&self) {}
fn on_stretch_changing(&self) {}
fn validate_vertical_alignment_ratio_change(&self, _old_value: f32, _new_value: f32) {}
fn on_vertical_alignment_ratio_changed(&self) {}
fn on_vertical_alignment_ratio_changing(&self) {}
}
pub struct CompositionViewBoxProps {
changed_fields_of_composition_view_box: Cell<CompositionViewBoxChangedFields>,
horizontal_alignment_ratio: Cell<f32>,
offset: Cell<Vector>,
size: Cell<Vector>,
stretch: Cell<CompositionStretch>,
vertical_alignment_ratio: Cell<f32>,
}
impl Default for CompositionViewBoxProps {
fn default() -> Self {
Self::new()
}
}
impl CompositionViewBoxProps {
pub fn new() -> Self {
Self {
changed_fields_of_composition_view_box: Cell::new(CompositionViewBoxChangedFields::empty()),
horizontal_alignment_ratio: Cell::new(Default::default()),
offset: Cell::new(Default::default()),
size: Cell::new(Default::default()),
stretch: Cell::new(Default::default()),
vertical_alignment_ratio: Cell::new(Default::default()),
}
}
pub fn initialize_defaults(&self, host: &dyn CompositionViewBoxHooks) {
self.initialize_own_defaults(host);
}
pub fn initialize_own_defaults(&self, host: &dyn CompositionViewBoxHooks) {
CompositionViewBoxHooks::initialize_defaults_extra(host);
self.set_horizontal_alignment_ratio(host, 0.5);
self.set_stretch(host, CompositionStretch::Fill);
self.set_vertical_alignment_ratio(host, 0.5);
}
pub fn horizontal_alignment_ratio(&self) -> f32 {
self.horizontal_alignment_ratio.get()
}
pub fn set_horizontal_alignment_ratio(&self, host: &dyn CompositionViewBoxHooks, value: f32) {
let mut changed = false;
let old_value = self.horizontal_alignment_ratio.get();
if old_value.differs(&value) {
CompositionViewBoxHooks::validate_horizontal_alignment_ratio_change(host, old_value, value);
CompositionViewBoxHooks::on_horizontal_alignment_ratio_changing(host);
changed = true;
self.horizontal_alignment_ratio.set(value);
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() | CompositionViewBoxChangedFields::HORIZONTAL_ALIGNMENT_RATIO);
host.register_for_serialization();
host.pending_animations().remove(ServerCompositionViewBoxProps::id_of_horizontal_alignment_ratio_property().base());
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() & !CompositionViewBoxChangedFields::HORIZONTAL_ALIGNMENT_RATIO_ANIMATED);
if let Some(animation) = host.implicit_animation("HorizontalAlignmentRatio") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() | CompositionViewBoxChangedFields::HORIZONTAL_ALIGNMENT_RATIO_ANIMATED);
host.pending_animations().set(
ServerCompositionViewBoxProps::id_of_horizontal_alignment_ratio_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "HorizontalAlignmentRatio", ExpressionVariant::create(value));
}
}
self.horizontal_alignment_ratio.set(value);
if changed {
CompositionViewBoxHooks::on_horizontal_alignment_ratio_changed(host);
}
}
pub fn offset(&self) -> Vector {
self.offset.get()
}
pub fn set_offset(&self, host: &dyn CompositionViewBoxHooks, value: Vector) {
let mut changed = false;
let old_value = self.offset.get();
if old_value.differs(&value) {
CompositionViewBoxHooks::validate_offset_change(host, old_value, value);
CompositionViewBoxHooks::on_offset_changing(host);
changed = true;
self.offset.set(value);
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() | CompositionViewBoxChangedFields::OFFSET);
host.register_for_serialization();
host.pending_animations().remove(ServerCompositionViewBoxProps::id_of_offset_property().base());
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() & !CompositionViewBoxChangedFields::OFFSET_ANIMATED);
if let Some(animation) = host.implicit_animation("Offset") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() | CompositionViewBoxChangedFields::OFFSET_ANIMATED);
host.pending_animations().set(
ServerCompositionViewBoxProps::id_of_offset_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "Offset", ExpressionVariant::create(value));
}
}
self.offset.set(value);
if changed {
CompositionViewBoxHooks::on_offset_changed(host);
}
}
pub fn size(&self) -> Vector {
self.size.get()
}
pub fn set_size(&self, host: &dyn CompositionViewBoxHooks, value: Vector) {
let mut changed = false;
let old_value = self.size.get();
if old_value.differs(&value) {
CompositionViewBoxHooks::validate_size_change(host, old_value, value);
CompositionViewBoxHooks::on_size_changing(host);
changed = true;
self.size.set(value);
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() | CompositionViewBoxChangedFields::SIZE);
host.register_for_serialization();
host.pending_animations().remove(ServerCompositionViewBoxProps::id_of_size_property().base());
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() & !CompositionViewBoxChangedFields::SIZE_ANIMATED);
if let Some(animation) = host.implicit_animation("Size") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() | CompositionViewBoxChangedFields::SIZE_ANIMATED);
host.pending_animations().set(
ServerCompositionViewBoxProps::id_of_size_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "Size", ExpressionVariant::create(value));
}
}
self.size.set(value);
if changed {
CompositionViewBoxHooks::on_size_changed(host);
}
}
pub fn stretch(&self) -> CompositionStretch {
self.stretch.get()
}
pub fn set_stretch(&self, host: &dyn CompositionViewBoxHooks, value: CompositionStretch) {
let mut changed = false;
let old_value = self.stretch.get();
if old_value.differs(&value) {
CompositionViewBoxHooks::validate_stretch_change(host, old_value, value);
CompositionViewBoxHooks::on_stretch_changing(host);
changed = true;
self.stretch.set(value);
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() | CompositionViewBoxChangedFields::STRETCH);
host.register_for_serialization();
}
self.stretch.set(value);
if changed {
CompositionViewBoxHooks::on_stretch_changed(host);
}
}
pub fn vertical_alignment_ratio(&self) -> f32 {
self.vertical_alignment_ratio.get()
}
pub fn set_vertical_alignment_ratio(&self, host: &dyn CompositionViewBoxHooks, value: f32) {
let mut changed = false;
let old_value = self.vertical_alignment_ratio.get();
if old_value.differs(&value) {
CompositionViewBoxHooks::validate_vertical_alignment_ratio_change(host, old_value, value);
CompositionViewBoxHooks::on_vertical_alignment_ratio_changing(host);
changed = true;
self.vertical_alignment_ratio.set(value);
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() | CompositionViewBoxChangedFields::VERTICAL_ALIGNMENT_RATIO);
host.register_for_serialization();
host.pending_animations().remove(ServerCompositionViewBoxProps::id_of_vertical_alignment_ratio_property().base());
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() & !CompositionViewBoxChangedFields::VERTICAL_ALIGNMENT_RATIO_ANIMATED);
if let Some(animation) = host.implicit_animation("VerticalAlignmentRatio") {
if let Some(a) = animation.as_composition_animation() {
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() | CompositionViewBoxChangedFields::VERTICAL_ALIGNMENT_RATIO_ANIMATED);
host.pending_animations().set(
ServerCompositionViewBoxProps::id_of_vertical_alignment_ratio_property().base(),
a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
);
}
host.start_animation_group(&animation, "VerticalAlignmentRatio", ExpressionVariant::create(value));
}
}
self.vertical_alignment_ratio.set(value);
if changed {
CompositionViewBoxHooks::on_vertical_alignment_ratio_changed(host);
}
}
pub fn start_animation(
&self,
host: &dyn CompositionViewBoxHooks,
property_name: &str,
animation: &dyn ICompositionAnimation,
final_value: Option<ExpressionVariant>,
) -> bool {
if property_name == "HorizontalAlignmentRatio" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerCompositionViewBoxProps::id_of_horizontal_alignment_ratio_property().base(), server);
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() | CompositionViewBoxChangedFields::HORIZONTAL_ALIGNMENT_RATIO_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "Offset" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerCompositionViewBoxProps::id_of_offset_property().base(), server);
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() | CompositionViewBoxChangedFields::OFFSET_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "Size" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerCompositionViewBoxProps::id_of_size_property().base(), server);
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() | CompositionViewBoxChangedFields::SIZE_ANIMATED);
host.register_for_serialization();
return true;
}
if property_name == "VerticalAlignmentRatio" {
let server = animation.create_instance(host.server(), final_value);
host.pending_animations().set(ServerCompositionViewBoxProps::id_of_vertical_alignment_ratio_property().base(), server);
self.changed_fields_of_composition_view_box.set(self.changed_fields_of_composition_view_box.get() | CompositionViewBoxChangedFields::VERTICAL_ALIGNMENT_RATIO_ANIMATED);
host.register_for_serialization();
return true;
}
false
}
pub fn serialize_changes_core(&self, host: &dyn CompositionViewBoxHooks, writer: &mut BatchStreamWriter<'_>) {
let changed = self.changed_fields_of_composition_view_box.get();
writer.write(changed);
if changed.contains(CompositionViewBoxChangedFields::HORIZONTAL_ALIGNMENT_RATIO_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerCompositionViewBoxProps::id_of_horizontal_alignment_ratio_property().base()));
} else if changed.contains(CompositionViewBoxChangedFields::HORIZONTAL_ALIGNMENT_RATIO) {
writer.write(self.horizontal_alignment_ratio.get());
}
if changed.contains(CompositionViewBoxChangedFields::OFFSET_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerCompositionViewBoxProps::id_of_offset_property().base()));
} else if changed.contains(CompositionViewBoxChangedFields::OFFSET) {
writer.write(self.offset.get());
}
if changed.contains(CompositionViewBoxChangedFields::SIZE_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerCompositionViewBoxProps::id_of_size_property().base()));
} else if changed.contains(CompositionViewBoxChangedFields::SIZE) {
writer.write(self.size.get());
}
if changed.contains(CompositionViewBoxChangedFields::STRETCH) {
writer.write(self.stretch.get());
}
if changed.contains(CompositionViewBoxChangedFields::VERTICAL_ALIGNMENT_RATIO_ANIMATED) {
writer.write_value(host.pending_animations().get_and_remove(ServerCompositionViewBoxProps::id_of_vertical_alignment_ratio_property().base()));
} else if changed.contains(CompositionViewBoxChangedFields::VERTICAL_ALIGNMENT_RATIO) {
writer.write(self.vertical_alignment_ratio.get());
}
self.changed_fields_of_composition_view_box.set(CompositionViewBoxChangedFields::empty());
}
}
pub trait ServerCompositionViewBoxHooks: IServerAnimatedPropertyHost {
fn deserialize_changes_extra(&self, _reader: &mut BatchStreamReader<'_>) {}
fn on_fields_deserialized(&self, _changed: CompositionViewBoxChangedFields) {}
fn on_stretch_changed(&self) {}
fn on_stretch_changing(&self) {}
}
pub struct ServerCompositionViewBoxProps {
horizontal_alignment_ratio: Cell<f32>,
offset: Cell<Vector>,
size: Cell<Vector>,
stretch: Cell<CompositionStretch>,
vertical_alignment_ratio: Cell<f32>,
}
impl Default for ServerCompositionViewBoxProps {
fn default() -> Self {
Self::new()
}
}
impl ServerCompositionViewBoxProps {
pub fn new() -> Self {
Self {
horizontal_alignment_ratio: Cell::new(Default::default()),
offset: Cell::new(Default::default()),
size: Cell::new(Default::default()),
stretch: Cell::new(Default::default()),
vertical_alignment_ratio: Cell::new(Default::default()),
}
}
pub fn find_props(&self, type_id: TypeId) -> Option<&dyn Any> {
if type_id == TypeId::of::<Self>() {
return Some(self);
}
None
}
pub fn id_of_horizontal_alignment_ratio_property() -> &'static CompositionPropertyOf<f32> {
static PROPERTY: OnceLock<CompositionPropertyOf<f32>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerCompositionViewBoxProps, f32>(
"HorizontalAlignmentRatio",
"ServerCompositionViewBox",
|obj| props_of::<ServerCompositionViewBoxProps>(obj).horizontal_alignment_ratio.get(),
|obj, v| props_of::<ServerCompositionViewBoxProps>(obj).horizontal_alignment_ratio.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionViewBoxProps>(obj).horizontal_alignment_ratio.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerCompositionViewBoxProps>(obj).horizontal_alignment_ratio.set(v.cast_or_default::<f32>())),
)
})
}
pub fn horizontal_alignment_ratio(&self) -> f32 {
self.horizontal_alignment_ratio.get()
}
pub fn set_horizontal_alignment_ratio(&self, host: &dyn ServerCompositionViewBoxHooks, value: f32) {
self.horizontal_alignment_ratio.set(value);
host.remove_animation_for_property(Self::id_of_horizontal_alignment_ratio_property().base());
}
pub fn id_of_offset_property() -> &'static CompositionPropertyOf<Vector> {
static PROPERTY: OnceLock<CompositionPropertyOf<Vector>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerCompositionViewBoxProps, Vector>(
"Offset",
"ServerCompositionViewBox",
|obj| props_of::<ServerCompositionViewBoxProps>(obj).offset.get(),
|obj, v| props_of::<ServerCompositionViewBoxProps>(obj).offset.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionViewBoxProps>(obj).offset.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerCompositionViewBoxProps>(obj).offset.set(v.cast_or_default::<Vector>())),
)
})
}
pub fn offset(&self) -> Vector {
self.offset.get()
}
pub fn set_offset(&self, host: &dyn ServerCompositionViewBoxHooks, value: Vector) {
self.offset.set(value);
host.remove_animation_for_property(Self::id_of_offset_property().base());
}
pub fn id_of_size_property() -> &'static CompositionPropertyOf<Vector> {
static PROPERTY: OnceLock<CompositionPropertyOf<Vector>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerCompositionViewBoxProps, Vector>(
"Size",
"ServerCompositionViewBox",
|obj| props_of::<ServerCompositionViewBoxProps>(obj).size.get(),
|obj, v| props_of::<ServerCompositionViewBoxProps>(obj).size.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionViewBoxProps>(obj).size.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerCompositionViewBoxProps>(obj).size.set(v.cast_or_default::<Vector>())),
)
})
}
pub fn size(&self) -> Vector {
self.size.get()
}
pub fn set_size(&self, host: &dyn ServerCompositionViewBoxHooks, value: Vector) {
self.size.set(value);
host.remove_animation_for_property(Self::id_of_size_property().base());
}
pub fn id_of_stretch_property() -> &'static CompositionPropertyOf<CompositionStretch> {
static PROPERTY: OnceLock<CompositionPropertyOf<CompositionStretch>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerCompositionViewBoxProps, CompositionStretch>(
"Stretch",
"ServerCompositionViewBox",
|obj| props_of::<ServerCompositionViewBoxProps>(obj).stretch.get(),
|obj, v| props_of::<ServerCompositionViewBoxProps>(obj).stretch.set(v),
None,
None,
)
})
}
pub fn stretch(&self) -> CompositionStretch {
self.stretch.get()
}
pub fn set_stretch(&self, host: &dyn ServerCompositionViewBoxHooks, value: CompositionStretch) {
let old_value = self.stretch.get();
let mut changed = false;
if old_value.differs(&value) {
ServerCompositionViewBoxHooks::on_stretch_changing(host);
changed = true;
}
host.set_value(
Self::id_of_stretch_property().base(),
ServerValueChange {
equal: old_value.default_equals(&value),
old_resource: None,
new_resource: None,
assign: &mut || self.stretch.set(value),
},
);
if changed {
ServerCompositionViewBoxHooks::on_stretch_changed(host);
}
}
pub fn id_of_vertical_alignment_ratio_property() -> &'static CompositionPropertyOf<f32> {
static PROPERTY: OnceLock<CompositionPropertyOf<f32>> = OnceLock::new();
PROPERTY.get_or_init(|| {
CompositionProperty::register::<ServerCompositionViewBoxProps, f32>(
"VerticalAlignmentRatio",
"ServerCompositionViewBox",
|obj| props_of::<ServerCompositionViewBoxProps>(obj).vertical_alignment_ratio.get(),
|obj, v| props_of::<ServerCompositionViewBoxProps>(obj).vertical_alignment_ratio.set(v),
Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionViewBoxProps>(obj).vertical_alignment_ratio.get())),
Some(|obj, v: ExpressionVariant| props_of::<ServerCompositionViewBoxProps>(obj).vertical_alignment_ratio.set(v.cast_or_default::<f32>())),
)
})
}
pub fn vertical_alignment_ratio(&self) -> f32 {
self.vertical_alignment_ratio.get()
}
pub fn set_vertical_alignment_ratio(&self, host: &dyn ServerCompositionViewBoxHooks, value: f32) {
self.vertical_alignment_ratio.set(value);
host.remove_animation_for_property(Self::id_of_vertical_alignment_ratio_property().base());
}
pub fn deserialize_changes_core(
&self,
host: &dyn ServerCompositionViewBoxHooks,
reader: &mut BatchStreamReader<'_>,
committed_at: Duration,
) {
ServerCompositionViewBoxHooks::deserialize_changes_extra(host, reader);
let changed = reader.read::<CompositionViewBoxChangedFields>();
if changed.contains(CompositionViewBoxChangedFields::HORIZONTAL_ALIGNMENT_RATIO_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `HorizontalAlignmentRatio` without an animation instance");
};
host.set_animated_value(
Self::id_of_horizontal_alignment_ratio_property().base(),
ExpressionVariant::create(self.horizontal_alignment_ratio.get()),
committed_at,
animation,
);
} else if changed.contains(CompositionViewBoxChangedFields::HORIZONTAL_ALIGNMENT_RATIO) {
let value = reader.read::<f32>();
self.set_horizontal_alignment_ratio(host, value);
}
if changed.contains(CompositionViewBoxChangedFields::OFFSET_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `Offset` without an animation instance");
};
host.set_animated_value(
Self::id_of_offset_property().base(),
ExpressionVariant::create(self.offset.get()),
committed_at,
animation,
);
} else if changed.contains(CompositionViewBoxChangedFields::OFFSET) {
let value = reader.read::<Vector>();
self.set_offset(host, value);
}
if changed.contains(CompositionViewBoxChangedFields::SIZE_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `Size` without an animation instance");
};
host.set_animated_value(
Self::id_of_size_property().base(),
ExpressionVariant::create(self.size.get()),
committed_at,
animation,
);
} else if changed.contains(CompositionViewBoxChangedFields::SIZE) {
let value = reader.read::<Vector>();
self.set_size(host, value);
}
if changed.contains(CompositionViewBoxChangedFields::STRETCH) {
let value = reader.read::<CompositionStretch>();
self.set_stretch(host, value);
}
if changed.contains(CompositionViewBoxChangedFields::VERTICAL_ALIGNMENT_RATIO_ANIMATED) {
let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
panic!("a batch starts an animation of `VerticalAlignmentRatio` without an animation instance");
};
host.set_animated_value(
Self::id_of_vertical_alignment_ratio_property().base(),
ExpressionVariant::create(self.vertical_alignment_ratio.get()),
committed_at,
animation,
);
} else if changed.contains(CompositionViewBoxChangedFields::VERTICAL_ALIGNMENT_RATIO) {
let value = reader.read::<f32>();
self.set_vertical_alignment_ratio(host, value);
}
ServerCompositionViewBoxHooks::on_fields_deserialized(host, changed);
}
pub fn get_composition_property(name: &str) -> Option<&'static CompositionProperty> {
if name == "HorizontalAlignmentRatio" {
return Some(Self::id_of_horizontal_alignment_ratio_property().base());
}
if name == "Offset" {
return Some(Self::id_of_offset_property().base());
}
if name == "Size" {
return Some(Self::id_of_size_property().base());
}
if name == "VerticalAlignmentRatio" {
return Some(Self::id_of_vertical_alignment_ratio_property().base());
}
None
}
}