Struct raqote::SolidSource
source · pub struct SolidSource {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
Expand description
A premultiplied color. i.e. r,b,g <= a
Fields§
§r: u8
§g: u8
§b: u8
§a: u8
Implementations§
source§impl SolidSource
impl SolidSource
pub fn to_u32(&self) -> u32
sourcepub fn from_unpremultiplied_argb(a: u8, r: u8, g: u8, b: u8) -> Self
pub fn from_unpremultiplied_argb(a: u8, r: u8, g: u8, b: u8) -> Self
Examples found in repository?
examples/stroke.rs (line 14)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.move_to(200., 200.);
pb.line_to(300., 300.);
pb.line_to(200., 300.);
let path = pb.finish();
dt.stroke(
&path,
&Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
&StrokeStyle {
width: 100000., // <--
..StrokeStyle::default()
},
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
More examples
examples/stroke-arc.rs (line 14)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut dt = DrawTarget::new(400, 400);
let mut pb = PathBuilder::new();
pb.arc(0., 0., 20., 0., std::f32::consts::PI);
let path = pb.finish();
dt.set_transform(&Transform::translation(50., 50.));
dt.stroke(
&path,
&Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
&StrokeStyle {
width: 40., // <--
..StrokeStyle::default()
},
&DrawOptions::new(),
);
dt.write_png("out.png").unwrap();
}
examples/text.rs (lines 8-10)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
fn main() {
let mut dt = DrawTarget::new(300, 100);
dt.clear(SolidSource::from_unpremultiplied_argb(
0xff, 0xcf, 0xcf, 0xcf,
));
let font = SystemSource::new()
.select_best_match(
&[FamilyName::Title("Roboto".into())],
&Properties::new().weight(Weight::MEDIUM),
)
.unwrap()
.load()
.unwrap();
println!("{:?}", font);
//dt.set_transform(&Transform::create_translation(50.0, 0.0));
dt.set_transform(&Transform::rotation(euclid::Angle::degrees(15.0)));
let font = font_kit::loader::Loader::from_file(&mut std::fs::File::open("res/Box3.ttf").unwrap(), 0).unwrap();
dt.draw_text(
&font,
30.,
"3",
Point::new(0., 30.),
&Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
&DrawOptions::new(),
);
dt.fill_rect(0., 35., 40., 5., &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
&DrawOptions::new() );
dt.write_png("out.png").unwrap();
}
Trait Implementations§
source§impl Clone for SolidSource
impl Clone for SolidSource
source§fn clone(&self) -> SolidSource
fn clone(&self) -> SolidSource
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for SolidSource
impl Debug for SolidSource
source§impl From<Color> for SolidSource
impl From<Color> for SolidSource
source§impl From<SolidSource> for Source<'_>
impl From<SolidSource> for Source<'_>
source§fn from(other: SolidSource) -> Self
fn from(other: SolidSource) -> Self
Converts to this type from the input type.
source§impl PartialEq for SolidSource
impl PartialEq for SolidSource
source§fn eq(&self, other: &SolidSource) -> bool
fn eq(&self, other: &SolidSource) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl Copy for SolidSource
impl StructuralPartialEq for SolidSource
Auto Trait Implementations§
impl Freeze for SolidSource
impl RefUnwindSafe for SolidSource
impl Send for SolidSource
impl Sync for SolidSource
impl Unpin for SolidSource
impl UnwindSafe for SolidSource
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
Mutably borrows from an owned value. Read more