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

better logic when out of textbox space

parent 55de8a88
No related branches found
No related tags found
No related merge requests found
......@@ -12,7 +12,9 @@ use heapless::String;
use crate::{
app::{HEIGHT, WIDTH},
keyboard::KeyCode,
storage::{Message, MessageDirection, Storage, MAX_CONTACT_CALLSIGN_LENGTH},
storage::{
Message, MessageDirection, Storage, MAX_CONTACT_CALLSIGN_LENGTH, MAX_MESSAGE_BODY_LENGTH,
},
};
use super::{textbox::TextBox as MyTextBox, Element};
......@@ -23,7 +25,7 @@ const MESSAGE_BOX_HEIGHT: u32 = 64;
pub struct Chat {
callsign: String<MAX_CONTACT_CALLSIGN_LENGTH>,
ssid: u8,
textbox: MyTextBox,
textbox: MyTextBox<MAX_MESSAGE_BODY_LENGTH>,
}
impl Chat {
......
......@@ -23,9 +23,9 @@ const TEXT_X: i32 = 100;
pub struct ContactView {
contact: Contact,
editable: bool,
name: TextBox,
callsign: TextBox,
ssid: TextBox,
name: TextBox<MAX_CONTACT_NAME_LENGTH>,
callsign: TextBox<MAX_CONTACT_CALLSIGN_LENGTH>,
ssid: TextBox<3>,
delete: Button,
tracker: ScrollTracker,
selected: usize,
......@@ -36,7 +36,7 @@ impl ContactView {
let mut name = TextBox::new(
TEXT_X,
(40 - textbox::BORDER_WIDTH).try_into().unwrap(),
MAX_CONTACT_NAME_LENGTH.try_into().unwrap(),
u32::try_from(MAX_CONTACT_NAME_LENGTH).unwrap() + 1,
1,
1,
false,
......@@ -47,7 +47,7 @@ impl ContactView {
let mut callsign = TextBox::new(
TEXT_X,
(80 - textbox::BORDER_WIDTH).try_into().unwrap(),
MAX_CONTACT_CALLSIGN_LENGTH.try_into().unwrap(),
u32::try_from(MAX_CONTACT_CALLSIGN_LENGTH).unwrap() + 1,
1,
1,
false,
......@@ -58,7 +58,7 @@ impl ContactView {
let mut ssid = TextBox::new(
TEXT_X,
(120 - textbox::BORDER_WIDTH).try_into().unwrap(),
3,
4,
1,
1,
true,
......
......@@ -23,9 +23,8 @@ const BACKGROUND_COLOR: Rgb565 = Rgb565::new(0xFF, 0xFF, 0xFF);
pub const BORDER_WIDTH: u32 = 3;
const CHAR_WIDTH: u32 = 10;
const CHAR_HEIGHT: u32 = 20;
const MAX_TEXT_LENGTH: usize = 500;
pub struct TextBox {
pub struct TextBox<const N: usize> {
// in # of chars
max_height: u32,
char_width: u32,
......@@ -42,13 +41,13 @@ pub struct TextBox {
number_only: bool,
text: String<MAX_TEXT_LENGTH>,
text: String<N>,
pub selected: bool,
tracker: ScrollTracker,
}
impl TextBox {
impl<const N: usize> TextBox<N> {
pub fn new(
x: i32,
y: i32,
......@@ -104,7 +103,7 @@ impl TextBox {
&self.text
}
pub fn clear(&mut self) -> String<MAX_TEXT_LENGTH> {
pub fn clear(&mut self) -> String<N> {
let mut other = String::new();
mem::swap(&mut self.text, &mut other);
......@@ -177,7 +176,7 @@ impl TextBox {
}
}
impl Element for TextBox {
impl<const N: usize> Element for TextBox<N> {
type KeyPushReturn = ();
fn render<E, DT: DrawTarget<Color = Rgb565, Error = E>>(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment