Indicators
This commit is contained in:
@ -8,6 +8,11 @@ thread_local! {
|
||||
pub static TEMPERATURE_ICON: UnsafeCell<MaybeUninit<Bmp<'static, Rgb565>>> = const { UnsafeCell::new(MaybeUninit::zeroed()) };
|
||||
pub static VOC_ICON: UnsafeCell<MaybeUninit<Bmp<'static, Rgb565>>> = const { UnsafeCell::new(MaybeUninit::zeroed()) };
|
||||
pub static CO2_ICON: UnsafeCell<MaybeUninit<Bmp<'static, Rgb565>>> = const { UnsafeCell::new(MaybeUninit::zeroed()) };
|
||||
|
||||
// Tendency indicators
|
||||
pub static TENDENCY_RISING: UnsafeCell<MaybeUninit<Bmp<'static, Rgb565>>> = const { UnsafeCell::new(MaybeUninit::zeroed()) };
|
||||
pub static TENDENCY_STEADY: UnsafeCell<MaybeUninit<Bmp<'static, Rgb565>>> = const { UnsafeCell::new(MaybeUninit::zeroed()) };
|
||||
pub static TENDENCY_FALLING: UnsafeCell<MaybeUninit<Bmp<'static, Rgb565>>> = const { UnsafeCell::new(MaybeUninit::zeroed()) };
|
||||
}
|
||||
|
||||
macro_rules! load_image {
|
||||
@ -28,12 +33,15 @@ macro_rules! get_image {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn prepare_images()
|
||||
{
|
||||
pub fn prepare_images() {
|
||||
unsafe {
|
||||
load_image!(HUMIDITY_ICON, "../assets/humidity-icon.bmp");
|
||||
load_image!(TEMPERATURE_ICON, "../assets/temperature-icon.bmp");
|
||||
load_image!(VOC_ICON, "../assets/voc-icon.bmp");
|
||||
load_image!(CO2_ICON, "../assets/co2-icon.bmp");
|
||||
|
||||
load_image!(TENDENCY_RISING, "../assets/indic-rising.bmp");
|
||||
load_image!(TENDENCY_STEADY, "../assets/indic-steady.bmp");
|
||||
load_image!(TENDENCY_FALLING, "../assets/indic-falling.bmp");
|
||||
}
|
||||
}
|
||||
|
||||
57
src/main.rs
57
src/main.rs
@ -1,4 +1,4 @@
|
||||
#![feature(unsafe_cell_access)]
|
||||
//#![feature(unsafe_cell_access)]
|
||||
|
||||
mod images;
|
||||
|
||||
@ -45,13 +45,13 @@ fn main() {
|
||||
fn hello_view() -> impl View<Rgb565> {
|
||||
VStack::new((
|
||||
HStack::new((
|
||||
main_menu_indicator(MenuIndicatorType::Temperature(31.5)),
|
||||
main_menu_indicator(MenuIndicatorType::Humidity(36.2)),
|
||||
main_menu_indicator(MenuIndicatorType::Temperature(31.5), Tendency::Falling),
|
||||
main_menu_indicator(MenuIndicatorType::Humidity(36.2), Tendency::Steady),
|
||||
))
|
||||
.with_spacing(5),
|
||||
HStack::new((
|
||||
main_menu_indicator(MenuIndicatorType::Co2(1329)),
|
||||
main_menu_indicator(MenuIndicatorType::Voc(29)),
|
||||
main_menu_indicator(MenuIndicatorType::Co2(1329), Tendency::Rising),
|
||||
main_menu_indicator(MenuIndicatorType::Voc(29), Tendency::Falling),
|
||||
))
|
||||
.with_spacing(5),
|
||||
))
|
||||
@ -99,7 +99,7 @@ impl MenuIndicatorType {
|
||||
}
|
||||
}
|
||||
|
||||
fn main_menu_indicator(indicator_type: MenuIndicatorType) -> impl View<Rgb565> {
|
||||
fn main_menu_indicator(indicator_type: MenuIndicatorType, tendency: Tendency) -> impl View<Rgb565> {
|
||||
Rectangle
|
||||
.corner_radius(10)
|
||||
.stroked(FRAME_STROKE)
|
||||
@ -112,14 +112,23 @@ fn main_menu_indicator(indicator_type: MenuIndicatorType) -> impl View<Rgb565> {
|
||||
VStack::new((
|
||||
HStack::new((
|
||||
Spacer::default(),
|
||||
buoyant::view::Image::new(get_image!(
|
||||
indicator_type.get_corresponding_icon()
|
||||
)),
|
||||
ZStack::new((
|
||||
Rectangle
|
||||
.corner_radius(10)
|
||||
//.stroked_offset(5, StrokeOffset::Outer)
|
||||
.foreground_color(Rgb565::new(4, 9, 4)),
|
||||
buoyant::view::Image::new(get_image!(
|
||||
indicator_type.get_corresponding_icon()
|
||||
)),
|
||||
))
|
||||
.flex_frame()
|
||||
.with_max_size(53, 53)
|
||||
.with_min_size(53, 53),
|
||||
Spacer::default(),
|
||||
)),
|
||||
HStack::new((
|
||||
Spacer::default(),
|
||||
tendency_indicator(Tendency::Rising),
|
||||
tendency_indicator(tendency),
|
||||
Text::new(indicator_type.get_value_str(), &PROFONT_24_POINT),
|
||||
Text::new(
|
||||
indicator_type.get_corresponding_unit_string(),
|
||||
@ -145,10 +154,26 @@ pub enum Tendency {
|
||||
Falling,
|
||||
}
|
||||
|
||||
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)
|
||||
impl Tendency {
|
||||
pub fn get_corresponding_icon(
|
||||
&self,
|
||||
) -> &'static std::thread::LocalKey<UnsafeCell<MaybeUninit<Bmp<'static, Rgb565>>>> {
|
||||
match self {
|
||||
Self::Rising => &images::TENDENCY_RISING,
|
||||
Self::Steady => &images::TENDENCY_STEADY,
|
||||
Self::Falling => &images::TENDENCY_FALLING,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn tendency_indicator(tendency: Tendency) -> impl View<Rgb565> {
|
||||
HStack::new((
|
||||
Image::new(get_image!(tendency.get_corresponding_icon()))
|
||||
.flex_frame()
|
||||
.with_min_size(10, 20)
|
||||
.with_max_size(10, 20),
|
||||
Spacer::default(),
|
||||
))
|
||||
.flex_frame()
|
||||
.with_max_width(15)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user