Skip to main content

Background

Struct Background 

Source
pub struct Background { /* private fields */ }
Expand description

A background: a solid colour, one of the two procedural patterns, or a linear / radial / conic gradient of up to GRADIENT_STOPS stops, optionally repeating and optionally tiled across the box.

The layout is the GPU layout — see the Quad word map in scene.rs and the hand-mirrored struct Background in each backend’s shader. Adding a field here is a six-file change; the checklist is on Quad.

Implementations§

Source§

impl Background

Source

pub fn as_solid(&self) -> Option<Hsla>

Returns the solid color if this is a solid background, None otherwise.

Source

pub fn color_space(self, color_space: ColorSpace) -> Self

Use specified color space for color interpolation.

https://developer.mozilla.org/en-US/docs/Web/CSS/color-interpolation-method

Source

pub fn opacity(&self, factor: f32) -> Self

Returns a new background color with the same hue, saturation, and lightness, but with a modified alpha value.

Source

pub fn is_transparent(&self) -> bool

Returns whether the background color is transparent.

Source

pub fn live_stops(&self) -> &[LinearColorStop]

The stops that actually take part in the ramp.

Source

pub fn repeating(self, on: bool) -> Self

Restarts the ramp every period instead of clamping at the ends — repeating-linear-gradient() and its radial and conic siblings.

Source

pub fn tiled( self, size: (f32, f32), size_fraction: (bool, bool), offset: (f32, f32), offset_fraction: (bool, bool), repeat: (bool, bool), ) -> Self

Evaluates the gradient inside one tile and paves the box with copies of it — CSS’s background-size + background-position + background-repeat.

Each of the four numbers is a length in pixels unless its *_fraction flag is set, when a SIZE is a fraction of the box and an OFFSET is a fraction of the space the tile leaves in it (which is what a percentage background-position means). A zero or negative size clears the tiling.

Source

pub fn is_tiled(&self) -> bool

Whether this background is painted as a repeated tile.

Source

pub fn to_corner(self, corner: u8) -> Self

Aims a linear gradient’s line at one of the box’s corners the way CSS does — 0 top right, 1 bottom right, 2 bottom left, 3 top left. The angle then depends on the box’s aspect ratio, so it is resolved in the shader rather than here.

Source

pub fn stop_in_pixels(self, index: usize) -> Self

Marks stop index’s position as an absolute length in pixels along the gradient line rather than a fraction of it.

Source

pub fn at(self, center: (f32, f32), in_pixels: bool) -> Self

Moves a radial or conic gradient’s centre — at <position>. The pair is a fraction of the box unless in_pixels, when it is an offset from the box’s top left corner.

Source

pub fn with_radii(self, radii: (f32, f32), in_pixels: bool) -> Self

Gives a radial gradient explicit radii — a fraction of the box unless in_pixels. Replaces any Background::with_extent.

Source

pub fn with_extent(self, keyword: u8, ellipse: bool) -> Self

Sizes a radial gradient by one of CSS’s four extent keywords: keyword is 1 closest-side, 2 farthest-side, 3 closest-corner, 4 farthest-corner. Replaces any Background::with_radii.

Source

pub fn with_stops(self, stops: &[LinearColorStop]) -> Self

Replaces the colour stops, keeping every other property. Stops beyond GRADIENT_STOPS are thinned from the middle.

Trait Implementations§

Source§

impl Clone for Background

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Background

Source§

impl Debug for Background

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Background

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Background

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Background

Source§

impl From<Background> for Fill

Source§

fn from(background: Background) -> Self

Converts to this type from the input type.
Source§

impl From<Hsla> for Background

Source§

fn from(value: Hsla) -> Self

Converts to this type from the input type.
Source§

impl From<Rgba> for Background

Source§

fn from(value: Rgba) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Background

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Background

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Background

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more