MCU backend: build with no_std

This commit is contained in:
Olivier Goffart 2021-11-30 16:30:40 +01:00 committed by Olivier Goffart
parent 6ca63aac9c
commit 691d43d416
3 changed files with 19 additions and 7 deletions

View file

@ -25,6 +25,13 @@ In order for the crate to be available at runtime, they need to be added as feat
*/ */
#![doc(html_logo_url = "https://sixtyfps.io/resources/logo.drawio.svg")] #![doc(html_logo_url = "https://sixtyfps.io/resources/logo.drawio.svg")]
#![cfg_attr(
not(any(
feature = "sixtyfps-rendering-backend-qt",
feature = "sixtyfps-rendering-backend-gl"
)),
no_std
)]
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(feature = "sixtyfps-rendering-backend-qt")] { if #[cfg(feature = "sixtyfps-rendering-backend-qt")] {

View file

@ -18,13 +18,18 @@ only be used with `version = "=x.y.z"` in Cargo.toml.
*/ */
#![doc(html_logo_url = "https://sixtyfps.io/resources/logo.drawio.svg")] #![doc(html_logo_url = "https://sixtyfps.io/resources/logo.drawio.svg")]
#![cfg_attr(not(feature = "simulator"), no_std)]
extern crate alloc;
use alloc::boxed::Box;
use alloc::rc::Rc;
use alloc::string::String;
use sixtyfps_corelib::{ use sixtyfps_corelib::{
graphics::{Image, Size}, graphics::{Image, Size},
window::Window, window::Window,
ImageInner, ImageInner,
}; };
use std::rc::Rc;
#[cfg(feature = "simulator")] #[cfg(feature = "simulator")]
mod simulator; mod simulator;
@ -33,7 +38,6 @@ mod simulator;
use simulator::*; use simulator::*;
mod renderer; mod renderer;
pub struct Backend; pub struct Backend;
impl sixtyfps_corelib::backend::Backend for Backend { impl sixtyfps_corelib::backend::Backend for Backend {
@ -101,5 +105,5 @@ pub const HAS_NATIVE_STYLE: bool = false;
pub const IS_AVAILABLE: bool = true; pub const IS_AVAILABLE: bool = true;
pub fn init() { pub fn init() {
sixtyfps_corelib::backend::instance_or_init(|| Box::new(Backend)); sixtyfps_corelib::backend::instance_or_init(|| alloc::boxed::Box::new(Backend));
} }

View file

@ -8,9 +8,10 @@
Please contact info@sixtyfps.io for more information. Please contact info@sixtyfps.io for more information.
LICENSE END */ LICENSE END */
use alloc::collections::VecDeque;
use alloc::rc::Rc;
use alloc::{vec, vec::Vec};
use core::pin::Pin; use core::pin::Pin;
use std::collections::VecDeque;
use std::rc::Rc;
use embedded_graphics::pixelcolor::Rgb888; use embedded_graphics::pixelcolor::Rgb888;
use embedded_graphics::prelude::*; use embedded_graphics::prelude::*;
@ -25,7 +26,7 @@ pub fn render_window_frame<T: DrawTarget<Color = Rgb888>>(
background: Rgb888, background: Rgb888,
display: &mut T, display: &mut T,
) where ) where
T::Error: std::fmt::Debug, T::Error: core::fmt::Debug,
{ {
let size = display.bounding_box().size; let size = display.bounding_box().size;
let mut scene = prepare_scene(runtime_window, SizeF::new(size.width as _, size.height as _)); let mut scene = prepare_scene(runtime_window, SizeF::new(size.width as _, size.height as _));
@ -244,7 +245,7 @@ struct LineCommand {
spans: Vec<SceneItem>, spans: Vec<SceneItem>,
} }
fn compare_scene_item(a: &SceneItem, b: &SceneItem) -> std::cmp::Ordering { fn compare_scene_item(a: &SceneItem, b: &SceneItem) -> core::cmp::Ordering {
// First, order by line (top to bottom) // First, order by line (top to bottom)
match a.y.partial_cmp(&b.y) { match a.y.partial_cmp(&b.y) {
None | Some(core::cmp::Ordering::Equal) => {} None | Some(core::cmp::Ordering::Equal) => {}