Struct embedded_graphics::primitives::Styled
source · [−]pub struct Styled<T, S> {
pub primitive: T,
pub style: S,
}
Expand description
Styled.
Fields
primitive: T
Primitive.
style: S
Style.
Implementations
sourceimpl<T: OffsetOutline, C: PixelColor> Styled<T, PrimitiveStyle<C>>
impl<T: OffsetOutline, C: PixelColor> Styled<T, PrimitiveStyle<C>>
sourcepub fn fill_area(&self) -> T
pub fn fill_area(&self) -> T
Returns the fill area.
The returned primitive coincides with the area that would be filled by calling draw
on this styled primitive.
Examples
use embedded_graphics::{
pixelcolor::Rgb888,
prelude::*,
primitives::{Circle, PrimitiveStyleBuilder},
};
let style = PrimitiveStyleBuilder::new()
.fill_color(Rgb888::RED)
.stroke_color(Rgb888::GREEN)
.stroke_width(6)
.build();
let center = Point::new(10, 20);
let diameter = 10;
let circle = Circle::with_center(center, diameter).into_styled(style);
assert_eq!(circle.fill_area(), Circle::with_center(center, diameter - style.stroke_width));
sourcepub fn stroke_area(&self) -> T
pub fn stroke_area(&self) -> T
Returns the stroke area.
The outer edge of the returned primitive coincides with the outer edge of the stroke that
would be drawn by calling draw
on this styled primitive.
Examples
This example tests if a point lies on the stroke. Because the stoke area surrounds the stoke and fill an additional test is required to check that the point is not inside the fill area.
use embedded_graphics::{
pixelcolor::Rgb888,
prelude::*,
primitives::{Circle, PrimitiveStyle},
};
let style = PrimitiveStyle::with_stroke(Rgb888::RED, 6);
let center = Point::new(10, 20);
let diameter = 10;
let circle = Circle::with_center(center, diameter).into_styled(style);
// A point lies on the stroke if it is inside the stroke area but not in the fill area.
let is_on_stroke = |p| circle.stroke_area().contains(p) && !circle.fill_area().contains(p);
assert!(is_on_stroke(center + Size::new(0, diameter / 2)));
assert!(!is_on_stroke(center));
Trait Implementations
sourceimpl<T: StyledDimensions<S>, S> Dimensions for Styled<T, S>
impl<T: StyledDimensions<S>, S> Dimensions for Styled<T, S>
sourcefn bounding_box(&self) -> Rectangle
fn bounding_box(&self) -> Rectangle
Returns the bounding box.
sourceimpl<T: StyledDrawable<S>, S> Drawable for Styled<T, S>
impl<T: StyledDrawable<S>, S> Drawable for Styled<T, S>
sourceimpl<T: Ord, S: Ord> Ord for Styled<T, S>
impl<T: Ord, S: Ord> Ord for Styled<T, S>
sourceimpl<T: PartialOrd, S: PartialOrd> PartialOrd<Styled<T, S>> for Styled<T, S>
impl<T: PartialOrd, S: PartialOrd> PartialOrd<Styled<T, S>> for Styled<T, S>
sourcefn partial_cmp(&self, other: &Styled<T, S>) -> Option<Ordering>
fn partial_cmp(&self, other: &Styled<T, S>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<T: Copy, S: Copy> Copy for Styled<T, S>
impl<T: Eq, S: Eq> Eq for Styled<T, S>
impl<T, S> StructuralEq for Styled<T, S>
impl<T, S> StructuralPartialEq for Styled<T, S>
Auto Trait Implementations
impl<T, S> RefUnwindSafe for Styled<T, S> where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S> Send for Styled<T, S> where
S: Send,
T: Send,
impl<T, S> Sync for Styled<T, S> where
S: Sync,
T: Sync,
impl<T, S> Unpin for Styled<T, S> where
S: Unpin,
T: Unpin,
impl<T, S> UnwindSafe for Styled<T, S> where
S: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CheckedAs for T
impl<T> CheckedAs for T
sourcepub fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
pub fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
sourcepub fn checked_cast_from(src: Src) -> Option<Dst>
pub fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
sourceimpl<T> OverflowingAs for T
impl<T> OverflowingAs for T
sourcepub fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
pub fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
sourcepub fn overflowing_cast_from(src: Src) -> (Dst, bool)
pub fn overflowing_cast_from(src: Src) -> (Dst, bool)
OverflowingCasts the value.
sourceimpl<T> SaturatingAs for T
impl<T> SaturatingAs for T
sourcepub fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
pub fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
sourcepub fn saturating_cast_from(src: Src) -> Dst
pub fn saturating_cast_from(src: Src) -> Dst
Casts the value.
sourceimpl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
sourcepub fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
pub fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
sourcepub fn unwrapped_cast_from(src: Src) -> Dst
pub fn unwrapped_cast_from(src: Src) -> Dst
UnwrappedCasts the value.
sourceimpl<T> WrappingAs for T
impl<T> WrappingAs for T
sourcepub fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
pub fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
sourcepub fn wrapping_cast_from(src: Src) -> Dst
pub fn wrapping_cast_from(src: Src) -> Dst
WrappingCasts the value.