Skip to content
Snippets Groups Projects
Commit 69f62b52 authored by Stephen D's avatar Stephen D
Browse files

symbols WIP

parent aa6d9f7f
No related branches found
No related tags found
1 merge request!5Symbols
......@@ -29,6 +29,7 @@ use crate::{
selector::Selector,
settings::SettingsView,
status::StatusBar,
symbol::SymbolSelector,
Element,
},
keyboard::KeyCode,
......@@ -260,6 +261,7 @@ pub struct TxItem {
pub struct Controller {
status: StatusBar,
cur_view: View,
symbol_selector: SymbolSelector,
storage: Storage,
tx_queue: Vec<TxItem, TX_QUEUE_SIZE>,
green_led: Option<Instant>,
......@@ -298,6 +300,7 @@ impl Controller {
Self {
status: StatusBar::new(volt_meter),
cur_view: View::default(),
symbol_selector: SymbolSelector::new(),
storage,
tx_queue: Vec::new(),
green_led: None,
......@@ -725,6 +728,8 @@ impl Controller {
self.status
.render(dt, &self.gps_data, self.storage.settings())?;
self.symbol_selector.render(dt)?;
}
Ok(())
......@@ -739,6 +744,10 @@ impl Controller {
return;
}
if self.symbol_selector.key_push(k) {
return;
}
match (&mut self.cur_view, k) {
(View::MainMenu(m), KeyCode::Touchpad) => {
if let Some(new_view) =
......
......@@ -14,6 +14,7 @@ pub mod selector;
pub mod settings;
pub mod slider;
pub mod status;
pub mod symbol;
pub mod textbox;
pub trait Element {
......
use core::fmt::Write;
use embedded_graphics::{
geometry::{Point, Size},
mono_font::{ascii::FONT_10X20, MonoTextStyle},
pixelcolor::{Rgb565, RgbColor},
primitives::{Primitive, PrimitiveStyleBuilder, Rectangle},
text::{renderer::TextRenderer, Baseline},
Drawable,
};
use heapless::String;
use crate::{
app::{HEIGHT, WIDTH},
keyboard::KeyCode,
};
use super::Element;
const KEYBOARD_REFERENCE: [&str; 3] = ["qwertyuiop", "asdfghjkl", "zxcvbnm"];
const PAGES: [[&str; 3]; 1] = [["[<{ ~= ^%", "]>} `\\ &", "$ | "]];
const BOX_WIDTH: u32 = 240;
const BOX_HEIGHT: u32 = 190;
const BORDER_WIDTH: u32 = 1;
const BG_COLOR: Rgb565 = Rgb565::BLACK;
const FG_COLOR: Rgb565 = Rgb565::WHITE;
const CHAR_WIDTH: i32 = 10;
const CHAR_WIDTH_WITH_BORDER: i32 = 18;
const CHAR_HEIGHT: i32 = 20;
pub struct SymbolSelector {
page: usize,
viewable: bool,
}
impl SymbolSelector {
pub fn new() -> Self {
Self {
page: 0,
viewable: false,
}
}
}
impl Element for SymbolSelector {
type KeyPushReturn = bool;
fn render<
E,
DT: embedded_graphics::prelude::DrawTarget<
Color = embedded_graphics::pixelcolor::Rgb565,
Error = E,
>,
>(
&mut self,
dt: &mut DT,
) -> Result<(), E> {
if !self.viewable {
return Ok(());
}
// render rectangle
let rect_style = PrimitiveStyleBuilder::new()
.stroke_color(FG_COLOR)
.stroke_width(BORDER_WIDTH)
.fill_color(BG_COLOR)
.build();
let bounds = Rectangle::with_center(
Point::new(WIDTH.try_into().unwrap(), HEIGHT.try_into().unwrap()) / 2,
Size::new(BOX_WIDTH, BOX_HEIGHT),
);
bounds.into_styled(rect_style).draw(dt)?;
let character_style = MonoTextStyle::new(&FONT_10X20, FG_COLOR);
// render page #
let mut buf: String<10> = String::new();
write!(&mut buf, "Page {}/{}", self.page + 1, PAGES.len()).unwrap();
character_style.draw_string(
&buf,
Point::new(
bounds.bottom_right().unwrap().x - CHAR_WIDTH * 10,
bounds.top_left.y + CHAR_HEIGHT + 4,
),
Baseline::Bottom,
dt,
)?;
// render lines
let border_style = PrimitiveStyleBuilder::new()
.stroke_color(FG_COLOR)
.stroke_width(BORDER_WIDTH)
.build();
for (i, line) in KEYBOARD_REFERENCE.iter().enumerate() {
let len = line.chars().count();
let x_start = (i32::try_from(WIDTH).unwrap()
- i32::try_from(len).unwrap() * CHAR_WIDTH_WITH_BORDER)
/ 2;
let y = bounds.top_left.y
+ (i32::try_from(i).unwrap() + 1) * (CHAR_HEIGHT + 8) * 2
+ CHAR_HEIGHT;
for (j, c) in line.chars().enumerate() {
let x = x_start + i32::try_from(j).unwrap() * CHAR_WIDTH_WITH_BORDER;
// Is there a better way to do char -> string?
let mut s: String<1> = String::new();
s.push(c.to_ascii_uppercase()).unwrap();
character_style.draw_string(&s, Point::new(x + 4, y + 4), Baseline::Bottom, dt)?;
Rectangle::new(
Point::new(x + 1, y - CHAR_HEIGHT + 1),
Size::new(
u32::try_from(CHAR_WIDTH).unwrap() + 6,
u32::try_from(CHAR_HEIGHT).unwrap() + 6,
),
)
.into_styled(border_style)
.draw(dt)?;
}
}
Ok(())
}
fn key_push(&mut self, k: KeyCode) -> Self::KeyPushReturn {
if k == KeyCode::Sym {
self.viewable = true;
}
self.viewable
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment