Nice graphs

This commit is contained in:
2025-11-30 22:11:47 +01:00
parent 3cb8a04a77
commit ea9852d5bc
28 changed files with 918 additions and 426 deletions

98
src/views/menu.rs Normal file
View File

@ -0,0 +1,98 @@
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::AppState;
use crate::MenuIndicatorType;
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::views::icon::icon_box_view;
pub fn menu_view(app_state: AppState) -> impl View<Rgb565> {
VStack::new((
HStack::new((
main_menu_indicator(
MenuIndicatorType::Temperature(app_state.sample.temperature),
app_state.tendencies.temperature,
),
main_menu_indicator(
MenuIndicatorType::Humidity(app_state.sample.humidity),
app_state.tendencies.humidity,
),
))
.with_spacing(2),
HStack::new((
main_menu_indicator(
MenuIndicatorType::Co2(app_state.sample.eco2 as u32),
app_state.tendencies.eco2,
),
main_menu_indicator(
MenuIndicatorType::Voc(app_state.sample.tvoc as u32),
app_state.tendencies.tvoc,
),
))
.with_spacing(2),
))
.with_spacing(2)
}
fn main_menu_indicator(indicator_type: MenuIndicatorType, tendency: Tendency) -> 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(tendency),
Text::new(indicator_type.get_value_str(), &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(),
))
})
}
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)
}