PaintCtx

Struct PaintCtx 

Source
pub struct PaintCtx<'a> { /* private fields */ }
Expand description

Context for painting by app into window.

Implementations§

Source§

impl<'a> PaintCtx<'a>

Source

pub fn d2d_factory(&self) -> &Factory

Return the raw Direct2D factory for this painting context. Note: it’s possible this will be wrapped to make it easier to port.

Source

pub fn render_target(&mut self) -> &mut GenericRenderTarget

Return the raw Direct2D RenderTarget for this painting context. Note: it’s possible this will be wrapped to make it easier to port.

Examples found in repository?
examples/hello.rs (line 42)
41    fn paint(&self, paint_ctx: &mut PaintCtx) -> bool {
42        let rt = paint_ctx.render_target();
43        let size = rt.get_size();
44        let rect = RectF::from((0.0, 0.0, size.width, size.height));
45        let bg = SolidColorBrush::create(rt).with_color(0x272822).build().unwrap();
46        let fg = SolidColorBrush::create(rt).with_color(0xf0f0ea).build().unwrap();
47        rt.fill_rectangle(rect, &bg);
48        rt.draw_line((10.0, 50.0), (90.0, 90.0),
49                &fg, 1.0, None);
50        false
51    }
More examples
Hide additional examples
examples/perftest.rs (line 50)
48    fn paint(&self, paint_ctx: &mut PaintCtx) -> bool {
49        let mut state = self.0.borrow_mut();
50        let rt = paint_ctx.render_target();
51        let size = rt.get_size();
52        let rect = RectF::from((0.0, 0.0, size.width, size.height));
53        let bg = SolidColorBrush::create(rt).with_color(0x272822).build().unwrap();
54        let fg = SolidColorBrush::create(rt).with_color(0xf0f0ea).build().unwrap();
55        rt.fill_rectangle(rect, &bg);
56
57        rt.draw_line((0.0, size.height), (size.width, 0.0), &fg, 1.0, None);
58
59        let th = ::std::f32::consts::PI * (get_time().nsec as f32) * 2e-9;
60        let dx = 100.0 * th.sin();
61        let dy = 100.0 * th.cos();
62        rt.draw_line((100.0, 100.0), (100.0 + dx, 100.0 - dy),
63            &fg, 1.0, None);
64
65        let text_format = TextFormat::create(&state.dwrite_factory)
66            .with_family("Consolas")
67            .with_size(15.0)
68            .build()
69            .unwrap();
70
71        let now = get_time();
72        let now = now.sec as f64 + 1e-9 * now.nsec as f64;
73        let msg = format!("{:3.1}ms", 1e3 * (now - state.last_time));
74        state.last_time = now;
75        rt.draw_text(
76            &msg,
77            &text_format,
78            (10.0, 210.0, 100.0, 300.0),
79            &fg,
80            default_text_options()
81        );
82
83        let msg = "Hello DWrite! This is a somewhat longer string of text intended to provoke slightly longer draw times.";
84        let dy = 15.0;
85        let x0 = 210.0;
86        let y0 = 10.0;
87        for i in 0..60 {
88            let y = y0 + (i as f32) * dy;
89            rt.draw_text(
90                msg,
91                &text_format,
92                (x0, y, x0 + 900.0, y + 80.0),
93                &fg,
94                default_text_options()
95            );
96        }
97
98    true
99    }

Auto Trait Implementations§

§

impl<'a> Freeze for PaintCtx<'a>

§

impl<'a> RefUnwindSafe for PaintCtx<'a>

§

impl<'a> Send for PaintCtx<'a>

§

impl<'a> Sync for PaintCtx<'a>

§

impl<'a> Unpin for PaintCtx<'a>

§

impl<'a> !UnwindSafe for PaintCtx<'a>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.