Skip to main content

ButtonDecoration

Trait ButtonDecoration 

Source
pub trait ButtonDecoration {
    // Provided methods
    fn paint_fill(
        &self,
        _surface: &ButtonSurface,
        _scene: &mut dyn PaintScene,
    ) -> DecorationOutcome { ... }
    fn paint_overlay(
        &self,
        _surface: &ButtonSurface,
        _scene: &mut dyn PaintScene,
    ) -> DecorationOutcome { ... }
    fn paint_outline(
        &self,
        _surface: &ButtonSurface,
        _scene: &mut dyn PaintScene,
    ) -> DecorationOutcome { ... }
    fn foreground_brush(&self, _surface: &ButtonSurface) -> Option<Brush> { ... }
}
Expand description

The paint-time decoration seam — where the reference’s m3eGradientSurfaceBuilder fill/overlay/outline layers (plus m3eGradientForegroundBuilder’s separate content layer) attach. See super::gradient for the built-in ButtonDecoration implementation that fills every hook with gradient paint.

The first three methods default to DecorationOutcome::Skipped, so an implementation overrides only the layers it draws and a button with no decoration behaves exactly as if this trait did not exist. They fire in paint order — fill, overlay, outline — each with the same ButtonSurface, whose radius is the morph’s live value rather than a resting token (the reference threads animatedRadius into its own builders for the same reason: a gradient must clip to the shape actually painted). Self::foreground_brush is shaped differently — see its own doc.

Provided Methods§

Source

fn paint_fill( &self, _surface: &ButtonSurface, _scene: &mut dyn PaintScene, ) -> DecorationOutcome

Paint the container fill. DecorationOutcome::Painted suppresses the core’s own solid fill.

Source

fn paint_overlay( &self, _surface: &ButtonSurface, _scene: &mut dyn PaintScene, ) -> DecorationOutcome

Paint an overlay above the fill. DecorationOutcome::Painted suppresses the core’s own interaction state layer — mirroring m3e_button_style.dart:47, where a gradient overlay forces overlayColor to transparent so the two never stack.

Source

fn paint_outline( &self, _surface: &ButtonSurface, _scene: &mut dyn PaintScene, ) -> DecorationOutcome

Paint the outline. DecorationOutcome::Painted suppresses the core’s own hairline.

Source

fn foreground_brush(&self, _surface: &ButtonSurface) -> Option<Brush>

Resolve a Brush (solid or gradient) to paint the label’s ink with, replacing the core’s own per-variant/per-state solid content color — where the reference’s foregroundGradient attaches (m3eGradientForegroundBuilder, m3e_button_content.dart:157).

Upstream applies this through ShaderMask + BlendMode.srcIn over the whole assembled content (icon and label together): the shader only shows through pixels the content already painted opaque, which is why upstream’s _resolveForegroundColor first forces the underlying paint to opaque white when a foreground gradient is set (m3e_button_style.dart:58) — srcIn discards that color anyway and keeps only its alpha. This port has no srcIn-style masking primitive in PaintScene, but the label’s own glyph runs already carry a Brush (never just a solid color) and paint only their covered glyph pixels either way — brushing a run with a gradient directly is pixel-equivalent to srcIn-masking a solid-ink run with the same gradient, no synthetic white layer needed. The leading/trailing icon is a nested frust::authoring::ChildPod this seam has no color-override reach into, so v1 narrows the foreground gradient to the label only — a documented gap (see super::gradient’s module doc), not a silent drop.

Shaped as a resolver rather than a paint callback (unlike the three hooks above): the label’s shaped glyph geometry is core-private — cached lazily against the exact style it was last shaped in — so only the core can safely re-emit it. This hook supplies the brush; the core does the drawing, right where it would otherwise paint the label in its own resolved solid ink. None (the default) leaves that solid ink untouched.

Resolve any gradient geometry against surface.origin/surface.size in window space, exactly like Self::paint_fill/Self::paint_outline do — the core re-expresses it relative to the label’s own glyph-run transform before painting (see [super::gradient::brush_relative_to_run_origin]’s doc for why a glyph run’s brush needs that step and the other three hooks don’t).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§