Skip to main content

ferroui_base/media/
i_gradient_stop.rs

1use crate::media::ref_adapter::RefAdapter;
2use crate::media::{Color, GradientStop};
3use crate::{ObjectType, Ref, Upcast};
4use std::rc::Rc;
5
6/// Describes the location and color of a transition point in a gradient.
7pub trait IGradientStop: 'static {
8    /// The gradient stop color.
9    fn color(&self) -> Color;
10
11    /// The gradient stop offset.
12    fn offset(&self) -> f64;
13
14    /// The stop as a composition gradient stop, if it is one (the `is
15    /// CompositionGradientStop` test of upstream).
16    fn as_composition_gradient_stop(&self) -> Option<&crate::rendering::composition::CompositionGradientStop> {
17        None
18    }
19
20    /// Whether the stop is an [`ImmutableGradientStop`](crate::media::immutable::ImmutableGradientStop)
21    /// (the `as ImmutableGradientStop` test of upstream).
22    fn is_immutable_gradient_stop(&self) -> bool {
23        false
24    }
25}
26
27impl<T: ObjectType + Upcast<GradientStop>> IGradientStop for RefAdapter<T> {
28    #[inline]
29    fn color(&self) -> Color {
30        Upcast::<GradientStop>::upcast(&*self.0).color()
31    }
32
33    #[inline]
34    fn offset(&self) -> f64 {
35        Upcast::<GradientStop>::upcast(&*self.0).offset()
36    }
37}
38
39impl<T: ObjectType + Upcast<GradientStop>> From<Ref<T>> for Rc<dyn IGradientStop> {
40    #[inline]
41    fn from(value: Ref<T>) -> Self {
42        Rc::new(RefAdapter(value))
43    }
44}