Centralised styles

This commit is contained in:
Sebastian 2020-12-24 14:35:38 +01:00
parent 8ff6642aa7
commit 1fb40ac65f
7 changed files with 105 additions and 84 deletions

View File

@ -4,7 +4,6 @@ use embedded_graphics::{
}; };
use embedded_hal::digital::v2::{InputPin, OutputPin}; use embedded_hal::digital::v2::{InputPin, OutputPin};
use profont::{ProFont12Point, ProFont14Point};
use st7735_lcd::Orientation; use st7735_lcd::Orientation;
use stm32f1xx_hal::prelude::*; use stm32f1xx_hal::prelude::*;
@ -21,44 +20,12 @@ impl App {
disp.set_orientation(&Orientation::LandscapeSwapped) disp.set_orientation(&Orientation::LandscapeSwapped)
.unwrap(); .unwrap();
let style_black = PrimitiveStyleBuilder::new() let rect = Rectangle::new(Point::new(0, 0), Point::new(160, 128))
.fill_color(Rgb565::BLACK) .into_styled(self.styles.fill_black);
.build();
let rect = Rectangle::new(Point::new(0, 0), Point::new(160, 128)).into_styled(style_black);
rect.draw(&mut disp).unwrap(); rect.draw(&mut disp).unwrap();
let text = TextStyleBuilder::new(ProFont12Point)
.text_color(Rgb565::WHITE)
.build();
let text_big = TextStyleBuilder::new(ProFont14Point)
.text_color(Rgb565::WHITE)
.build();
let text_big_black = TextStyleBuilder::new(ProFont14Point)
.text_color(Rgb565::BLACK)
.build();
let normal_box = PrimitiveStyleBuilder::new()
.fill_color(Rgb565::BLACK)
.stroke_color(Rgb565::WHITE)
.stroke_width(1)
.build();
let ok_box = PrimitiveStyleBuilder::new()
.fill_color(Rgb565::GREEN)
.stroke_color(Rgb565::WHITE)
.stroke_width(1)
.build();
let cancel_box = PrimitiveStyleBuilder::new()
.fill_color(Rgb565::RED)
.stroke_color(Rgb565::WHITE)
.stroke_width(1)
.build();
Text::new("Confirm profile", Point::new(4, 4)) Text::new("Confirm profile", Point::new(4, 4))
.into_styled(text) .into_styled(self.styles.text)
.draw(&mut disp) .draw(&mut disp)
.unwrap(); .unwrap();
@ -66,7 +33,7 @@ impl App {
profiles::REFLOW_PROFILES[self.selected_profile].get_name(), profiles::REFLOW_PROFILES[self.selected_profile].get_name(),
Point::new(20, 50), Point::new(20, 50),
) )
.into_styled(text_big) .into_styled(self.styles.text_big)
.draw(&mut disp) .draw(&mut disp)
.unwrap(); .unwrap();
@ -77,25 +44,41 @@ impl App {
while press_count < 5 { while press_count < 5 {
if needs_redraw { if needs_redraw {
let style = if confirmed { ok_box } else { normal_box }; let style = if confirmed {
self.styles.ok_box
} else {
self.styles.normal_box
};
Rectangle::new(Point::new(4, 104), Point::new(70, 124)) Rectangle::new(Point::new(4, 104), Point::new(70, 124))
.into_styled(style) .into_styled(style)
.draw(&mut disp) .draw(&mut disp)
.unwrap(); .unwrap();
let text_style = if confirmed { text_big_black } else { text_big }; let text_style = if confirmed {
self.styles.text_big_black
} else {
self.styles.text_big
};
Text::new("Start", Point::new(12, 105)) Text::new("Start", Point::new(12, 105))
.into_styled(text_style) .into_styled(text_style)
.draw(&mut disp) .draw(&mut disp)
.unwrap(); .unwrap();
let style = if !confirmed { cancel_box } else { normal_box }; let style = if !confirmed {
self.styles.cancel_box
} else {
self.styles.normal_box
};
Rectangle::new(Point::new(90, 104), Point::new(155, 124)) Rectangle::new(Point::new(90, 104), Point::new(155, 124))
.into_styled(style) .into_styled(style)
.draw(&mut disp) .draw(&mut disp)
.unwrap(); .unwrap();
let text_style = if !confirmed { text_big_black } else { text_big }; let text_style = if !confirmed {
self.styles.text_big_black
} else {
self.styles.text_big
};
Text::new("Cancel", Point::new(96, 105)) Text::new("Cancel", Point::new(96, 105))
.into_styled(text_style) .into_styled(text_style)
.draw(&mut disp) .draw(&mut disp)

View File

@ -1,3 +1,5 @@
use embedded_hal::digital::v2::{InputPin, OutputPin};
use st7735_lcd::Orientation;
use stm32f1xx_hal::{ use stm32f1xx_hal::{
delay::Delay, delay::Delay,
gpio::{gpioa, gpiob, gpioc, Alternate, Floating, Input, Output, PushPull}, gpio::{gpioa, gpiob, gpioc, Alternate, Floating, Input, Output, PushPull},
@ -11,9 +13,12 @@ mod profile_selection;
mod run_profile; mod run_profile;
mod setup; mod setup;
mod splash; mod splash;
mod styles;
pub use setup::setup; pub use setup::setup;
use styles::Styles;
type AppSPI = Spi< type AppSPI = Spi<
pac::SPI1, pac::SPI1,
Spi1NoRemap, Spi1NoRemap,
@ -30,6 +35,9 @@ type AppQEI = qei::Qei<
(gpiob::PB4<Input<Floating>>, gpiob::PB5<Input<Floating>>), (gpiob::PB4<Input<Floating>>, gpiob::PB5<Input<Floating>>),
>; >;
type AppDisp =
st7735_lcd::ST7735<AppSPI, gpioa::PA4<Output<PushPull>>, gpioa::PA1<Output<PushPull>>>;
pub struct App { pub struct App {
delay: Delay, delay: Delay,
board_led: gpioc::PC13<Output<PushPull>>, board_led: gpioc::PC13<Output<PushPull>>,
@ -42,6 +50,8 @@ pub struct App {
button: gpiob::PB3<Input<Floating>>, button: gpiob::PB3<Input<Floating>>,
selected_profile: usize, selected_profile: usize,
styles: Styles,
} }
impl App { impl App {

View File

@ -22,31 +22,13 @@ impl App {
disp.set_orientation(&Orientation::LandscapeSwapped) disp.set_orientation(&Orientation::LandscapeSwapped)
.unwrap(); .unwrap();
let style_black = PrimitiveStyleBuilder::new() let rect = Rectangle::new(Point::new(0, 0), Point::new(160, 128))
.fill_color(Rgb565::BLACK) .into_styled(self.styles.fill_black);
.build();
let rect = Rectangle::new(Point::new(0, 0), Point::new(160, 128)).into_styled(style_black);
rect.draw(&mut disp).unwrap(); rect.draw(&mut disp).unwrap();
let text_lager = TextStyleBuilder::new(ProFont12Point)
.text_color(Rgb565::WHITE)
.build();
let profile_box = PrimitiveStyleBuilder::new()
.fill_color(Rgb565::BLACK)
.stroke_color(Rgb565::WHITE)
.stroke_width(1)
.build();
let selected_box = PrimitiveStyleBuilder::new()
.fill_color(Rgb565::BLUE)
.stroke_color(Rgb565::WHITE)
.stroke_width(1)
.build();
Text::new("Selected a profile", Point::new(4, 4)) Text::new("Selected a profile", Point::new(4, 4))
.into_styled(text_lager) .into_styled(self.styles.text)
.draw(&mut disp) .draw(&mut disp)
.unwrap(); .unwrap();
@ -58,9 +40,9 @@ impl App {
if needs_redraw { if needs_redraw {
for i in 0..profiles::REFLOW_PROFILES.len() { for i in 0..profiles::REFLOW_PROFILES.len() {
let style = if i == self.selected_profile { let style = if i == self.selected_profile {
selected_box self.styles.selected_box
} else { } else {
profile_box self.styles.normal_box
}; };
Rectangle::new( Rectangle::new(
Point::new(0, 20 + (i as i32) * 16), Point::new(0, 20 + (i as i32) * 16),
@ -74,7 +56,7 @@ impl App {
profiles::REFLOW_PROFILES[i].get_name(), profiles::REFLOW_PROFILES[i].get_name(),
Point::new(4, 21 + (i as i32) * 16), Point::new(4, 21 + (i as i32) * 16),
) )
.into_styled(text_lager) .into_styled(self.styles.text)
.draw(&mut disp) .draw(&mut disp)
.unwrap(); .unwrap();
} }

View File

@ -1,7 +1,7 @@
use embedded_graphics::{ use embedded_graphics::{
drawable::Drawable, fonts::Text, pixelcolor::Rgb565, prelude::*, drawable::Drawable, fonts::Text, pixelcolor::Rgb565, prelude::*, primitive_style,
primitives::rectangle::Rectangle, primitives::Line, style::PrimitiveStyleBuilder, primitives::rectangle::Rectangle, primitives::Line, style::PrimitiveStyle,
style::TextStyleBuilder, style::PrimitiveStyleBuilder, style::TextStyleBuilder,
}; };
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
@ -31,27 +31,20 @@ impl App {
disp.set_orientation(&Orientation::LandscapeSwapped) disp.set_orientation(&Orientation::LandscapeSwapped)
.unwrap(); .unwrap();
let style_black = PrimitiveStyleBuilder::new() let rect = Rectangle::new(Point::new(0, 0), Point::new(160, 128))
.fill_color(Rgb565::BLACK) .into_styled(self.styles.fill_black);
.build();
let rect = Rectangle::new(Point::new(0, 0), Point::new(160, 128)).into_styled(style_black);
rect.draw(&mut disp).unwrap(); rect.draw(&mut disp).unwrap();
let style_grid = PrimitiveStyleBuilder::new()
.stroke_color(Rgb565::new(4, 8, 4))
.stroke_width(1)
.build();
for x in (0..160).step_by(30) { for x in (0..160).step_by(30) {
Line::new(Point::new(x, 20), Point::new(x, 127)) Line::new(Point::new(x, 20), Point::new(x, 127))
.into_styled(style_grid) .into_styled(self.styles.grid)
.draw(&mut disp) .draw(&mut disp)
.unwrap(); .unwrap();
} }
for y in (0..110).step_by(10) { for y in (0..110).step_by(10) {
Line::new(Point::new(0, 127 - y), Point::new(195, 127 - y)) Line::new(Point::new(0, 127 - y), Point::new(195, 127 - y))
.into_styled(style_grid) .into_styled(self.styles.grid)
.draw(&mut disp) .draw(&mut disp)
.unwrap(); .unwrap();
} }
@ -60,7 +53,7 @@ impl App {
let y = 148 let y = 148
- (profiles::REFLOW_PROFILES[self.selected_profile].get_temp(t as f32) / 2.0) - (profiles::REFLOW_PROFILES[self.selected_profile].get_temp(t as f32) / 2.0)
as i32; as i32;
Pixel(Point::new((t / 2) as i32, y), Rgb565::new(24, 48, 24)) Pixel(Point::new((t / 2) as i32, y), self.styles.profile_color)
.draw(&mut disp) .draw(&mut disp)
.unwrap(); .unwrap();
} }

View File

@ -9,6 +9,7 @@ use stm32f1xx_hal::{
timer::Timer, timer::Timer,
}; };
use crate::application::styles::Styles;
use crate::application::App; use crate::application::App;
pub fn setup(cp: cortex_m::peripheral::Peripherals, dp: stm32::Peripherals) -> App { pub fn setup(cp: cortex_m::peripheral::Peripherals, dp: stm32::Peripherals) -> App {
@ -88,5 +89,7 @@ pub fn setup(cp: cortex_m::peripheral::Peripherals, dp: stm32::Peripherals) -> A
button: button, button: button,
selected_profile: 0, selected_profile: 0,
styles: Styles::new(),
} }
} }

View File

@ -21,10 +21,8 @@ impl App {
disp.set_orientation(&Orientation::LandscapeSwapped) disp.set_orientation(&Orientation::LandscapeSwapped)
.unwrap(); .unwrap();
let style_black = PrimitiveStyleBuilder::new() let rect = Rectangle::new(Point::new(0, 0), Point::new(160, 128))
.fill_color(Rgb565::BLACK) .into_styled(self.styles.fill_black);
.build();
let rect = Rectangle::new(Point::new(0, 0), Point::new(160, 128)).into_styled(style_black);
rect.draw(&mut disp).unwrap(); rect.draw(&mut disp).unwrap();

52
src/application/styles.rs Normal file
View File

@ -0,0 +1,52 @@
use embedded_graphics::{
fonts::Text, pixelcolor::Rgb565, prelude::*, primitive_style, primitives::rectangle::Rectangle,
primitives::Line, style::PrimitiveStyle, style::TextStyle, style::TextStyleBuilder, text_style,
};
use profont::{ProFont12Point, ProFont14Point};
pub struct Styles {
pub fill_black: PrimitiveStyle<Rgb565>,
pub text: TextStyle<Rgb565, ProFont12Point>,
pub text_big: TextStyle<Rgb565, ProFont14Point>,
pub text_big_black: TextStyle<Rgb565, ProFont14Point>,
pub normal_box: PrimitiveStyle<Rgb565>,
pub selected_box: PrimitiveStyle<Rgb565>,
pub ok_box: PrimitiveStyle<Rgb565>,
pub cancel_box: PrimitiveStyle<Rgb565>,
pub grid: PrimitiveStyle<Rgb565>,
pub profile_color: Rgb565,
}
impl Styles {
pub fn new() -> Styles {
Styles {
fill_black: primitive_style!(fill_color = Rgb565::BLACK),
text: text_style!(font = ProFont12Point, text_color = Rgb565::WHITE),
text_big: text_style!(font = ProFont14Point, text_color = Rgb565::WHITE),
text_big_black: text_style!(font = ProFont14Point, text_color = Rgb565::BLACK),
normal_box: primitive_style!(
fill_color = Rgb565::BLACK,
stroke_color = Rgb565::WHITE,
stroke_width = 1
),
selected_box: primitive_style!(
fill_color = Rgb565::BLUE,
stroke_color = Rgb565::WHITE,
stroke_width = 1
),
ok_box: primitive_style!(
fill_color = Rgb565::GREEN,
stroke_color = Rgb565::WHITE,
stroke_width = 1
),
cancel_box: primitive_style!(
fill_color = Rgb565::GREEN,
stroke_color = Rgb565::WHITE,
stroke_width = 1
),
grid: primitive_style!(stroke_color = Rgb565::new(4, 8, 4), stroke_width = 1),
profile_color: Rgb565::new(24, 48, 24),
}
}
}