FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    CustomEffect

    trait · ferroui-base · v0.5.0

    trait CustomEffect: Clone + PartialEq + Default + fmt::Debug + Send + Sync + 'static
    

    An effect defined outside the framework: an immutable value of plain data (numbers, colours, points; never a live object), shared with the render thread as an ImmutableCustomEffect.

    #[derive(Clone, Debug, Default, PartialEq)]
    struct Tint { color: Color, strength: f64 }
    
    impl CustomEffect for Tint {
        const NAME: &'static str = "tint";
    
        fn for_each_parameter(&self, f: &mut dyn FnMut(&'static str, EffectParameterValue)) {
            f("color", self.color.into());
            f("strength", self.strength.into());
        }
    
        fn set_parameter(&mut self, name: &str, value: EffectParameterValue) -> bool {
            match name {
                "color" => value.as_color().map(|v| self.color = v).is_some(),
                "strength" => value.as_float().map(|v| self.strength = v).is_some(),
                _ => false,
            }
        }
    }
    
    CustomEffectRegistry::register::<Tint>()?;
    border.set_effect(Some(ImmutableCustomEffect::new(Tint { color: Colors::TEAL, strength: 0.5 }).into()));
    let parsed = Effect::parse("tint(color=#0F9D8E, strength=0.55)")?;
    

    View source

    Members

    NAME

    const NAME: &'static str
    

    The name of the effect in effect strings: tint in tint(color=#0F9D8E, strength=0.55). Letters, digits, - and _; matched ignoring case, - and _.

    Source

    for_each_parameter

    fn for_each_parameter(self: &Self, f: &mut dyn FnMut(&'static str, EffectParameterValue) -> ())
    

    Calls f with the name and the current value of each parameter, in a fixed order. Parsing finds a parameter here by name (ignoring case, - and _) and reads the text as a value of the kind of the current one.

    Source

    set_parameter

    fn set_parameter(self: &mut Self, name: &str, value: EffectParameterValue) -> bool
    

    Sets the parameter name (as for_each_parameter spells it) to value. Returns false when there is no such parameter or the value is of the wrong kind.

    Source

    padding

    fn padding(self: &Self) -> Thickness
    

    How far the output of the effect extends beyond the bounds of its content. None by default.

    Source

    neutral

    fn neutral() -> Option<Self>
    

    The value of this effect that leaves its content unchanged, if there is one. A transition from no effect to this effect (or back) interpolates from (or to) it; without one the effect switches at half of the transition.

    Source

    interpolate

    fn interpolate(self: &Self, to: &Self, progress: f64) -> Self
    

    The value at progress (0 to 1, possibly beyond with an easing that overshoots) of the way from self to to. By default each parameter interpolates by its kind (EffectParameterValue::interpolate) and the others switch at half.

    Source

    graph

    fn graph() -> Option<GraphicsEffect>
    

    The effect as an effect graph (#455, E2), in the vocabulary of the composition effects (GraphicsEffect): the description of the graph, whose source parameter content (CUSTOM_EFFECT_CONTENT) is the content of the visual the effect is set on, and whose animatable members take the values of for_each_graph_value. None (the default) for an effect without a graph.

    The description is read once per type and loaded into a graph with the checks of Compositor::create_effect_factory_with_properties; the render walk paints the graph around the content of the visual (the composed content is the source parameter content, as the children of a layer visual are the first source parameter of its effect), and every frame only sets the values of the members. A graph whose source parameters are not all content, or that does not load, is reported once (a warning in the log area Visual) and the effect is drawn as an effect without a graph.

    The content is one layer: a graph uses it once, along one path of the graph; a second use of content draws nothing, except under a source-over composite of a shadow of the content and the content itself (a glow), which is drawn as the drop shadow effect of the drawing contexts.

    Members. The animatable members are named as the animatable properties of an effect factory, EffectName.PropertyName (Tint.Color), where EffectName is the name of an effect of the graph. A value of for_each_graph_value named with a dot sets that member; a value named without one (as the parameters are) sets the one animatable member of its kind of the effect of the graph with that name: a parameter amount (a number) sets amount.Intensity of a sepia effect named amount. A number sets a scalar member, a colour a colour member; other kinds are not members.

    Source

    for_each_graph_value

    fn for_each_graph_value(self: &Self, f: &mut dyn FnMut(&'static str, EffectParameterValue) -> ())
    

    Calls f with the name and the value of each animatable member of the graph for this value, in a fixed order (the order and the names do not depend on the value). By default the parameters (for_each_parameter): each parameter is the value of the effect of the graph named after it. An effect whose members are computed from its parameters (a matrix from a strength, a clamped value) gives them here, named EffectName.PropertyName.

    Source

    cpu_reference

    fn cpu_reference(self: &Self, pixels: &mut [u8], width: usize, height: usize, scale: f64) -> bool
    

    The CPU reference of the effect (decision 3 of the plan): applies the effect to pixels, premultiplied RGBA of eight bits a channel, width by height pixels in rows of width * 4 bytes, the content drawn at scale pixels per device independent pixel over the area of the effect (its content and its padding). Returns whether the effect has a reference; false (the default) leaves the pixels unchanged.

    It is what the render tests compare the output of the GPU with, and the fallback of a backend that has no GPU program for the effect. Every effect FerroUI ships has one; an application's own effect may leave it out.

    Source

    shader

    fn shader() -> Option<ShaderEffectDescription>
    

    The effect as a runtime shader (#455, E4, decision 4 of the plan): an SkSL program for Skia and a WGSL program for Vello, with the uniform convention of ShaderEffectDescription (the size and the scale of the layer, then the parameters in the order of for_each_parameter), and whether the program samples the content or is an overlay. None (the default) for an effect without a shader.

    The description is read once per type, like the graph; a frame only sets the uniforms from the parameters of the snapshot. A program that does not compile, or whose uniforms are not those of the convention, is reported once by the backend, which then draws the content unchanged.

    Precedence. A type with both a graph and a shader is drawn as its graph: the shader is not read (and the type is drawn as an effect without a graph when the graph does not load). Every backend draws a graph; a shader needs a backend that runs programs (Skia from E4 on, Vello from E5 on).

    Source

    Trait implementations

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.