92 lines
3.1 KiB
Rust
92 lines
3.1 KiB
Rust
use buoyant::view::VStack;
|
|
use buoyant::view::View;
|
|
|
|
use buoyant::view::prelude::*;
|
|
use embedded_graphics::pixelcolor::Rgb565;
|
|
use embedded_graphics::prelude::*;
|
|
use profont::PROFONT_18_POINT;
|
|
use profont::PROFONT_24_POINT;
|
|
|
|
use crate::MeasurementType;
|
|
use crate::Tendencies;
|
|
use crate::Tendency;
|
|
use crate::colors::FRAME_BACKGROUD_COLOR;
|
|
use crate::colors::FRAME_STROKE;
|
|
use crate::colors::FRAME_STROKE_COLOR;
|
|
use crate::colors::MAIN_TEXT_COLOR;
|
|
use crate::colors::SUB_TEXT_COLOR;
|
|
use crate::get_image;
|
|
use crate::sampler::Sample;
|
|
use crate::views::icon::icon_box_view;
|
|
|
|
pub fn menu_view(sample: Sample, tendencies: Tendencies) -> impl View<Rgb565> {
|
|
VStack::new((
|
|
HStack::new((
|
|
main_menu_indicator(MeasurementType::Temperature, tendencies, sample),
|
|
main_menu_indicator(MeasurementType::Humidity, tendencies, sample),
|
|
))
|
|
.with_spacing(2),
|
|
HStack::new((
|
|
main_menu_indicator(MeasurementType::ECo2, tendencies, sample),
|
|
main_menu_indicator(MeasurementType::TVoc, tendencies, sample),
|
|
))
|
|
.with_spacing(2),
|
|
))
|
|
.with_spacing(2)
|
|
}
|
|
|
|
fn main_menu_indicator(
|
|
indicator_type: MeasurementType,
|
|
tendencies: Tendencies,
|
|
sample: Sample,
|
|
) -> impl View<Rgb565> {
|
|
Rectangle
|
|
.corner_radius(5)
|
|
.stroked(FRAME_STROKE)
|
|
.foreground_color(FRAME_STROKE_COLOR)
|
|
.background(Alignment::Center, || {
|
|
ZStack::new((
|
|
Rectangle
|
|
.corner_radius(15)
|
|
.foreground_color(FRAME_BACKGROUD_COLOR),
|
|
VStack::new((
|
|
HStack::new((
|
|
Spacer::default(),
|
|
icon_box_view(FRAME_STROKE_COLOR, indicator_type.get_corresponding_icon()),
|
|
Spacer::default(),
|
|
)),
|
|
HStack::new((
|
|
Spacer::default(),
|
|
tendency_indicator(indicator_type.get_tendency(tendencies)),
|
|
Text::new(indicator_type.get_value_str(sample), &PROFONT_24_POINT)
|
|
.foreground_color(MAIN_TEXT_COLOR),
|
|
Text::new(
|
|
indicator_type.get_corresponding_unit_string(),
|
|
&PROFONT_18_POINT,
|
|
)
|
|
.foreground_color(SUB_TEXT_COLOR)
|
|
.flex_frame()
|
|
.with_infinite_max_height()
|
|
.with_vertical_alignment(VerticalAlignment::Bottom)
|
|
.with_max_height(25),
|
|
Spacer::default(),
|
|
)),
|
|
))
|
|
.with_alignment(HorizontalAlignment::Center)
|
|
.flex_frame(),
|
|
))
|
|
})
|
|
}
|
|
|
|
pub 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)
|
|
}
|