@@ -312,22 +312,24 @@ Fortunately, there is the nice `no_std`-compatible [`embedded-graphics`] crate,
312
312
313
313
``` rust ,hl_lines=3
314
314
// in kernel/src/framebuffer.rs
315
+ use embedded_graphics :: pixelcolor :: Rgb888 ;
315
316
316
317
pub struct Display {
317
- framebuffer : Framebuffer ,
318
+ framebuffer : FrameBuffer ,
318
319
}
319
320
320
321
impl Display {
321
- pub fn new (framebuffer : Framebuffer ) -> Display {
322
+ pub fn new (framebuffer : FrameBuffer ) -> Display {
322
323
Self { framebuffer }
323
324
}
324
325
325
- fn draw_pixel (& mut self , pixel : Pixel ) {
326
+ fn draw_pixel (& mut self , Pixel ( coordinates , color ) : Pixel < Rgb888 > ) {
326
327
// ignore any pixels that are out of bounds.
327
328
let (width , height ) = {
328
329
let info = self . framebuffer. info ();
329
330
(info . width, info . height)
330
331
}
332
+
331
333
if let Ok ((x @ 0 .. width , y @ 0 .. height )) = coordinates . try_into () {
332
334
let color = Color { red : color . r (), green : color . g (), blue : color . b ()};
333
335
set_pixel_in (& mut self . framebuffer, Position { x , y }, color );
@@ -336,7 +338,7 @@ impl Display {
336
338
}
337
339
338
340
impl embedded_graphics :: draw_target :: DrawTarget for Display {
339
- type Color = embedded_graphics :: pixelcolor :: Rgb888 ;
341
+ type Color = Rgb888 ;
340
342
341
343
/// Drawing operations can never fail.
342
344
type Error = core :: convert :: Infallible ;
@@ -345,9 +347,10 @@ impl embedded_graphics::draw_target::DrawTarget for Display {
345
347
where
346
348
I : IntoIterator <Item = Pixel <Self :: Color >>,
347
349
{
348
- for Pixel ( coordinates , color ) in pixels . into_iter () {
350
+ for pixel in pixels . into_iter () {
349
351
self . draw_pixel (pixel );
350
352
}
353
+
351
354
Ok (())
352
355
}
353
356
}
0 commit comments