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
impl Background
Sourcepub fn as_solid(&self) -> Option<Hsla>
pub fn as_solid(&self) -> Option<Hsla>
Returns the solid color if this is a solid background, None otherwise.
Sourcepub fn color_space(self, color_space: ColorSpace) -> Self
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
Sourcepub fn opacity(&self, factor: f32) -> Self
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.
Sourcepub fn is_transparent(&self) -> bool
pub fn is_transparent(&self) -> bool
Returns whether the background color is transparent.
Sourcepub fn live_stops(&self) -> &[LinearColorStop]
pub fn live_stops(&self) -> &[LinearColorStop]
The stops that actually take part in the ramp.
Sourcepub fn repeating(self, on: bool) -> Self
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.
Sourcepub fn tiled(
self,
size: (f32, f32),
size_fraction: (bool, bool),
offset: (f32, f32),
offset_fraction: (bool, bool),
repeat: (bool, bool),
) -> Self
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.
Sourcepub fn to_corner(self, corner: u8) -> Self
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.
Sourcepub fn stop_in_pixels(self, index: usize) -> Self
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.
Sourcepub fn at(self, center: (f32, f32), in_pixels: bool) -> Self
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.
Sourcepub fn with_radii(self, radii: (f32, f32), in_pixels: bool) -> Self
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.
Sourcepub fn with_extent(self, keyword: u8, ellipse: bool) -> Self
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.
Sourcepub fn with_stops(self, stops: &[LinearColorStop]) -> Self
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
impl Clone for Background
impl Copy for Background
Source§impl Debug for Background
impl Debug for Background
Source§impl Default for Background
impl Default for Background
Source§impl<'de> Deserialize<'de> for Background
impl<'de> Deserialize<'de> for Background
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Background
Source§impl From<Background> for Fill
impl From<Background> for Fill
Source§fn from(background: Background) -> Self
fn from(background: Background) -> Self
Source§impl From<Hsla> for Background
impl From<Hsla> for Background
Source§impl From<Rgba> for Background
impl From<Rgba> for Background
Source§impl PartialEq for Background
impl PartialEq for Background
Source§impl Serialize for Background
impl Serialize for Background
impl StructuralPartialEq for Background
Auto Trait Implementations§
impl Forget for Background
impl Freeze for Background
impl Move for Background
impl RefUnwindSafe for Background
impl Send for Background
impl Sync for Background
impl Unpin for Background
impl UnsafeUnpin for Background
impl UnwindSafe for Background
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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