This commit is contained in:
2025-11-28 13:42:17 +01:00
parent 9a880c23ac
commit 3e789661ef
6 changed files with 149 additions and 142 deletions

View File

@ -1,29 +1,33 @@
#![feature(unsafe_cell_access)]
mod images;
mod triangle;
use core::fmt::Write;
use std::{cell::UnsafeCell, mem::MaybeUninit};
use std::cell::UnsafeCell;
use std::mem::MaybeUninit;
use buoyant::{primitives::Point, render::StrokedShape, view::prelude::*};
use embedded_graphics::{
pixelcolor::{Rgb565, Rgb888},
prelude::*,
};
use embedded_graphics_simulator::{OutputSettings, SimulatorDisplay, Window};
use embedded_sprites::{include_image, sprite::Sprite};
use buoyant::primitives::Point;
use buoyant::render::StrokedShape;
use buoyant::view::prelude::*;
use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::pixelcolor::Rgb888;
use embedded_graphics::prelude::*;
use embedded_graphics_simulator::OutputSettings;
use embedded_graphics_simulator::SimulatorDisplay;
use embedded_graphics_simulator::Window;
use embedded_sprites::include_image;
use embedded_sprites::sprite::Sprite;
use heapless::format;
use profont::{PROFONT_12_POINT, PROFONT_14_POINT, PROFONT_18_POINT, PROFONT_24_POINT};
use profont::PROFONT_12_POINT;
use profont::PROFONT_14_POINT;
use profont::PROFONT_18_POINT;
use profont::PROFONT_24_POINT;
use tinybmp::Bmp;
use crate::triangle::Triangle;
const BACKGROUND_COLOR: Rgb565 = Rgb565::BLACK;
const DEFAULT_COLOR: Rgb565 = Rgb565::WHITE;
fn main()
{
fn main() {
images::prepare_images();
let mut window = Window::new("Hello World", &OutputSettings::default());
@ -38,8 +42,7 @@ fn main()
window.show_static(&display);
}
fn hello_view() -> impl View<Rgb565>
{
fn hello_view() -> impl View<Rgb565> {
VStack::new((
HStack::new((
main_menu_indicator(MenuIndicatorType::Temperature(31.5)),
@ -58,22 +61,18 @@ fn hello_view() -> impl View<Rgb565>
const FRAME_STROKE: u32 = 2;
const FRAME_COLOR: Rgb565 = Rgb565::new(5, 9, 5);
pub enum MenuIndicatorType
{
pub enum MenuIndicatorType {
Temperature(f32),
Humidity(f32),
Co2(u32),
Voc(u32),
}
impl MenuIndicatorType
{
impl MenuIndicatorType {
pub fn get_corresponding_icon(
&self,
) -> &'static std::thread::LocalKey<UnsafeCell<MaybeUninit<Bmp<'static, Rgb565>>>>
{
match self
{
) -> &'static std::thread::LocalKey<UnsafeCell<MaybeUninit<Bmp<'static, Rgb565>>>> {
match self {
MenuIndicatorType::Temperature(_) => &images::TEMPERATURE_ICON,
MenuIndicatorType::Humidity(_) => &images::HUMIDITY_ICON,
MenuIndicatorType::Co2(_) => &images::CO2_ICON,
@ -81,10 +80,8 @@ impl MenuIndicatorType
}
}
pub fn get_corresponding_unit_string(&self) -> &'static str
{
match self
{
pub fn get_corresponding_unit_string(&self) -> &'static str {
match self {
MenuIndicatorType::Temperature(_) => "C",
MenuIndicatorType::Humidity(_) => "%",
MenuIndicatorType::Co2(_) => "ppm",
@ -92,10 +89,8 @@ impl MenuIndicatorType
}
}
pub fn get_value_str(&self) -> heapless::String<16>
{
match self
{
pub fn get_value_str(&self) -> heapless::String<16> {
match self {
MenuIndicatorType::Temperature(temp) => format!(16; "{:.1}", temp).unwrap(),
MenuIndicatorType::Humidity(hum) => format!(16; "{:.1}", hum).unwrap(),
MenuIndicatorType::Co2(co2) => format!(16; "{}", co2).unwrap(),
@ -104,8 +99,7 @@ impl MenuIndicatorType
}
}
fn main_menu_indicator(indicator_type: MenuIndicatorType) -> impl View<Rgb565>
{
fn main_menu_indicator(indicator_type: MenuIndicatorType) -> impl View<Rgb565> {
Rectangle
.corner_radius(10)
.stroked(FRAME_STROKE)
@ -145,23 +139,16 @@ fn main_menu_indicator(indicator_type: MenuIndicatorType) -> impl View<Rgb565>
})
}
pub enum Tendency
{
pub enum Tendency {
Rising,
Steady,
Falling,
}
fn tendency_indicator(tendency: Tendency) -> impl View<Rgb565>
{
VStack::new((
StrokedShape::new(
Triangle::new(Point::new(0, 5), Point::new(10, 0), Point::new(0, 10)),
10,
),
StrokedShape::new(
Triangle::new(Point::new(0, 5), Point::new(10, 0), Point::new(0, 10)),
10,
),
))
fn tendency_indicator(tendency: Tendency) -> impl View<Rgb565> {
Rectangle
.foreground_color(Rgb565::WHITE)
.flex_frame()
.with_min_size(10, 20)
.with_max_size(10, 20)
}

View File