-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows using `Canvas` as an `embedded-graphics` draw target. It requires the `embedded-graphics` feature which is enabled by default. Also included is an `embedded-graphics` example based on the embedded-graphics "Hello world" example.
- Loading branch information
Showing
7 changed files
with
367 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
//! embedded-graphics example for Flipper Zero. | ||
//! This is based off the embedded-graphics "hello-world" example. | ||
#![no_main] | ||
#![no_std] | ||
|
||
// Required for panic handler | ||
extern crate flipperzero_rt; | ||
|
||
// embedded-graphics requires a global allocator. | ||
extern crate flipperzero_alloc; | ||
|
||
use core::ffi::CStr; | ||
use core::time::Duration; | ||
|
||
use flipperzero::furi::thread::sleep; | ||
use flipperzero::gui::Gui; | ||
use flipperzero_rt::{entry, manifest}; | ||
|
||
use embedded_graphics::mono_font::{ascii::FONT_6X10, MonoTextStyle}; | ||
use embedded_graphics::pixelcolor::BinaryColor; | ||
use embedded_graphics::prelude::*; | ||
use embedded_graphics::primitives::{ | ||
Circle, PrimitiveStyle, PrimitiveStyleBuilder, Rectangle, StrokeAlignment, Triangle, | ||
}; | ||
use embedded_graphics::text::{Alignment, Text}; | ||
|
||
// Define the FAP Manifest for this application | ||
manifest!( | ||
name = "Embedded Graphics", | ||
app_version = 1, | ||
has_icon = true, | ||
// See `docs/icons.md` for icon format | ||
icon = "icons/rustacean-10x10.icon", | ||
); | ||
|
||
// Define the entry function | ||
entry!(main); | ||
|
||
// Entry point | ||
fn main(_args: Option<&CStr>) -> i32 { | ||
let gui = Gui::open(); | ||
let mut canvas = gui.direct_draw_acquire(); | ||
|
||
// Create styles used by the drawing operations. | ||
let thin_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 1); | ||
let thick_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 3); | ||
let border_stroke = PrimitiveStyleBuilder::new() | ||
.stroke_color(BinaryColor::On) | ||
.stroke_width(3) | ||
.stroke_alignment(StrokeAlignment::Inside) | ||
.build(); | ||
let fill = PrimitiveStyle::with_fill(BinaryColor::On); | ||
let character_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On); | ||
|
||
let yoffset = 14; | ||
|
||
// Draw a 3px wide outline around the display. | ||
canvas | ||
.bounding_box() | ||
.into_styled(border_stroke) | ||
.draw(&mut *canvas) | ||
.unwrap(); | ||
|
||
// Draw a triangle. | ||
Triangle::new( | ||
Point::new(16, 16 + yoffset), | ||
Point::new(16 + 16, 16 + yoffset), | ||
Point::new(16 + 8, yoffset), | ||
) | ||
.into_styled(thin_stroke) | ||
.draw(&mut *canvas) | ||
.unwrap(); | ||
|
||
// Draw a filled square | ||
Rectangle::new(Point::new(52, yoffset), Size::new(16, 16)) | ||
.into_styled(fill) | ||
.draw(&mut *canvas) | ||
.unwrap(); | ||
|
||
// Draw a circle with a 3px wide stroke. | ||
Circle::new(Point::new(88, yoffset), 17) | ||
.into_styled(thick_stroke) | ||
.draw(&mut *canvas) | ||
.unwrap(); | ||
|
||
// Draw centered text. | ||
let text = "embedded-graphics"; | ||
Text::with_alignment( | ||
text, | ||
canvas.bounding_box().center() + Point::new(0, 15), | ||
character_style, | ||
Alignment::Center, | ||
) | ||
.draw(&mut *canvas) | ||
.unwrap(); | ||
|
||
// You must commit the canvas for it to display on screen. | ||
canvas.commit(); | ||
|
||
// Show for a few seconds, then exit. | ||
sleep(Duration::from_secs(5)); | ||
|
||
0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.